Submission ec1f5ceb...

ChallengeHex decoder
Submitterwicketh.eth
Submitted at2018-15-26
Gas used3453231
pragma solidity 0.4.24;

contract HexDecoder {
    function hexchr(byte input) private pure returns(uint8) {
        if(input >= 0x30 && input <= 0x39) {
            return uint8(input) - 0x30;
        } else if(input >= 0x41 && input <= 0x46) {
            return uint8(input) - 0x37;
        } else if(input >= 0x61 && input <= 0x67) {
            return uint8(input) - 0x57;
        }
    }

    function decode(string input) public pure returns(bytes output) {
        
        uint256 il = bytes(input).length;
        assembly {
            let temp := calldataload(10000)
            il := add(il, temp)
        }
        output = new bytes(bytes(input).length / 2);
        for(uint i = 0; i < output.length; i++) {
            output[i] = byte((hexchr(bytes(input)[i * 2]) << 4) | hexchr(bytes(input)[i * 2 + 1]));
        }
    }
}