All SolutionsAll Solutions

🔐

TOTP

Week 38, 2026

Test each secret, use valid to generate results | greenya | Odin Solutions

package main import "core:fmt" import "core:slice" main :: proc () { next_secret: for secret in 0..=255 { fmt.printfln("Checking secret: %i", secret) for test in ([?] [2] int { { 1785818743, 995543 }, { 1785818761, 399222 }, { 1785818823, 988976 }, }) { if test[1] != otp_gen(test[0], secret) { continue next_secret } } fmt.println("Found! The result OTPs:") for timestamp in ([?] int { 123456789, 1798156817, 1798761646 }) { otp := otp_gen(timestamp, secret) fmt.printfln("%i: %i", timestamp, otp) } break } } otp_gen :: proc (timestamp: int, secret: int) -> int { ts := timestamp / 30 buf: [32] u8 str := fmt.bprint(buf[:], ts) slice.reverse(transmute ([] u8) str) value := ts + secret for c in str do if c != '0' do value *= int(c-'0') for (value/10)*10 == value do value /= 10 return value%1000000 }

Test each secret, use valid to generate results | greenya | Odin Solutions

package main import "core:fmt" import "core:slice" main :: proc () { next_secret: for secret in 0..=255 { fmt.printfln("Checking secret: %i", secret) for test in ([?] [2] int { { 1785818743, 995543 }, { 1785818761, 399222 }, { 1785818823, 988976 }, }) { if test[1] != otp_gen(test[0], secret) { continue next_secret } } fmt.println("Found! The result OTPs:") for timestamp in ([?] int { 123456789, 1798156817, 1798761646 }) { otp := otp_gen(timestamp, secret) fmt.printfln("%i: %i", timestamp, otp) } break } } otp_gen :: proc (timestamp: int, secret: int) -> int { ts := timestamp / 30 buf: [32] u8 str := fmt.bprint(buf[:], ts) slice.reverse(transmute ([] u8) str) value := ts + secret for c in str do if c != '0' do value *= int(c-'0') for (value/10)*10 == value do value /= 10 return value%1000000 }

py | shallowspirit | Python Solutions

def gen_otp(timestamp, secret): part1 = timestamp // 30 total = part1 + secret digits = str(part1)[::-1] for d in digits: d = int(d) if d == 0: continue total = d * total s = str(total) s = s.rstrip('0') if s == '': s = '0' otp = s[-6:] if len(s) >= 6 else s.zfill(6) return otp # Known OTPs shoulder-surfed from the suspect's phone targets = { 1785818743: "995543", 1785818761: "399222", 1785818823: "988976", } # Brute-force every possible 8-bit secret key (0-255) for secret in range(256): ok = True for ts, expected in targets.items(): got = gen_otp(ts, secret) if got != expected: ok = False break if ok: print("Found secret:", secret) # Once found, generate OTPs for the required timestamps secret = 38 for ts in [123456789, 1798156817, 1798761646]: print(ts, gen_otp(ts, secret))