This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hex_str = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d" | |
decoded = hex_str.decode("hex") | |
# I'm killing your brain like a poisonous mushroom | |
base64_str = decoded.encode("base64") | |
# SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t\n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def xor(b1, b2): | |
b = bytearray(len(b1)) | |
for i in range(len(b1)): | |
b[i] = b1[i] ^ b2[i] | |
return b | |
b1 = bytearray.fromhex("1c0111001f010100061a024b53535009181c") | |
b2 = bytearray.fromhex("686974207468652062756c6c277320657965") | |
b = bytes(xor(b1, b2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def xor(b1, b2): | |
b = bytearray(len(b1)) | |
for i in range(len(b1)): | |
b[i] = b1[i] ^ b2[i] | |
return b | |
def score(s): | |
freq = {} | |
freq[' '] = 700000000 | |
freq['e'] = 390395169 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def score(s): | |
freq = {} | |
freq[' '] = 700000000 | |
freq['e'] = 390395169 | |
freq['t'] = 282039486 | |
freq['a'] = 248362256 | |
freq['o'] = 235661502 | |
# ... | |
freq['z'] = 2456495 | |
score = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def xor(b1, b2): | |
b = bytearray(len(b1)) | |
for i in range(len(b1)): | |
b[i] = b1[i] ^ b2[i] | |
return b | |
def score(s): | |
freq = {} | |
freq[' '] = 700000000 | |
freq['e'] = 390395169 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max_score = None | |
english_plaintext = None | |
key = None | |
for line in open("4.txt", "r"): | |
line = line.rstrip() | |
b1 = bytearray.fromhex(line) | |
for i in range(256): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lines = [ | |
"Burning 'em, if you ain't quick and nimble\n", | |
"I go crazy when I hear a cymbal", | |
] | |
text = "".join(lines) | |
key = bytearray("ICE" * len(text)) | |
plaintext = bytes(xor(bytearray(text), key)) | |
plaintext.encode("hex") | |
# 0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def xor(b1, b2): | |
b = bytearray(len(b1)) | |
for i in range(len(b1)): | |
b[i] = b1[i] ^ b2[i] | |
return b | |
lines = [ | |
"Burning 'em, if you ain't quick and nimble\n", | |
"I go crazy when I hear a cymbal", | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hamming_distance(enc_str1, enc_str2): | |
differing_bits = 0 | |
for byte in xor(b1, b2): | |
differing_bits += bin(byte).count("1") | |
return differing_bits | |
b1 = bytearray("this is a test") | |
b2 = bytearray("wokka wokka!!!") | |
hamming_distance(b1, b2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b = bytearray("".join(list(open("6.txt", "r"))).decode("base64")) | |
normalized_distances = [] | |
for KEYSIZE in range(2, 40): | |
b1 = b[:KEYSIZE] | |
b2 = b[KEYSIZE:KEYSIZE*2] | |
b3 = b[KEYSIZE*2:KEYSIZE*3] | |
b4 = b[KEYSIZE*3:KEYSIZE*4] | |
normalized_distance = float( |
OlderNewer