This program demonstrates the single key exploit by way of ciphertext decryption. The single key exploit has also been know to go by other names including one-time pad and many-time pad.
Single Key Exploit is a python program that decrypts ciphertext. This ciphertext has been encrypted using a single key for each message, leading to the single key exploit. Upon execution, the program will display the plaintext message that will be encrypted. Then it will try to decrypt as much of the encrypted text as possible. The resulting decrypted text will be output to the user.
To execute run the command python3 main.py
display_info()
-
Description:
Outputs plain text to be encrypted
-
Parameters:
None
-
Return:
msgs
List containing strings to be encryptedkey
List of bytes representing the encryption key
make_cipher(text, key)
-
Description:
Creates a list of strings representing ciphertext
-
Parameters:
text
List representing plaintextkey
List of bytes representing the encryption key -
Return:
cipher
List containing ciphertext
encrypt(msg, key)
-
Description:
Encrypts plain text using an encryption key
-
Parameters:
mag
String to be encryptedkey
List representing encryption key -
Return:
bytes
String representing encrypted text in hexadecimal
preprocess(text)
-
Description:
Turns encrypted text into hexadecimal and initializes a list of dashes acting as placeholders
-
Parameters:
text
List containing ciphertext -
Return:
hex
List representing hexadecimal representation of encrypted textplace_holders
List containing dashes -
break_encryption(encrypted_text, decrypted_text)
-
Description:
Attempts to break encryption by utilizing XOR operations
-
Parameters:
encrypted_text
List containing the ciphertextdecrypted_text
List of placeholders to store decrypted text -
Return:
cracked_cipher
List of decrypted text
ascii_space(not_cracked, current_char, columns)
-
Description:
Checks a character to determine if it is a space
-
Parameters:
not_cracked
List containing text that has not been decryptedcurrent_char
Char representing the current character that is being test to determine if it is a spacecolumns
Int representing the index of the current character we are testing -
Return:
Bool
True if a space is found, False otherwise
output_text(text)
-
Description:
Outputs the decrypted text
-
Parameters:
text
List containing decrypted text -
Return:
None
To learn more about this encryption vulnerability refer to this article: One-time Pad