"""Testhilfe (quick-261008-mzu): aktueller TOTP-Code zu einem Base32-Geheimnis. Aufruf: python3 -I totp.py """ import base64 import hashlib import hmac import struct import sys import time k = base64.b32decode(sys.argv[1].upper() + '=' * (-len(sys.argv[1]) % 8)) h = hmac.new(k, struct.pack('>Q', int(time.time()) // 30), hashlib.sha1).digest() o = h[-1] & 15 print('%06d' % ((struct.unpack('>I', h[o:o + 4])[0] & 0x7FFFFFFF) % 1000000))