希爾密碼
Now, Hill Cipher is a very basic cryptographic technique which is used to convert a string into ciphertext. This technique was invented by an American Mathematician "Lester Sanders Hill". This is a polygraphic substitution cipher because the substitution or encryption is performed on the block on letters. It works on multiple letters at the same time. It was the first polygraphic cipher which was operable on more than 3 symbols.
現在, Hill Cipher是一種非常基本的加密技術,用于將字符串轉換為密文。 這項技術是由美國數學家“萊斯特·桑德斯·希爾(Lester Sanders Hill)”發明的。 這是一個多圖形替換密碼,因為替換或加密是在字母上的塊上執行的。 它可以同時處理多個字母。 這是第一個可用于3個以上符號的多重密碼。
Implementation Technique
實施技術
加密 (Encryption )
In Hill Cipher, each letter is represented by a number modulo 26. So according to this, A = 0, B = 1, C = 2, ..., Z = 25. A string will be given to you and you have to make a column matrix using the letter-numberer relationship shown above. We'll be given a key matrix as well. We must ensure that | Key | should not be zero otherwise we can not apply hill cipher technique. This key matrix will be used in decryption as well. We need to multiply these two matrices. The formula for the ciphertext using Hill Cipher is:
在Hill Cipher中 ,每個字母都由一個以26為模的數字表示。因此, A = 0,B = 1,C = 2,...,Z = 25 。 將為您提供一個字符串,您必須使用上面顯示的字母-數字關系創建一個列矩陣。 我們還將獲得一個密鑰矩陣。 我們必須確保 關鍵 不應為零,否則我們將無法應用希爾密碼技術 。 該密鑰矩陣也將用于解密。 我們需要將這兩個矩陣相乘。 使用希爾密碼的密文公式為:
Here, n is the order of matrix or we can say the n is the number of letters we are taking at once to encrypt. Now, you'll get column matrix of order n x 1 which will have numbers from 0 to 25. You just have to replace the number with the letters from the relationship shown above and your ciphertext is ready.
在這里, n是矩陣的階數,或者我們可以說n是我們一次要加密的字母數。 現在,您將獲得順序為nx 1的列矩陣,該列矩陣的數字從0到25。您只需要用上面顯示的關系中的字母替換數字,即可準備好密文。
解密 (Decryption)
The letter-numberer relationship will remain the same in the decryption part. We'll use the inverse of the key matrix in decryption. Order of the matrix will remain the same. We need to multiply the inverse of the key matrix with the cipher text matrix we've got from the encryption technique. The formula is given below:
字母-數字關系在解密部分將保持不變。 我們將在解密中使用密鑰矩陣的逆函數。 矩陣的順序將保持不變。 我們需要將密鑰矩陣的逆乘以從加密技術獲得的密文矩陣。 公式如下:
Example:
例:
Let us take plain text: DOG and the key matrix is:
讓我們采用純文本:DOG和密鑰矩陣為:
D = 3, O = 14 , G = 6 so our column matrix is:
D = 3,O = 14,G = 6,所以我們的列矩陣為:
Now we have to apply the multiplication as shown in the encryption formula. After multiplying and applying modulo 26 we got this cipher text matrix:
現在,我們必須應用加密公式中所示的乘法。 在乘并應用模26之后,我們得到了這個密文矩陣:
Now, 22 = W, 11 = L, 24 = Y
現在,22 = W,11 = L,24 = Y
So cipher text of DOG is WLY
所以DOG的密文是WLY
Now we'll do decryption and we'll use the generated ciphertext to convert it to plain text. First of all, we need to find the inverse of the key matrix. So the inverse of our key matrix is:
現在我們將進行解密,并將使用生成的密文將其轉換為純文本。 首先,我們需要找到密鑰矩陣的逆矩陣。 因此,我們的密鑰矩陣的逆是:
Now after multiplying the inverse matrix with the ciphertext matrix that we've generated in the encryption, we can get out plain text matrix again.
現在,將逆矩陣與我們在加密中生成的密文矩陣相乘后,我們可以再次得到純文本矩陣。
So after multiplying and taking modulo 26, the decrypted matrix is:
因此,在乘以26后,解密后的矩陣為:
3 = D, 14 = 0 and 6 = G, So this is equal to the plain text it means our encryption and decryption both are right. Now, the Hill Cipher technique is over.
3 = D,14 = 0和6 = G,所以這等于純文本,這意味著我們的加密和解密都是正確的。 現在, 希爾密碼技術已經結束。
翻譯自: https://www.includehelp.com/cyber-security/hill-cipher.aspx
希爾密碼