首页 > 编程知识 正文

希尔密码在线工具,凯撒密码c++代码

时间:2023-05-05 21:53:52 阅读:162932 作者:4019

弗吉尼亚密码:

加密:

voidenVirginia(char*plaintext,int* k ) int length=strlen (plaintext ); int m,n; for(intI=0; i length; I ) {m=plaintext[i] - 'a '; n=m k[i]; n 26? n=n : n=n % 26; printf('%c ',' a' n ); }printf((n ); }解密:

voiddeVirginia(char*ciphertext,int* k ) (intlength=strlen ) ciphertext ); int m,n; for(intI=0; i length; I ) {m=ciphertext[i] - 'a '; n=m - k[i]; n=0? n=n : n=n 26; printf('%c ',' a' n ); }printf((n ); (希尔密码:

加密:

voidenhillcipher (char * plaintext,int k[][10] ) intlength=strlen ) plaintext; int x[100]; int y[4][4]; for(intI=0; i=length; I ) {x[i 1]=plaintext[i] - 'a '; }for(intI=1; i=3; I ) for(intj=1; j=3; j ) {y[I][j]=x[(I-1 ) * 3 j]; }int matrix[100]={ 0 }; int count=1; int flag=1; while(count=length ) for ) intI=0; i 3; I ) for(intj=0; j3; j ({ matrix [ count ]=k [ I ] [ j ] * y [ flag ] [ J1 ] matrix [ count ]; }matrix[count]=matrix[count]&; 出局; (}标志; }for(intj=1; j length; j () printf('%c ',' a' matrix[j] ); }printf((n ); }解密:

voiddehillcipher (char * ciphertext,int k[][10] ) intlength=strlen ) cipher text ); int x[100]; int y[4][4]; for(intI=0; i=length; I ) x(I1 )=ciphertext )-'a ); }for(intI=1; i=3; I ) for(intj=1; j=3; j ) {y[I][j]=x[(I-1 ) * 3 j]; }int matrix[100]={ 0 }; int count=1; int flag=1; while(count=length ) for ) intI=0; i 3; I ) for(intj=0; j 3; j ({ matrix [ count ]=k [ I ] [ j ] * y [ flag ] [ J1 ] matrix [ count ]; }matrix[count]=matrix[count]&; 出局; (}标志; }for(intj=1; j length; j () printf('%c ',' a' matrix[j] ); }printf((n ); )希尔密码的加密算法其实是一样的,但是密钥不同,解密的密钥是加密密钥的乘法逆元。 另外,钥匙的长度也可以自己调整。 密钥选择的矩阵的行数和列数最好等于明文的长度。 上面的算法使用了3*3矩阵。 我用来加密8长的明文。 在明文后添加任意字符,最后输出8个即可。

由于时间有限,以后生成8*8、或者更高维的n次方阵的算法,以后会慢慢学习并上传。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。