This Python script implements a simple XOR-based encryption and decryption algorithm for text data. It provides functionalities for both encrypting plaintext messages and decrypting previously encrypted text using a user-defined key.
Learn More: https://youtu.be/QqiFrOG-IvU?si=JqLvjH_X4Mcrz1au
Encrypt and decrypt text messages using XOR operation. Generate random keys for encryption or use user-provided keys. Display detailed encryption/decryption steps for educational purposes.
Clone this repository or download the script. Open a terminal window and navigate to the script's directory. Run the script using python xor_cipher.py. Follow the prompts to select encryption or decryption, provide the plaintext/ciphertext, and optionally enter a key.
Select an option:
- Encrypt
- Decrypt Enter 1 or 2: 1
Enter plaintext: This is a secret message! Enter key (press Enter for random key): secret_key
Key: secret_key
Encryption Steps:
Character | ASCII | Binary Plain | Binary Key | XOR Result | Hex |
---|---|---|---|---|---|
T | 84 | 01010100 | 11100100 | 10110000 | d0 |
h | 104 | 01101000 | 11100100 | 00001100 | 0c |
i | 105 | 01101001 | 11100100 | 00001101 | 0d |
s | 115 | 01110011 | 11100100 | 00010111 | 1f |
... (remaining characters) ... |
Encrypted Text: d00c0d1f... (truncated)
Select an option:
- Encrypt
- Decrypt Enter 1 or 2: 2
Enter the decryption key: secret_key Enter the encrypted text: d00c0d1f... (truncated)
Decryption Key: secret_key
Decryption Steps:
Hex Value | Binary Plain | Binary Key | XOR Result | Character | ASCII |
---|---|---|---|---|---|
d0 | 01010100 | 11100100 | 10110000 | T | 84 |
0c | 00001100 | 11100100 | 11100000 | h | 104 |
0d | 00001101 | 11100100 | 11100001 | i | 105 |
1f | 00010111 | 11100100 | 11110011 | s | 115 |
... (remaining characters) ... |
Decrypted Text: This is a secret message!