资源描述:
《董凤鸿-41040317-信计1002-密码学1.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、密码学实验报告序号班级学号日期时间地点1信计1002董凤鸿410403178月3日6:00-9:00实验楼102指导教师:实验名称:密码学数学基础实验实验任务:实验一密码学数学基础实验(验证性实验,1学时)1、求最大公约数A、实验容:实现欧几里德算法;B、测试数据:gcd(1736,2848)=8。2、求元素逆元及求解同余方程A、实验容:实现扩展的欧几里德算法;B、测试数据:678-1mod1937=20。C、实验方程:。实验二古典密码学实验(验证性实验,1学时)1、Vigenere密码和Playfair密码实验容:用下列密码,对信息“thehous
2、eisbeingsoldtonight”进行加密。忽略单词间的间距。并对信息解密得到原明文;A、密钥为“dollars”的Vigenere密码B、Playfair密码,其密钥如下LGDBAQMHECURNI/JFXVSOKZYWTP实验三现代对称密码学实验(验证性实验,2学时)1、DESA、实验容:熟悉DES算法,并实现DES;B、测试数据:任意,并验证加/解密结果。程序清单:实验一1、functionfcd=f2(a,b)r1=a;r2=b;while(r2>0)q=fix(r1/r2);r=r1-q*r2;r1=r2;r2=r;endfcd=r1
3、;end2、functiongb=f1(n,b)r1=n;r2=b;t1=0;t2=1;while(r2>0)q=fix(r1/r2);r=r1-q*r2;r1=r2;r2=r;t=t1-q*t2;t1=t2;t2=t;endif(r1==1)gb=t1;endfunctionhj=tongyu(b,d,n)r1=n;r2=b;t1=0;t2=1;while(r2>0)q=fix(r1/r2);r=r1-q*r2;r1=r2;r2=r;t=t1-q*t2;t1=t2;t2=t;endif(r1==1)fans=t1;elsefprintf('²»ÊÇ
4、»¥ËØ');returnendhj=mod(fans*d,n);end实验二古典密码学实验1、Vigenere密码和Playfair密码a.Vigenere密码求密文:functiony=shift(x,b);%Thisfunctionperformstheshiftencryptionfunction%y=x+bmod26%Weassumethatxisatextstringandbisanumber%Theresultiskeptintextrepresentationxnum=text2int(x);ynum=mod(xnum+b,26);y
5、=int2text(ynum);functiony=vigenere1(txt,key);%ThisfunctionperformstheVigenerecipherontheplaintextin%thevariabletxt,usingkey(weassumethekeyisinnumerical%representation).if((key<'a')
6、(key>'z')),error('Textcharacteroutofrangea-z');end;key2=key-'a';%key2=text2int(key);xln=length(tx
7、t);kln=length(key2);forj=1:xln,jmod=mod(j,kln);ifjmod==0,jmod=kln;end;%mapanindexof0intoanindexofklny(j)=shift(txt(j),key2(jmod));end;求明文:functiony=shift(x,b);%Thisfunctionperformstheshiftencryptionfunction%y=x+bmod26%Weassumethatxisatextstringandbisanumber%Theresultiskeptintex
8、trepresentationxnum=text2int(x);ynum=mod(xnum+b,26);y=int2text(ynum);functiony=vigenere2(txt,key);%ThisfunctionperformstheVigenerecipherontheplaintextin%thevariabletxt,usingkey(weassumethekeyisinnumerical%representation).if((key<'a')
9、(key>'z')),error('Textcharacteroutofrangea-z
10、');end;key2=-(key-'a');%key2=text2int(key);xln=length(