Submission d8a590b7...

ChallengeHex decoder
Submitterwicketh.eth
Submitted at2018-15-28
Gas used20131
pragma solidity ^0.4.23;

contract HexDecoder {
    
    function () payable { assembly {

        jumpi(empty, eq(68, calldatasize))
        
        let o := 64
        let i := 68
        
    loop: // Stack: [o i]
        dup1
        calldataload
        
        // Convert characters to nibbles
        64
        dup2
        div
        0x0101010101010101010101010101010101010101010101010101010101010101
        and
        9
        mul
        swap1
        0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F
        and
        add
        
        // Shuffle odd nibbles to consecutive bytes
        0x11
        mul
        0x0FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF0
        and
        0x101
        mul
        0x0FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF000
        and
        0x10001
        mul
        0x0FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF0000000
        and
        0x100000001
        mul
        0x0FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF000000000000000
        and
        0x100000000000000010
        mul
        
        // Store
        o
        mstore
        
        // Stack: [o i]
        
        // o := add(o, 16)
        swap1
        16
        add
        swap1
        
        // i := add(i, 32)
        32
        add
        
        // Loop
        dup1
        calldatasize
        gt
        loop
        jumpi
        
    exit:
        let ol := div(calldataload(36), 2)
        mstore(0, 32)
        mstore(32, ol)
        
        // Add 64 to ol and round to the next multiple of 32
        return(0, and(add(ol, 95), 0xFFFFFFE0))
        
    empty:
        mstore(0, 32)
        return(0, 64)
        
    }}
}