pragma solidity ^0.4.25; /* Workshop challenge: Obtener la password */ contract WorkshopChallenge { string memX; string memY; string memZ; function buildPass() private view returns (string) { return string(abi.encodePacked(memZ, memX, memY)); } function init() public { memX = "6f726b7368"; memY = "6f703432"; memZ = "636c61766577"; } function getPassword(uint salt) public view returns(string pass) { if (salt == 42 szabo) { pass = string(fromHex(buildPass())); } else { pass = string(abi.encodePacked(blockhash(block.number))); } } function fromHex(string s) private pure returns (bytes) { bytes memory ss = bytes(s); require(ss.length%2 == 0); bytes memory r = new bytes(ss.length/2); for (uint i=0; i<ss.length/2; ++i) { r[i] = byte(fromHexChar(uint(ss[2*i])) * 16 + fromHexChar(uint(ss[2*i+1]))); } return r; } function fromHexChar(uint c) private pure returns (uint) { if (byte(c) >= byte('0') && byte(c) <= byte('9')) { return c - uint(byte('0')); } if (byte(c) >= byte('a') && byte(c) <= byte('f')) { return 10 + c - uint(byte('a')); } if (byte(c) >= byte('A') && byte(c) <= byte('F')) { return 10 + c - uint(byte('A')); } } }
0.4.25