print("Solution to challenge 3 of set 1")
initial_hex = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'
print("Initial hex string is: ")
print(initial_hex)

text = bytearray.fromhex(initial_hex)
#print(text)

def keyxor(inp, key):
    out = b''
    for byte in inp:
        out += bytes([byte ^ key])
    return out


# stage two: make it rank the solutions based on how english-y they feel
# compare to character frequency in english and rank
# then print out the best one
def vibe_check(byt_str):
        char_freq = {
        'a': .08167, 'b': .01492, 'c': .02782, 'd': .04253,
        'e': .12702, 'f': .02228, 'g': .02015, 'h': .06094,
        'i': .06094, 'j': .00153, 'k': .00772, 'l': .04025,
        'm': .02406, 'n': .06749, 'o': .07507, 'p': .01929,
        'q': .00095, 'r': .05987, 's': .06327, 't': .09056,
        'u': .02758, 'v': .00978, 'w': .02360, 'x': .00150,
        'y': .01974, 'z': .00074, ' ': .13000
    }
        lower = byt_str.lower()
        return sum([char_freq.get(chr(byte), 0) for byte in lower])

maybes = []
for i in range(256):
    message = keyxor(text, i)
    rank = vibe_check(message)
    vals = {
            'coded message': message,
            'rank': rank,
            'xor key': i
            }
    maybes.append(vals)
    winner = sorted(maybes, key = lambda x: x['rank'], reverse=True)[0]
print("Solutions is: ", winner['coded message'])


# References: read these for algorithm help
# https://laconicwolf.com/2018/05/29/cryptopals-challenge-3-single-byte-xor-cipher-in-python/
# https://cryptik.io/83/cryptopals-write-up-set-1-challenge-3/ 

efb581926ddd2bc9bb0a4eebc6141be8b52bc624
<mask token>

<mask token>


def keyxor(inp, key):
    out = b''
    for byte in inp:
        out += bytes([byte ^ key])
    return out


def vibe_check(byt_str):
    char_freq = {'a': 0.08167, 'b': 0.01492, 'c': 0.02782, 'd': 0.04253,
        'e': 0.12702, 'f': 0.02228, 'g': 0.02015, 'h': 0.06094, 'i': 
        0.06094, 'j': 0.00153, 'k': 0.00772, 'l': 0.04025, 'm': 0.02406,
        'n': 0.06749, 'o': 0.07507, 'p': 0.01929, 'q': 0.00095, 'r': 
        0.05987, 's': 0.06327, 't': 0.09056, 'u': 0.02758, 'v': 0.00978,
        'w': 0.0236, 'x': 0.0015, 'y': 0.01974, 'z': 0.00074, ' ': 0.13}
    lower = byt_str.lower()
    return sum([char_freq.get(chr(byte), 0) for byte in lower])


<mask token>

print('Solution to challenge 3 of set 1')
<mask token>
print('Initial hex string is: ')
print(initial_hex)
<mask token>


def keyxor(inp, key):
    out = b''
    for byte in inp:
        out += bytes([byte ^ key])
    return out


def vibe_check(byt_str):
    char_freq = {'a': 0.08167, 'b': 0.01492, 'c': 0.02782, 'd': 0.04253,
        'e': 0.12702, 'f': 0.02228, 'g': 0.02015, 'h': 0.06094, 'i': 
        0.06094, 'j': 0.00153, 'k': 0.00772, 'l': 0.04025, 'm': 0.02406,
        'n': 0.06749, 'o': 0.07507, 'p': 0.01929, 'q': 0.00095, 'r': 
        0.05987, 's': 0.06327, 't': 0.09056, 'u': 0.02758, 'v': 0.00978,
        'w': 0.0236, 'x': 0.0015, 'y': 0.01974, 'z': 0.00074, ' ': 0.13}
    lower = byt_str.lower()
    return sum([char_freq.get(chr(byte), 0) for byte in lower])


<mask token>
for i in range(256):
    message = keyxor(text, i)
    rank = vibe_check(message)
    vals = {'coded message': message, 'rank': rank, 'xor key': i}
    maybes.append(vals)
    winner = sorted(maybes, key=lambda x: x['rank'], reverse=True)[0]
print('Solutions is: ', winner['coded message'])

print('Solution to challenge 3 of set 1')
initial_hex = (
    '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736')
print('Initial hex string is: ')
print(initial_hex)
text = bytearray.fromhex(initial_hex)


def keyxor(inp, key):
    out = b''
    for byte in inp:
        out += bytes([byte ^ key])
    return out


def vibe_check(byt_str):
    char_freq = {'a': 0.08167, 'b': 0.01492, 'c': 0.02782, 'd': 0.04253,
        'e': 0.12702, 'f': 0.02228, 'g': 0.02015, 'h': 0.06094, 'i': 
        0.06094, 'j': 0.00153, 'k': 0.00772, 'l': 0.04025, 'm': 0.02406,
        'n': 0.06749, 'o': 0.07507, 'p': 0.01929, 'q': 0.00095, 'r': 
        0.05987, 's': 0.06327, 't': 0.09056, 'u': 0.02758, 'v': 0.00978,
        'w': 0.0236, 'x': 0.0015, 'y': 0.01974, 'z': 0.00074, ' ': 0.13}
    lower = byt_str.lower()
    return sum([char_freq.get(chr(byte), 0) for byte in lower])


maybes = []
for i in range(256):
    message = keyxor(text, i)
    rank = vibe_check(message)
    vals = {'coded message': message, 'rank': rank, 'xor key': i}
    maybes.append(vals)
    winner = sorted(maybes, key=lambda x: x['rank'], reverse=True)[0]
print('Solutions is: ', winner['coded message'])

print("Solution to challenge 3 of set 1")
initial_hex = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'
print("Initial hex string is: ")
print(initial_hex)

text = bytearray.fromhex(initial_hex)
#print(text)

def keyxor(inp, key):
    out = b''
    for byte in inp:
        out += bytes([byte ^ key])
    return out


# stage two: make it rank the solutions based on how english-y they feel
# compare to character frequency in english and rank
# then print out the best one
def vibe_check(byt_str):
        char_freq = {
        'a': .08167, 'b': .01492, 'c': .02782, 'd': .04253,
        'e': .12702, 'f': .02228, 'g': .02015, 'h': .06094,
        'i': .06094, 'j': .00153, 'k': .00772, 'l': .04025,
        'm': .02406, 'n': .06749, 'o': .07507, 'p': .01929,
        'q': .00095, 'r': .05987, 's': .06327, 't': .09056,
        'u': .02758, 'v': .00978, 'w': .02360, 'x': .00150,
        'y': .01974, 'z': .00074, ' ': .13000
    }
        lower = byt_str.lower()
        return sum([char_freq.get(chr(byte), 0) for byte in lower])

maybes = []
for i in range(256):
    message = keyxor(text, i)
    rank = vibe_check(message)
    vals = {
            'coded message': message,
            'rank': rank,
            'xor key': i
            }
    maybes.append(vals)
    winner = sorted(maybes, key = lambda x: x['rank'], reverse=True)[0]
print("Solutions is: ", winner['coded message'])


# References: read these for algorithm help
# https://laconicwolf.com/2018/05/29/cryptopals-challenge-3-single-byte-xor-cipher-in-python/
# https://cryptik.io/83/cryptopals-write-up-set-1-challenge-3/ 
