<commit_before>#!/usr/bin/python
# coding: utf8

"""
The cryptopals crypto challenges
Challenge: Single-byte XOR cipher
url: https://cryptopals.com/sets/1/challenges/3
"""

import sys
import codecs
import collections
import string


def decode_hex_string(hex_string):
    """
    Decodes hex string
    """
    return codecs.encode(codecs.decode(hex_string, 'hex'))


def find_most_frequent_character(ciphertext):
    """
    Find and return the character with the maximum occurrences
    """
    return collections.Counter(ciphertext).most_common(1)[0][0]


def decipher_text(ciphertext, xor_key):
    """
    Recover the plaintext from the ciphertext
    """
    text = ""
    for i in ciphertext:
        text += chr(ord(i) ^ xor_key)
    return text.lower()


def find_key_from_frequent_characters(character):
    """
    Key = cipher_character xor character_in_clear
    We create a list of potential Keys for each character in frequent_character
    """
    frequent_characters = "etaoin shrdlu"
    keys = list()
    for i in frequent_characters:
        keys.append(ord(character) ^ ord(i))
    return keys


def score(word_list, language_dictionary):
    """
    Iterates on each word and try to find a match in a language dictionary.
    """<commit_msg>update: Set 1 challenge_3<commit_after>#!/usr/bin/python
# coding: utf8

"""
The cryptopals crypto challenges
Challenge: Single-byte XOR cipher
url: https://cryptopals.com/sets/1/challenges/3
"""

import sys
import codecs
import collections
import string


def decode_hex_string(hex_string):
    """
    Decodes hex string
    """
    return codecs.encode(codecs.decode(hex_string, 'hex'))


def find_most_frequent_character(ciphertext):
    """
    Find and return the character with the maximum occurrences
    """
    return collections.Counter(ciphertext).most_common(1)[0][0]


def decipher_text(ciphertext, xor_key):
    """
    Recover the plaintext from the ciphertext
    """
    text = ""
    for i in ciphertext:
        text += chr(ord(i) ^ xor_key)
    return text.lower()


def find_key_from_frequent_characters(character):
    """
    Key = cipher_character xor character_in_clear
    We create a list of potential Keys for each character in frequent_character
    """
    frequent_characters = "etaoin shrdlu"
    keys = [ord(character) ^ ord(frequent_char) for frequent_char in frequent_characters]
    return keys


def score(word_list, language_dictionary):
    """
    Iterates on each word and try to find a match in a language dictionary.
    """
{'fraction_non_alphanumeric': 0.09679968391939944, 'fraction_numerical': 0.005531410509679968, 'mean_word_length': 3.688888888888889, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1774314', 'n_tokens_mistral': 813, 'n_tokens_neox': 766, 'n_words': 220}