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. |
||
|---|---|---|
| .envrc | Initial commit | |
| .gitignore | Initial commit | |
| flake.lock | Initial commit | |
| flake.nix | Initial commit | |
| LICENSE | Initial commit | |
| main.bqn | Initial commit | |
| README.md | README: Cite mintotp | |
| tests.bqn | Use ⌽ ̄4↑ instead of 4↑⌽ | |
| totp.bqn | Use ⌽ ̄4↑ instead of 4↑⌽ | |
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:
- 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.