Transposition Cipher Encryption and Decryption
Plaintext
Ciphertext
What is a Transposition Cipher?
A Transposition Cipher is a classic encryption method that works by rearranging the positions of characters in the plaintext, rather than changing the characters themselves. Unlike substitution ciphers, which replace characters, a transposition cipher keeps the letters of the plaintext the same but changes their order. One common variation of the transposition cipher is the Columnar Transposition Cipher, which typically encrypts the message by writing the plaintext in columns and then rearranging the columns according to a predetermined key.
How Does the Transposition Cipher Encrypt?
The encryption process for a Transposition Cipher is as follows:
- Prepare the Plaintext: First, remove spaces, punctuation, or any other non-alphabetical characters (optional based on your preferences to keep or ignore unknown characters).
- Determine the Key: The key is a string (such as an English word) used to determine the order in which the letters should be rearranged. By converting each letter of the key to its position in the alphabet, you create a numerical sequence that dictates the column order.
- Fill the Plaintext into a Matrix: The plaintext is divided into columns according to the length of the key, filling the matrix column by column.
- Rearrange the Columns: Using the key, rearrange the columns of the matrix based on the alphabetical order of the key's letters.
- Generate the Ciphertext: After rearranging the columns, read the matrix vertically (column by column) to form the ciphertext.
Example
Suppose the plaintext is "HELLO WORLD" and the key is "KEYWORD".
1. Prepare the Plaintext and Fill the Matrix:
The key "KEYWORD" means the plaintext will be divided into 7 columns. The key letter order is: [3, 2, 7, 6, 4, 5, 1]. The matrix is filled as follows:
K | E | Y | W | O | R | D |
---|---|---|---|---|---|---|
3 | 2 | 7 | 6 | 4 | 5 | 1 |
H | E | L | L | O | W | O |
R | L | D | - | - | - | - |
2. Rearrange Columns According to the Key:
D | E | K | O | R | W | Y |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
O | E | H | O | W | L | L |
- | L | R | - | - | - | D |
3. Output the Ciphertext:
Reading vertically (by columns) gives us the final ciphertext: O ELHRO W L LD.
How Does the Transposition Cipher Decrypt?
The decryption process of a Transposition Cipher is simply the reverse of the encryption process. We need to restore the original positions of the characters based on the key's alphabetical order, and rearrange the ciphertext into the original plaintext.
- Determine the Key: As with encryption, start by determining the key and converting it to its alphabetical order.
- Rebuild the Matrix: Divide the ciphertext into columns, maintaining the same number of columns as used during encryption. Based on the ciphertext length and the number of columns, calculate how many characters should be placed in each column.
- Reverse the Column Arrangement: Using the key's alphabetical order, reverse the column arrangement to match the encryption process.
- Retrieve the Plaintext: Finally, read the matrix horizontally (row by row) to obtain the original plaintext.
Example
Suppose we have the ciphertext "O ELHRO W L LD" and the key is "KEYWORD". Let's decrypt it.
1. Determine the Key and Construct the Alphabetical Order:
The key "KEYWORD" corresponds to the letter order: [3, 2, 7, 6, 4, 5, 1].
2. Rebuild the Matrix:
We now distribute the ciphertext into the matrix using the number of columns from the key:
D | E | K | O | R | W | Y |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
O | E | H | O | W | L | L |
- | L | R | - | - | - | D |
3. Reverse the Column Order:
Rearranging the columns according to the order [3, 2, 7, 6, 4, 5, 1], we get:
K | E | Y | W | O | R | D |
---|---|---|---|---|---|---|
3 | 2 | 7 | 6 | 4 | 5 | 1 |
H | E | L | L | O | W | O |
R | L | D | - | - | - | - |
4. Retrieve the Plaintext:
Finally, reading horizontally (row by row), we get the original plaintext: HELLOWORLD.