logo资料库

希尔密码的实现.docx

第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
资料共5页,全文预览结束
实验一:希尔密码(Hill Cipher)的实现
实验一:希尔密码(Hill Cipher)的实现 姓名 实验目的 班级 学号 通过实验,使学生对古典密码学有充分的认识;学会正确使用编程语言(C、Mathematica、 Maple 等)实现希尔密码,验证课堂中所学的古典密码算法;为学习现代密码算法及其应用奠 定基础。 实验内容及要求 1、学生自己随机选取一个55矩阵,判断是否可以作为密钥 2、利用所选密钥,对给定的5元明文信息进行加解密 3、对加密得到的密文进行解密,验证结果的正确性 实验结果(可续页)(包括实验代码、实验结果) 实验代码 #include #include #include #include using namespace std; const int V=5; int gcd(int a,int b){ if(a%b==0) return b; return gcd(b,a%b); } int det(int s,int a[V][V]){ if(s==2) return a[0][0]*a[1][1]-a[0][1]*a[1][0]; int b,c[V][V],m=0,n=0,sum=0; for(int i=0;i
} return sum; } string operation(int a1,int a2,string s1,int a[V][V]){ string s2; int textm[V],texty[V]={0}; for(int i=0;i
Y[m][n]=k[m+row][n+column]; } pp = 0; } int if((i+j)%2==0) pp=1; else pp=-1; A_i_j=pp*det(V-1,Y); kb[j][i]=A_i_j; } } cout<<"其伴随矩阵为: "<
cout<>s1; s2=operation(a2,a1,s1,k); cout<<"密文为: "<>s3; s4=operation(a1,a2,s3,kn); cout<<"明文为: "<
由图可知,实验结果正确。
分享到:
收藏