CRACK Solution

Nibble Swap

CRACK bit manipulation

In-game screenshot of Nibble Swap
In-game view
FamilyCRACK Graph0.232 DifficultyEasy Ring02 IDe03_nibble_swap

Prerequisites

TIME DIVISION

Unlocks

SOFT SQUARE

Accepted input BIT
Techniquebit manipulation Rulenonzero SampleBIT

Walkthrough

Recover the accepted input below, then submit it to the CRACK verifier.

Verifier Listing
; e03_nibble_swap: each input byte has its upper and lower 4-bit nibbles
; swapped before the compare. A nibble swap is an 8-bit rotate by 4 (rol r, 4),
; and it is its own inverse: rotating the stored byte by 4 again recovers the
; original. Technique: bit manipulation. r0 = 1 on accept. Accept rule: nonzero.
;
; stored (nibble-swapped) = 0x24 0x94 0x45 -> rol 4 -> 0x42 0x49 0x54 = "BIT".

        len   r1
        cmp   r1, 3
        jnz   bad           ; exactly 3 bytes

        mov   r7, 0
        ldb   r0, [r7]
        rol   r0, 4         ; swap nibbles
        cmp   r0, 0x24      ; swap('B')
        jnz   bad
        inc   r7
        ldb   r0, [r7]
        rol   r0, 4
        cmp   r0, 0x94      ; swap('I')
        jnz   bad
        inc   r7
        ldb   r0, [r7]
        rol   r0, 4
        cmp   r0, 0x45      ; swap('T')
        jnz   bad

        mov   r0, 1
        ret
bad:    mov   r0, 0
        ret