Hill Cipher加密

时间:2016-01-15 03:07:46

标签: c++ encryption cryptography

< p>所以我试图使用山密码用给定的密钥加密我的3x3矩阵。它适用于第一个输出n的值,它应该是,但是在那个值之后,我得到大的值,它永远不会采用它们的mod。我添加了cout语句来帮助我调试并查看出了什么问题,但我仍然无法修复它。第二个mod 26也在那里,因为当我没有它时,我得到了负13而不是正13.这是一个家庭作业程序,我们的钥匙是作为数字给我们的,以防任何重要。 < / p为H. < p>< a href =" https://i.stack.imgur.com/PDNkO.png" rel =" nofollow noreferrer">< img src =" https://i.stack.imgur.com/PDNkO.png" alt ="在此处输入图像说明">< / a>< / p> < pre>< code> #include< iostream> #include< string> #include< stdio.h> #include< ctype.h> 使用std :: endl; 使用std :: string; void inverse_matrix(); 字符串加密(字符串x); int main() { std :: string one =" paymoremoney&#34 ;; // inverse_matrix(); 加密(之一); 系统("暂停&#34); 返回0; } 字符串加密(字符串x) { int encrypted [4] [4]; int key [3] [3]; key [0] [0] = 4; key [0] [1] = 9; key [0] [2] = 15; key [1] [0] = 15; key [1] [1] = 17; key [1] [2] = 6; key [2] [0] = 24; key [2] [1] = 0; key [2] [2] = 17; int test = 0; char str [] ="&#34 ;; char c; int length =(int)x.length(); for(int i = 0; i< length; i ++) {     x [i] = tolower(x [i]); } / * 而(str [test]) {     c = str [test];     的putchar(tolower的(C));     试验++; } * / int encrypt [4] [4]; encrypt [0] [0] = x [0]; encrypt [0] [1] = x [1]; encrypt [0] [2] = x [2]; encrypt [1] [0] = x [3]; encrypt [1] [1] = x [4]; encrypt [1] [2] = x [5]; encrypt [2] [0] = x [6]; encrypt [2] [1] = x [7]; encrypt [2] [2] = x [8]; encrypt [3] [0] = x [9]; encrypt [3] [1] = x [10]; encrypt [3] [2] = x [11]; encrypted [0] [0] =(key [0] [0] * encrypt [0] [0])+(key [1] [0] * encrypt [0] [1])+(key [3] [ 0] *加密[0] [2])%26; 加密[0] [0]%= 26; encrypted [0] [1] =(key [0] [1] * encrypt [0] [0])+(key [1] [1] * encrypt [0] [1])+(key [2] [ 1] * encrypt [0] [2])%26; 加密[0] [0]%= 26; encrypted [0] [2] =(key [0] [2] * encrypt [0] [0])+(key [1] [2] * encrypt [0] [1])+(key [2] [ 2] * encrypt [0] [2])%26; 加密[0] [0]%= 26; std :: cout<<加密[0] [0]; std :: cout<< ENDL; std :: cout<<加密[0] [1]; std :: cout<< ENDL; std :: cout<<加密[0] [2]; std :: cout<< ENDL; < /代码>< /预> &LT p为H.;}< / p为H.

1 个答案:

答案 0 :(得分:0)

由于这是家庭作业,我指出了正确的方向,而不是直接回答。您已分配给encrypted[0][1]。分配给你后,你对该值做了什么?

相关问题