Computer Architectures have predefined ASCII values & Binary forms for all printable characters, which allows us to operate bit-wise logic like XOR and most encryption/decryption algorithms depend on. The Key is XOR-operated on the plain text to produce the encrypted text.
Only Parameters required to encrypt a plain text using this technique:
- Plain text (text which has to be encrypted).
- Key (unique byte of text which is used to encrypt, can be of any length).
- Finding the lengths of “Plain text” and “Key”.
- Breaking the plain text into pieces of length equivalent to the length of Key.
- XOR-ring the pieces of Plain text with the Key in respective order individually.
- Store the above XOR operated outcome in an array.
- When the looping is done, the array contains the whole encrypted text.
Note: Sometimes you may have to pad the plain text in case it is not welly aligned with the general block size. Here is how to do it https://www.geeksforgeeks.org/retaining-the-padded-bytes-of-structural-padding-in-python/
Below is the Code to encrypt Repeated-key XOR;
Plain text: b”Burning ’em, if you ain’t quick and nimble\nI go crazy when I hear a cymbal”
Encrypted as: 0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f
- Difference between Monoalphabetic Cipher and Polyalphabetic Cipher
- XOR Cipher
- How to encrypt passwords in a Spring Boot project using Jasypt
- Encrypt the String according to the given algorithm in Python
- Python - Extract target key from other key values
- Python - Filter key's value from other key
- Python - Extract Key's Value, if Key Present in List and Dictionary
- Caesar Cipher in Cryptography
- Vigenère Cipher
- Rail Fence Cipher - Encryption and Decryption
- Implementation of Affine Cipher
- Columnar Transposition Cipher
- ROT13 cipher
- Implementing Atbash Cipher
- Baconian Cipher
- Keyword Cipher
- Null Cipher
- Latin alphabet cipher
- Hill Cipher
- Playfair Cipher with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.