HW2 Hill cipher
TA 吳元魁
Cryptography
Hill cipher
Flow chart
encode stage:
decode stage:
Crack password:
[encode matrix] * [Plain] = [Cipher]
[encode matrix] = [Cipher] * [Plain]^-1
Plain text
encode matrix
Cipher text
mod
Cipher text
decode matrix
Plain text
mod
How to do
=> WPK_FJEIIXZ.OQFPM_
util.py (在ceiba的檔案裡)
破解Hill Cipher
(mod S)
(mod S)
作業規定
key, text轉換成矩陣
無論是key還是plain text, cipher text,請用numpy.reshape來轉換成矩陣�numpy.reshape(a, (3, 4))是將 a 這個numpy array轉換成 3x4 的矩陣�ex: �key: 11 12 13 14 15 16 17 18 19�plain text: ABCDEFGHIJKLMNO�key會變成[[11, 12, 13], [14, 15, 16], [17, 18, 19]]�plain text會變成[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]
Reference
Appendix
modular inverse of a matrix
det(A) = 200 ; (det(A))^-1 = 1/200 = 20 (mod 31)
20
not 1/200
hint: when you call np.linalg.inv(), you will get
but what you need is
In this case, not 1/200, replace it by det(A)^-1 mod(31)
(mod 31)
modular inverse of the matrix determinant