def main(in_file='7.txt', key_str=b'YELLOW SUBMARINE'): # Convert input base64 to byte array enc_bytes = b64.decode_file(in_file) # Decrypt plain_bytes = AES.ECB_decrypt(key_str, enc_bytes) # Print output print(utils.bytes_string(plain_bytes))
def main(hex_str='1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'): # Convert input to bytes bytes = utils.hexstr_bytes(hex_str) # Perfomr decryption decrypted_bytes = XOR_1B_decrypt(bytes); # Print output print(utils.bytes_string(decrypted_bytes));
def main(file_name='10.txt', key=b'YELLOW SUBMARINE'): # Extract raw data from file bytes = b64.decode_file(file_name) # Set default IV iv = bytearray([0] * AES.block_size) # Decrypt the file plain = AES.CBC_decrypt(key, bytes, iv) # Print output print(utils.bytes_string(plain))
def main( hexstr='49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d' ): # Convert to bytes bytes = utils.hexstr_bytes(hexstr) # Calculate base64 bytes enc_bytes = b64.encode(bytes) # Convert bytes to string str = utils.bytes_string(enc_bytes) print(str)
def main(): # Create 'admin' block with padding enc1 = profile_encrypt( profile_encode( profile_for("*****@*****.**" + "admin" + utils.bytes_string(bytes([11] * 11))))) # Create target email account enc2 = profile_encrypt(profile_encode(profile_for("*****@*****.**"))) # Concatinate target + admin blocks enc = enc2[0:32] + enc1[16:32] # Decrypt new profile dec = profile_decode(profile_decrypt(enc)) print(dec)
def main(in_file='6.txt'): # Extract bytes enc_bytes=b64.decode_file(in_file) print (enc_bytes, len(enc_bytes)) # Guess key size keysizes = get_keysize(enc_bytes) # Decrypt with each keysize (we try only few best candidates) # then score the decrypted text with english score and determine best decryption guesses = {} for k in keysizes[0:5]: dec_bytes = decrypt_per_keysize(enc_bytes, k) score = ch3.english_score(dec_bytes) dec_text = utils.bytes_string(dec_bytes) guesses.update({dec_text:score}) # Sort guesses by their frequency (lower -> better) sorted_guesses = sorted(guesses, key=guesses.__getitem__,reverse=False); # Eventually print the best scored decryption print (sorted_guesses[0])
def main(in_file='4.txt'): guesses = {} f = open(in_file, 'r') for line in f: # Extract line bytes line = line.rstrip('\r\n') line_bytes = utils.hexstr_bytes(line) # Try to decrypt it decrypt_bytes = ch3.XOR_1B_decrypt(line_bytes) # Get English score guess_score = ch3.english_score(decrypt_bytes) # Add to guesses dictionary guesses.update({line: guess_score}) # Sort guesses by their frequency (lower -> better) sorted_guesses = sorted(guesses, key=guesses.__getitem__, reverse=False) # Print guess line = sorted_guesses[0] line_bytes = utils.hexstr_bytes(line) decrypt_bytes = ch3.XOR_1B_decrypt(line_bytes) decrypt_str = utils.bytes_string(decrypt_bytes) print(decrypt_str)
def profile_decrypt(bytes): return utils.bytes_string(AES.ECB_decrypt(key, bytes))