首页 > 编程知识 正文

数据完整性保护密码算法,凯撒密码算法流程代码

时间:2023-05-03 16:35:54 阅读:186230 作者:339

sqdy密码sqdy密码是简单移位。 注意负数取模就好了。

# include bits/stdc.husingnamespacestd; const int mod=26; int k; 字符串str; //解密函数stringdecryptionfunction (string ecode ) { string dCode=' '; for(intI=0; ieCode.length (; I ) { int n=eCode[i] - 'a '; intm=(n-kmod ) %mod; dode=(a ) m; } return dCode; }请输入}int main () { cout明文和键: ' endl; wile(cinsTrk ) { string eCode=' '; for(intI=0; istr.length (; I ) { int n=str[i]-'a '; intm=(nk ) %mod; ecode=(a ) m; } cout '加密的密文:“eCodeendl; cout '调用解密函数。' decryptionfunction(ecode ) endl; } return 0; (/*测试用例security 3*/) /

仿射密码对于仿射密码,加密过程与上述sqdy密码没有太大区别。 重要的是解密那个块。

首先,我得到了密文号码c。 怎么求m?

m=(c-5 )/3 ) mod26 ) )

但是,这里有时会想,如果c-5的结果小于3,m的值会不会为0。 因此,为了使m=(c-5 ) *x(mod26 )这个x成为3的逆矩阵,解决如下。 求出逆元函数就可以得到x

# include bits/stdc.husingnamespacestd; const int mod=26; int k; 字符串str; typedef long ll; //gcdvoidexgcd(lla,ll b,ll d,ll x,ll y ) { if (! b () d=a; x=1; y=0; }else{EXgcd(b,a%b,d,y,x ); y-=x*(a/b ); }//逆元llinv(lla,ll p ) ) lld,x,y; exgcd(a,p,d,x,y ); return d==1? (x p ) %p : -1; //解密函数stringdecryptionfunction (string ecode ) { string dCode=' '; //求逆元intrev=inv(3,mod )的for(intI=0; ieCode.length (; I ) { int c=eCode[i] - 'a '; c=(c-5mod ) %mod; intm=(c*rev ) %mod; dode=(a ) m; } return dCode; }请输入}int main () { cout明文。 (endl; wile(cinstr ) { string eCode=' '; for(intI=0; istr.length (; I ) { int n=str[i]-'a '; intm=(3*n5 ) %mod; ecode=(a ) m; } cout '加密的密文:“eCodeendl; cout '调用解密函数。 ' decryptionfunction(ecode ) endl; } return 0; (/*测试用例securityhrlnedkz*/) /学习就像逆水行舟,不进则退

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