Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python3
import re
import argparse
from colorama import init, Fore, Style
from terminaltables import DoubleTable
def main():
args = usage()
clean_id = re.sub('[-Y]', '', args.ID)
res = decode(clean_id)
print_data(res)
def usage():
parser = argparse.ArgumentParser(description='Decode Spora ID')
parser.add_argument("ID", type=str, help="Spora ID (eg. RU302-15XRK-GXTFO-GZTET-KTXFF-ORTXA-AYYYY)")
return parser.parse_args()
def decode(ID):
DELIM = "T"
SBOX_IN = "ZXROAHFGEK"
SBOX_OUT = "0123456789"
TRANS = str.maketrans(SBOX_IN, SBOX_OUT)
res = {}
res.update({"country": ID[0:2]})
res.update({"hash": ID[2:7]})
res.update({"stats": [elem.translate(TRANS) for elem in ID[7:].split(DELIM)]})
return res
def print_data(id_dict):
init(autoreset=True)
data = []
data.append(("{}Country{}".format(Fore.GREEN, Style.RESET_ALL),
"{}Hash{}".format(Fore.GREEN, Style.RESET_ALL),
"{}Office Document{}".format(Fore.GREEN, Style.RESET_ALL),
"{}PDF{}".format(Fore.GREEN, Style.RESET_ALL),
"{}CorelDraw, AutoCAD, Photoshop{}".format(Fore.GREEN, Style.RESET_ALL),
"{}DB{}".format(Fore.GREEN, Style.RESET_ALL),
"{}Image{}".format(Fore.GREEN, Style.RESET_ALL),
"{}Archive{}".format(Fore.GREEN, Style.RESET_ALL)))
data.append((id_dict['country'],
id_dict['hash'],
id_dict['stats'][0],
id_dict['stats'][1],
id_dict['stats'][2],
id_dict['stats'][3],
id_dict['stats'][4],
id_dict['stats'][5]))
table_instance = DoubleTable(data, "{}Spora ID Table{}".format(Fore.RED, Style.RESET_ALL))
print(table_instance.table)
if __name__ == "__main__":
main()
@sdshlanta

This comment has been minimized.

Copy link

commented Mar 30, 2017

thanks fam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.