Skip to content

Instantly share code, notes, and snippets.

@tsmolka
Created January 31, 2017 13:30
Show Gist options
  • Select an option

  • Save tsmolka/cb023503d419e7366ada9de52149f10e to your computer and use it in GitHub Desktop.

Select an option

Save tsmolka/cb023503d419e7366ada9de52149f10e to your computer and use it in GitHub Desktop.
Derive current OTP-auth tokens from secret (e.g. as in Google Authenticator)
"""
Prerequisites (install using easy_install or pip):
otpauth argparse
Sample token: https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/user@host%3Fsecret%3DAAAAAAAAAAAAAAAA
Usage: python otp.py --secret AAAAAAAAAAAAAAAA
"""
import argparse, time
from otpauth import generate_totp
from base64 import b32decode
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='OTP (e.g. Google Authenticator)')
parser.add_argument('-s', '--secret', required=True)
args = parser.parse_args()
print generate_totp(b32decode(args.secret))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment