Skip to content

Instantly share code, notes, and snippets.

@WorkingRobot
Created January 14, 2023 00:48
Show Gist options
  • Save WorkingRobot/3b5116154b88c85cfca311faf8b6a47f to your computer and use it in GitHub Desktop.
Save WorkingRobot/3b5116154b88c85cfca311faf8b6a47f to your computer and use it in GitHub Desktop.
Converts totp secret to Steam code
# Steam uses the standard totp algorithm but instead of displaying the value modulo 1000000, it converts the value to a base26 string
# Take the uri from the generated .maFile from https://github.com/Jessecar96/SteamDesktopAuthenticator
# Make sure to select no encryption so you can open the json from a text editor
# Ported from https://github.com/geel9/SteamAuth/blob/96ca6af3eb03d1a45f7fbff78851f055ba47c0d4/SteamAuth/SteamGuardAccount.cs#L85
from base64 import b32decode
from hmac import digest
from time import time
# otpauth://totp/Steam:(username)?secret=(secret)&issuer=Steam
# Take this value and input it here ^^^^^^
key_b32 = input("Secret: ")
key = b32decode(key_b32)
t = time()
t_rounded = int(t // 30)
t_bytes = t_rounded.to_bytes(8, byteorder='big')
d = digest(key, t_bytes, 'sha1')
d_offset = d[len(d) - 1] & 0x0F
d_value = (d[d_offset] & 0x7F) << 24 | (d[d_offset + 1] & 0xFF) << 16 | (d[d_offset + 2] & 0xFF) << 8 | (d[d_offset + 3] & 0xFF)
alpha_lut = "23456789BCDFGHJKMNPQRTVWXY"
code = ""
for n in range(5):
code += alpha_lut[d_value % len(alpha_lut)]
d_value //= len(alpha_lut)
print(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment