table of Contents
Replacement password/transposition password
Permutation Cipher is also called Transposi-tion Cipher, which rearranges the plaintext according to certain rules in order to break the structural characteristics of the plaintext. The feature of the replacement password is to keep all the characters in the plaintext unchanged , but to use the replacement to disrupt the position and order of the plaintext characters .
There are two most common replacement passwords:
- Column replacement password (key procedures in accordance with the plaintext P by column transposition and column by column readout sequence to obtain the ciphertext C);
- Periodic replacement cipher (group the plaintext P according to a fixed length m , and then rearrange the position of each group according to a certain permutation of 1, 2..., m to obtain the ciphertext C).
- Write the plaintext P in lines with the set fixed grouping width m , that is, there are m characters in each line . If the length of the plaintext is not an integral multiple of m, the insufficient part shall be filled in the method agreed by both parties. If the two parties agree to replace the characters in the vacant with spaces, you may wish to set the final character matrix
character matrix is obtained by swapping the position order of a certain permutation column of 1, 2..., m
- The matrix
by columns 1, 2, ..., n in order to obtain sequentially read ciphertext sequence C.
For the 2022 Beijing Winter Olympics, the English name is " The XXIV Olympic Winter Games ". Assuming m is 5, there is no space when sending.
The content in column 1 is changed to 4, the content in column 4 is changed to 3, the content in column 3 is changed to 1, 2, and 5 are interchanged.
Clear text: TheXXIVOlympicWinterGames
- Write the ciphertext C in columns with the same packet width m as the encryption process to obtain a character matrix
- The character matrix is obtained by exchanging the position order of the columns according to
the inverse permutation of the permutation used in the encryption process .
- Read the matrix in the
order of 1, 2, ..., m rows to get the plaintext P.
The periodic replacement cipher is to group the plaintext string P according to a fixed length m, and then rearrange the substrings in each group according to a certain permutation position of 1, 2..., m to obtain the ciphertext C. The key
contains the packet length information. When decrypting, the ciphertext C is also grouped by length m, and
each group of substrings are rearranged according to the inverse permutation of the mouth to obtain the plaintext P.
Encrypt "State Key Laboratory of Networking and Switching" without spaces, and m is 7. Encryption key
The plaintext is divided into 7 groups:
It is easy to know the decryption key from the encryption key:
=(13265), the decryption is easy to implement, please try it yourself.
The so-called substitution is a method of replacing a letter in the plain text with other letters, numbers or symbols .
Substitution password refers to the establishment of a substitution table . When encrypting, the plaintext that needs to be encrypted is sequentially checked through the table and replaced with corresponding characters . After the plaintext characters are replaced one by one, a character string with no meaning is generated, that is, ciphertext. Such a substitution table is usually called a key.
Single table substitution password
For the same letter that appears in the plaintext message, the same fixed letter is used to replace it when encrypting , no matter where it appears. Such as Caesar, affine and so on.
All the letters in the plaintext are shifted backward (or forward) in the alphabet by a fixed number ( key n ) and then replaced with ciphertext.
The encryption and decryption methods are as follows:
When the key n is 3:
Plaintext alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ.
Ciphertext alphabet: DEFGHIJKLMNOPQRSTUVWXYZABC.
The encryption process is as follows:
Plain text: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG;
Ciphertext: WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ.
The reverse process of decryption is enough. You can write a small program yourself, enter the plaintext/ciphertext, key, and get the result. Of course, there is also an online toolbox.
Find the online encryption and decryption toolbox, the URL is in the reference section
Multi-table substitution password
The same letter that appears in the plaintext message is not completely replaced by the same fixed letter during encryption , but is replaced with a different letter according to the order of its appearance. Multi-table substitution cipher is a cryptographic system that uses multiple single tables to replace passwords. It uses multiple single tables to replace passwords in turn in the process of encrypting plaintext. Such as Virginia, Playfair, Runner, etc.
It is an encryption algorithm that uses a series of Caesar ciphers to form a cipher alphabet, which is a simple form of multi-table ciphers.
Suppose the plaintext is:
Select a certain keyword and repeat it to get the key. For example, when the key word is LEMON, the key is:
For the first letter A of the plaintext , it corresponds to the first letter L of the key , so use the L row alphabet in the table to encrypt, and get the first letter L of the ciphertext . Similarly, the second letter T of the plaintext is encrypted with the corresponding row E in the table to obtain the second letter X of the ciphertext . And so on, namely:
Plain text: ATTACKATDAWN
The decryption process is reversed