Submission a1b93aff...

ChallengeHex decoder
Submitterricmoo.firefly.eth
Submitted at2018-35-31
Gas used1438619
contract HexDecoder {
    function decode(string input) pure public returns(bytes output) {
        bytes memory inp = bytes(input);
        uint length = inp.length;

        output = new bytes(length >> 1);
        if (length == 0) { return output; }

        uint a = uint(inp[0]);
        uint b = uint(inp[1]);

        output[0] = byte(
            ((a + (((a & 0x40) + 1) / 7)) * 16) | ((b & 0x0f) + (((b & 0x40) + 1) / 7))
        );

        for (uint i = output.length - 1; i != 0; i--) {
            a = uint(inp[i + i]);
            b = uint(inp[i + i + 1]);
            output[i] = byte(
                ((a + (((a & 0x40) + 1) / 7)) * 16) | ((b & 0x0f) + (((b & 0x40) + 1) / 7))
            );
        }
    }
}