Skip to content

Instantly share code, notes, and snippets.

View livingstonetech's full-sized avatar

livingstonetech

View GitHub Profile
@livingstonetech
livingstonetech / calculate_totp.py
Created April 29, 2019 07:16
Reference code to calculate TOTP, given a base32 secret.
#!/usr/bin/env python3
"""
Gist to calculate Time-based One Time Password (TOTP).
This function is designed to be used in two modes:
- Current Mode
No timestamp supplied, and the current timestamp is considered.
This mode gives the totp at the present moment in time.
- Historic Mode
Here an explicit timestamp is supplied. This is to calculate a TOTP
that had occured at a moment in history.