Created
January 15, 2020 21:52
-
-
Save atucom/b4adc9cae195e4a6ac5b2ee86386c51c to your computer and use it in GitHub Desktop.
Solution to Cryptopals Challenge 4
This file contains hidden or 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
import langdetect | |
from langdetect import detect | |
def ascii_hex_to_bytes(hex_input): | |
return bytearray.fromhex(hex_input) | |
with open('Downloads/cryptopals-challenge4.txt') as f: | |
xorinput=f.readlines() | |
xor2 = [line.strip() for line in xorinput] | |
xorinput = xor2 | |
for line in xorinput: | |
input_bytes=ascii_hex_to_bytes(line) | |
for integer in range(0,256): | |
candidate_xor = [] | |
for byte in input_bytes: | |
candidate_xor.append(byte ^ integer) | |
decoded="".join([chr(element) for element in candidate_xor]) | |
try: | |
if 'en' in detect(decoded) and decoded.isascii(): | |
print(decoded) | |
except langdetect.lang_detect_exception.LangDetectException: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment