<commit_before>#!/usr/bin/python3

import string
import argparse
import base64
import binascii
import sys

# Coming Later
# def rotn(message, n=13):
#    code_alphabet = string.ascii_lowercase[n:] + string.ascii_lowercase[0:n]
#    return message.lower().translate(string.maketrans(string.ascii_lowercase, code_alphabet))

def parseArgs():
    parser = argparse.ArgumentParser(description="Tries many different \
                    encodings so you can figure out WTF is this string")
    parser.add_argument('datafile', type=str,
                        help="The file with the data to decode")

    args = parser.parse_args()
    return args

# Is there a way to iterate over these functions instead?
# Might be nicer
def baseDecode(data):
    try:
        print("Base16: " + str(base64.b16decode(data, casefold=True)))
    except binascii.Error:
        print("Cannot be Base16")

    try:
        print("Base32: " + str(base64.b32decode(data, casefold=True)))
    except binascii.Error:
        print("Cannot be Base32")

    try:
        print("Base64: " + str(base64.b64decode(data)))
    except binascii.Error:
        print("Cannot be Base64")

    try:
        print("Base85: " + str(base64.b85decode(data)))
    except:
        print("Cannot be Base85")

    try:
        print("Ascii85: " + str(base64.a85decode(data)))
    except:
        print("Cannot be Ascii85")

if __name__ == "__main__":
    try:
        wtfstring = open(parseArgs().datafile, 'rb').read()
    except:
        print("Cannot Open file")
        sys.exit()
        
    baseDecode(wtfstring)
<commit_msg>Colored printing and better error detectio<commit_after>#!/usr/bin/python3

import base64
import argparse
from termcolor import cprint

rprint = lambda x: cprint(x, 'red')
gprint = lambda x: cprint(x, 'white')


def parseArgs():
    parser = argparse.ArgumentParser(description="Tries many different \
                    encodings so you can figure out WTF is this string")
    parser.add_argument('datafile', type=str,
                        help="The file with the data to decode")

    return parser.parse_args()


def baseDecode(data):
    try:
        gprint("Base16: " + str(base64.b16decode(data, casefold=True)))
    except Exception as e:
        rprint("Cannot be Base16 : " + str(e))

    try:
        gprint("Base32: " + str(base64.b32decode(data, casefold=True)))
    except Exception as e:
        rprint("Cannot be Base32 : " + str(e))

    try:
        gprint("Base64: " + str(base64.b64decode(data)))
    except Exception as e:
        rprint("Cannot be Base64 : " + str(e))

    try:
        gprint("Base85: " + str(base64.b85decode(data)))
    except Exception as e:
        rprint("Cannot be Base85 : " + str(e))

    try:
        gprint("Ascii85: " + str(base64.a85decode(data)))
    except Exception as e:
        rprint("Cannot be Ascii85 : " + str(e))


def main():
    args = parseArgs()

    try:
        wtfstring = open(args.datafile, 'rb').read()
    except Exception:
        rprint("Cannot open " + args.datafile)
        return

    baseDecode(wtfstring)

if __name__ == "__main__":
    main()

{'fraction_non_alphanumeric': 0.12259306803594351, 'fraction_numerical': 0.028562259306803596, 'mean_word_length': 2.791970802919708, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '764583', 'n_tokens_mistral': 1053, 'n_tokens_neox': 976, 'n_words': 248}