CRACK Solution
THRESHOLD
CRACK threshold count

Prerequisites
Unlocks
12JZ
Techniquethreshold count
Rulenonzero
Sample12JZ
Walkthrough
Recover the accepted input below, then submit it to the CRACK verifier.
Reject Samples
- 12J
- 12JZX
- 12JY
- 12KZ
- ???J
- @@`'
- AAAA
Verifier Listing
; e04_threshold: a real threshold gate. The old version accepted any string
; with a single byte at or above 0x40, so almost everything passed. This version
; pins three independent facts that the player must recover together:
; 1. the length is exactly 4 bytes,
; 2. exactly 2 of those bytes are at or above the threshold 0x40 ('@'),
; 3. the 16-bit sum of all 4 bytes equals 263 (0x0107).
; Technique: threshold count plus byte sum. The threshold count is the new idea;
; the sum is reused from CHECKSUM so a one-byte slip always breaks the total.
; r0 = 1 on accept. Accept rule: nonzero.
;
; The 8-bit registers cannot hold a 4-byte sum (up to 1020), so we keep the low
; byte in r3 and count the carries (the high byte) in r4 by hand, exactly as
; CHECKSUM does. target 263 = 0x0107 -> high byte 1, low byte 0x07.
;
; sample "12JZ": bytes 0x31 0x32 0x4a 0x5a.
; sum = 49 + 50 + 74 + 90 = 263 = 0x0107. (high 1, low 0x07)
; >= 0x40: 0x4a and 0x5a -> exactly 2 over the threshold.
len r1
cmp r1, 4
jnz bad ; exactly 4 bytes
mov r3, 0 ; r3 = running sum, low byte
mov r4, 0 ; r4 = running sum, high byte (carry count)
mov r5, 0 ; r5 = count of bytes at or above 0x40
mov r7, 0 ; index
loop: cmp r7, 4
jge final
ldb r0, [r7] ; r0 = next input byte
; --- accumulate the 16-bit sum -----------------------------------
add r3, r0 ; low += byte (wraps mod 256)
cmp r3, r0 ; if the new low is below the byte we added,
jge nocarry ; the add wrapped -> carry into the high byte
inc r4
nocarry:
; --- count bytes at or above the threshold 0x40 ------------------
cmp r0, 0x40
jl under ; below '@' does not count
inc r5
under:
inc r7
jmp loop
; --- all three facts must hold -----------------------------------
final: cmp r5, 2 ; exactly two bytes at or above the threshold
jnz bad
cmp r4, 1 ; sum high byte must be 1
jnz bad
cmp r3, 0x07 ; sum low byte must be 7
jnz bad
mov r0, 1
ret
bad: mov r0, 0
ret