TOTP in BQN
October 13, 2025 · View on GitHub
This is a simple implementation of the TOTP algorithm in
BQN, including most of its dependencies. Without comments, the code in
totp.bqn weighs in at around 50 lines; the
implementation follows the following RFC's:
- RFC 3174 for SHA1
- RFC 4648 for Base32 decoding
- RFC 2104 for HMAC
- RFC 4226 for HOTP
- RFC 6238 for TOTP
For ease of use—but don't actually use this, please—a main.bpn file is
provided that can read input from stdin:
$ echo "ZYTYYE5FOAGW5ML7LRWUL4WTZLNJAMZS" | bqn main.bqn
024999
Right now, the implementation is locked to a time step of 30, six digits, and SHA1 as the hashing algorithm. Incidentally, this covers 100% of my real-world use-cases for TOTP, so it seems like a sane minimal implementation.
Inspirations
The venerable mintotp.