lewis-crawler/crawler_software/raspberry_pi/tests/otp/otp_test.py

26 lines
659 B
Python

from random import randrange
import time, pyotp, datetime
hotp = pyotp.HOTP(pyotp.random_base32())
success = 0
num_tries = 20
for i in range(0,num_tries):
epoch = int(time.time())
code = hotp.at(epoch)
print('------------------------')
print(f'Made a code {code} at {epoch}, sending a simualted instruction')
waittime = randrange(5)
print(f'Instuction will take {waittime} seconds to receive or be recieved')
time.sleep(waittime)
if hotp.verify(code, epoch):
print(f'code:{code} verified')
success += 1
else:
print(f'code:{code} expired')
print(f'Succeded {success} out of {num_tries} tries')