Skip to content

Instantly share code, notes, and snippets.

@tiagoapimenta
Last active July 20, 2022 17:53
Show Gist options
  • Save tiagoapimenta/c7d7058c7466ce79c6e28749c74dc9dc to your computer and use it in GitHub Desktop.
Save tiagoapimenta/c7d7058c7466ce79c6e28749c74dc9dc to your computer and use it in GitHub Desktop.
Steam Guard Token Generator
#!/bin/sh
set -e
# To get the Secret value follow this:
# https://github.com/steamguard-totp/steamguard-shared-secret
# Don't forget to unescape '/' if there is
file="$(dirname "$(readlink -f "$0")")/steam.secret"
time=$(date -u +%s)
chars='23456789BCDFGHJKMNPQRTVWXY'
len=${#chars}
sha=$(
printf '00000000%08x' "$(((time + 3600 * 0) / 30))" |
xxd -r -p |
openssl sha1 -mac HMAC -macopt "hexkey:$(
base64 -d < "$file" | xxd -p
)" |
cut -d\ -f2
)
start=$(printf '%d' "0x$(printf '%s' "$sha" | tail -c1)")
code=$(($(
printf '%d' "0x$(
printf '%s' "$sha" | tail "-c+$((start * 2 + 1))" | head -c8
)"
) & 0x7FFFFFFF))
for n in $(seq 1 5); do
printf '%s' "$chars" | tail -c+$((code % len + 1)) | head -c1
code=$((code / len))
done
printf '\nRemaining: %ss\n' "$((30 - time % 30))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment