Compare commits

..

3 Commits

Author SHA1 Message Date
e165dc107f future cli program 2025-08-24 00:50:05 +02:00
e18953b287 Corrects left padding with zeroes 2025-08-24 00:33:08 +02:00
290c52a71f Version with 1 parameter that gets current time 2025-08-24 00:25:10 +02:00
3 changed files with 19 additions and 13 deletions

3
src/totp/app.clj Normal file
View File

@@ -0,0 +1,3 @@
(ns totp.app
( :require [totp.core :refer :all]))

View File

@@ -71,7 +71,7 @@
(defn get-otp
"Generate an OTP with the given secret (in base32) for the specified timestep"
[secret step]
([secret step]
(when (and secret step)
(let [k (b32/decode secret)
c (long->bytes step)
@@ -79,7 +79,9 @@
offset (bit-and (get hs (dec (count hs))) 0x0f) ;; int offset = hs[hs.length-1] & 0xf;
chunk (Arrays/copyOfRange hs offset (+ offset 4)) ;(take 4 (drop offset hs)) ;; byte[] chunk = Arrays.copyOfRange(hs, offset, offset+4)
]
(format "%6d" (-> chunk
(format "%06d" (-> chunk
(bytes->int)
(bit-and 0x7fffffff)
(rem 1000000))))))
([secret]
(get-otp secret (timestamp->steps (System/currentTimeMillis) 30))))

View File

@@ -67,4 +67,5 @@
(is (nil? (get-otp nil "")))
(is (nil? (get-otp nil 1000))))
(testing "Common usage"
(is (= "837552" (get-otp "MJXW42LBORXQ====" 10000)))))
(is (= "837552" (get-otp "MJXW42LBORXQ====" 10000)))
(is (= 6 (count (get-otp "MJXW42LBORXQ===="))))))