Last active
August 18, 2022 22:25
-
-
Save plambrechtsen/21f80c0b8b3ad226fa9854fe9a1983c0 to your computer and use it in GitHub Desktop.
Convert TOTP Tokens Seeds from Base32 to Base16/HEX and vice versa based on input CSV.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Convert TOTP Base32 Seeds into Base16/Hex format and vice versa based on CSV with: | |
SerialNumber,SeedValue | |
If the seed value isn't a valid Base32 then the base32 decoder will exception so assume it's Base16/Hex | |
''' | |
import base64 | |
import sys | |
filename = 'seeds.csv' | |
if len(sys.argv) > 1: | |
filename = sys.argv[1] | |
print(f'Using seed file {filename}') | |
with open(filename.replace('.csv', '-output.csv'), 'w') as seed_output_file: | |
seed_output_file.writelines('SerialNumber,Type,Base32,HEX\n') | |
with open(filename, 'r') as seed_file: | |
lines = seed_file.readlines() | |
for line in lines: | |
line_split = line.split(',') | |
if len(line_split) >= 1: | |
seed = line_split[1].strip() | |
try: | |
seed_output_file.writelines(f'{line_split[0]},Base32,{seed},{base64.b16encode(base64.b32decode(seed)).decode("utf-8")}') | |
except Exception as e: | |
seed_output_file.writelines(f'{line_split[0]},HEX,{base64.b32encode(base64.b16decode(seed)).decode("utf-8")},{seed}') | |
seed_output_file.write("\n") | |
seed_output_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment