Submission 1d643f7b...

ChallengeHex decoder
Submitterzac.creditmint.eth
Submitted at2018-14-09
Gas used44827
contract HexDecoder {
    function decode(string) external pure returns(bytes output) {
        assembly {
            let p := mload(0x40)
            let length := div(calldataload(0x24), 2)

            let start := 0x44
            let m := add(0x40, p)

            for {} lt(start, calldatasize) { start := add(start, 0x20) } {
                let w := calldataload(start)

                w := and(add(mulmod(
                    0x9000000000000000000000000000000000000000000000000000000000000000,
                    not(or(
                        w,
                        0xEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEF
                    )),
                    0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
                ), w), 0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F)
                w := or(w, div(w, 16))
                
                mstore(0x20, w)
                mstore8(34, mload(4))
                mstore8(35, mload(6))
                mstore8(36, mload(8))
                mstore8(37, mload(10))
                mstore8(38, mload(12))
                mstore8(39, mload(14))
                mstore8(40, mload(16))
                mstore8(41, mload(18))
                mstore8(42, mload(20))
                mstore8(43, mload(22))
                mstore8(44, mload(24))
                mstore8(45, mload(26))
                mstore8(46, mload(28))
                mstore8(47, mload(30))
                mstore8(48, mload(32))

                mstore(m, mload(33))
                m := add(m, 0x10)
            }
            mstore(add(add(p, 0x40), length), 0x00)

            mstore(add(p, 0x20), length)
            mstore(p, 0x20)
            
            // let padded := mul(div(length, 32), 32)
            let r := sub(m, p)
            let q := add(r, mul(iszero(iszero(and(r, 0x1f))), 0x20))
            return(p, q)
            // output := add(p, 0x20)
        }
    }
}