[Odin] Test each secret, use valid to generate results[Odin] Test each secret, use valid to generate results
🔐
TOTP
Week 38, 2026
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
}