<commit_before>import hashlib
import base64
import itertools

from v0ltlib.utils.v0lt_utils import red, fail

'''
Some basic functions used in easy crypto challenge

TODO: Make ceasar with yield, stuff like this
'''

def ceasar(string, offset=0):
    upper_bound = 128 - 32
    if offset != 0:
        encrypted = ''
        for each in string:
            p = 32 + ((ord(each) + offset) % upper_bound)
            encrypted += chr(p)
        return encrypted
    else:
        for i in range(0, upper_bound + 32):
            plaintext = ''
            for each in string:
                p = 32 + ((ord(each) - i) % upper_bound)
                plaintext += chr(p)
            print("{0}: {1}".format(i, plaintext))


def basic_ceasar(string, offset=0):
    # If ofset == 0, bruteforce all possibilities

    string = string.upper()
    alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    upper_bound = len(alphabet)

    if offset != 0:
        encrypted = ''

        for c in string:
            if c == " ":
                encrypted += " "
            else:
                if c in alphabet:
                    encrypted += alphabet[(alphabet.index(c) + offset) % upper_bound]
        return encrypted

    else:
        for i in range(upper_bound, 0, -1):
            plaintext = ''

            for c in string:
                if c == " ":
                    plaintext += " "
                else:
                    if c in alphabet:
                        plaintext += alphabet[(alphabet.index(c) + i) % upper_bound]
            print("{0}: {1}".format(upper_bound - i, plaintext))


def xor_str(s, key):
    return "".join(chr(ord(c) ^ ord(k)) for c, k in zip(s, itertools.cycle(key)))


def str_inv_xor(key, xored):
    for i, char_xored in enumerate(xored):
        found = 0

        for char in range(32, 128):
            if char ^ ord(key[i]) == ord(char_xored):
                print(chr(char), end="")
                found = 1
                break

        if not found:
            print(red("X"), end="")


def int_inv_xor(key, xored):
    for i, char_xored in enumerate(xored):
        found = 0

        for char in range(32, 128):
            if char ^ key[i] == char_xored:<commit_msg>Suppress redundant function<commit_after>import hashlib
import base64
import itertools

from v0ltlib.utils.v0lt_utils import red, fail

'''
Some basic functions used in easy crypto challenge

TODO: Make ceasar with yield, stuff like this
'''

def ceasar(string, offset=0):
    upper_bound = 128 - 32
    if offset != 0:
        encrypted = ''
        for each in string:
            p = 32 + ((ord(each) + offset) % upper_bound)
            encrypted += chr(p)
        return encrypted
    else:
        for i in range(0, upper_bound + 32):
            plaintext = ''
            for each in string:
                p = 32 + ((ord(each) - i) % upper_bound)
                plaintext += chr(p)
            print("{0}: {1}".format(i, plaintext))


def basic_ceasar(string, offset=0):
    # If ofset == 0, bruteforce all possibilities

    string = string.upper()
    alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    upper_bound = len(alphabet)

    if offset != 0:
        encrypted = ''

        for c in string:
            if c == " ":
                encrypted += " "
            else:
                if c in alphabet:
                    encrypted += alphabet[(alphabet.index(c) + offset) % upper_bound]
        return encrypted

    else:
        for i in range(upper_bound, 0, -1):
            plaintext = ''

            for c in string:
                if c == " ":
                    plaintext += " "
                else:
                    if c in alphabet:
                        plaintext += alphabet[(alphabet.index(c) + i) % upper_bound]
            print("{0}: {1}".format(upper_bound - i, plaintext))


def str_inv_xor(key, xored):
    for i, char_xored in enumerate(xored):
        found = 0

        for char in range(32, 128):
            if char ^ ord(key[i]) == ord(char_xored):
                print(chr(char), end="")
                found = 1
                break

        if not found:
            print(red("X"), end="")


def int_inv_xor(key, xored):
    for i, char_xored in enumerate(xored):
        found = 0

        for char in range(32, 128):
            if char ^ key[i] == char_xored:
{'fraction_non_alphanumeric': 0.11495047224141902, 'fraction_numerical': 0.018428933425478, 'mean_word_length': 1.6703567035670357, 'pattern_counts': {'":': 4, '<': 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': '4866787', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1296, 'n_words': 383}