Problem H
TOTP Problem
TOTP
Use of multi-factor authentication is a recommend best
security practice for securing critical systems.
A common deployed second factor authentication is Time-based
one-time password (TOTP) base on IETF RFC 6238.
Write a program that computes 6 digit one-time password (OTP)
given a UTC date, time, and a base32 secret (size 128 bits or
160 bits).
OTP to be computed using standard HMAC SHA1.
OTP to be computed based on time window of 30 seconds from Unix
time UTC Jan 1, 1970 00:00:00.
Input
The input consists of multiple test cases one per line. Each
test case consists UTC date, time, and a base32 secret (size
128 bits or 160 bits). The input is terminated by end of
file.
Input line will only consist of valid input data. No invalid
date and time will be given.
Base32 encoding of secret based on IETF RFC 4648.
Output
For each input, output 6 digit OTP.
Sample Input 1 | Sample Output 1 |
---|---|
12/31/2023 18:52:35 BEROT2WTNL2ZZJQJDGEIC2TRWDQGXK2W 01/29/2024 12:30:00 CSIGU6O3PH3W2NS3OVWY4KCT6M====== |
999250 448651 |