Submission d2ecc643...

ChallengeHex decoder
Submitter0x888888417655103...
Submitted at2018-44-30
Gas used192500
pragma solidity 0.4.24;

contract HexDecoder {

    function decode(
        string _input
    ) public pure returns(bytes outBytes) {
        uint outLen;
        assembly { outLen := div(mload(0x80), 2) }
        if (outLen == 0) { return; }
        outBytes = new bytes(outLen);
        assembly {
            let inPtr := 0xa0
            let ptrStopLoop := add(0xa0, mload(0x80))
            let tmpVal
            for { } lt(inPtr, ptrStopLoop) { } {
                tmpVal := mload(inPtr)
                tmpVal := add(
                    mul(
                        div(
                            and(tmpVal, 0x4040404040404040404040404040404040404040404040404040404040404040),
                            0x40),
                        0x09),
                    and(tmpVal, 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f))
                tmpVal := mul(tmpVal, 0x110)
                mstore(inPtr, tmpVal)
                inPtr := add(inPtr, 0x20)
            }
            inPtr := sub(ptrStopLoop, 0x21)
            ptrStopLoop := add(outBytes, 0x1f)
            let outPtr := add(add(outBytes, 0x1f), outLen)
            for { } gt(outPtr, ptrStopLoop) { } {
                mstore8(outPtr, mload(inPtr))
                outPtr := sub(outPtr, 0x1)
                inPtr := sub(inPtr, 0x2)
            }
        }
    }
}