Skip to content

Instantly share code, notes, and snippets.

@rcoh
rcoh / otp.py
Last active September 19, 2025 04:44
An implementation of Google Authenticator Compatible 2-factor Codes
"""
An implementation of TOTP as described in https://tools.ietf.org/html/rfc6238#section-4 aka Google Authenticator Style 2-factor Auth
"""
import base64
import datetime
import hashlib
import hmac
import sys
import struct
import time