1
0
Fork
You've already forked totp
0
Simple TOTP generator in BQN
  • BQN 85%
  • Nix 15%
Tony Zorman 3ba559fbd0 Use ⌽ ̄4↑ instead of 4↑⌽
This is one more character and perhaps not as æsthetic, but reversing
that whole array seems like a waste just to get to the last four bits.
Plus, at this point ×ばつ⊸+ ̃ ́⌽ feels like a block itself to me, and having
the reverse baked into the previous manipulation might be annoying when
re-reading this part of the code.
2025年10月15日 15:24:10 +02:00
.envrc Initial commit 2025年10月13日 13:41:02 +02:00
.gitignore Initial commit 2025年10月13日 13:41:02 +02:00
flake.lock Initial commit 2025年10月13日 13:41:02 +02:00
flake.nix Initial commit 2025年10月13日 13:41:02 +02:00
LICENSE Initial commit 2025年10月13日 13:41:02 +02:00
main.bqn Initial commit 2025年10月13日 13:41:02 +02:00
README.md README: Cite mintotp 2025年10月13日 19:38:35 +02:00
tests.bqn Use ⌽ ̄4↑ instead of 4↑⌽ 2025年10月15日 15:24:10 +02:00
totp.bqn Use ⌽ ̄4↑ instead of 4↑⌽ 2025年10月15日 15:24:10 +02:00

TOTP in BQN

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:

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.