《近代密码学---IT实验01--RSA实现.docx》由会员分享,可在线阅读,更多相关《近代密码学---IT实验01--RSA实现.docx(11页珍藏版)》请在第一文库网上搜索。
1、云南大学数学与统计学实验教学中心实验报告课程名称:近代密码学年级:2010级上机实践成绩:指导教师:陆正福姓名:段飞龙上机实践名称:RSA实现学号:20101910050上机实践日期:上机实践编号:No.1组号:上机实践时间:一、实验目的配置gmp环境,并对其进行测试;通过gmp实现RSA加密、解密。二、实验内容1、配置gmp环境,并对其进行测试;2、编程实现RSA非对称密码算法。三、实验环境UbuntUsVC四、实验结果1.对gmp的测试结果如下:1)对加法运算进行测试的结果:thenis1thesumisOthenisIO1thesumis338350thenisIOO1thesumis3
2、33833500thenisIO(X)Ithesumis3333833350(X)thenisIOOOO1thesumis333338333350000thenis1000001thesumis333333833333500000thenisIO(XX)(M)Ithesumis333333383333335000000thenis100000001thesumis333333338333333350000000thenis1000000001thesumis333333333833333333500000000thesumis45724737(X)731595796547782352)对乘法运
3、算进行测试的结果:1234567823456789theresu1tis289589963907942.2.测试输入的字符串为最大长度(在此例中取最大长度为:10)的字符串时的结果:Inputmax1engthofmessage:10Mainmenu:1 Encryption!21Deciphering!3 Outputthesecretkeyofencryption!41Outputthesecretkeyofdeciphering!0Exit!Inputyouroption:3Thesecretkeyofencryptionis(d,n):4220569777156790391680309
4、7123,87144653527546255677906076663Mainmenu:11 Encryption!2 Deciphering!3 Outputthesecretkeyofencryption!4 Outputthesecretkeyofdeciphering!5 Exit!Inputyouroption:!Thesecretkeyofdeciperingis(e,n):2340244659714722280430171267,87144653527546255677906076663Mainmenu:6 Encryption!7 Deciphering!8 Outputthes
5、ecretkeyofencryption!9 Outputthesecretkeyofdeciphering!0Exit!Inputyouroption:IInputamessage:1234567890Theciphertextisc:26935842609122606219432699240Mainmenu:1 Encryption!2 Deciphering!3 Outputthesecretkeyofencryption!4 Outputthesecretkeyofdeciphering!0Exit!Inputyouroption:!Inputtheciphertext:2693584
6、2609122606219432699240messageis1234567890Mainmenu:1 Encryption!2 Deciphering!31Outputthesecretkeyofencryption!4 Outputthesecretkeyofdeciphering!0Exit!Inputyouroption:1)3.测试输入的字符串小于最大长度(在此例中取最大长度为:50)的字符串时的结果:Inputmax1engthofmessage:50Mainmenu:IEncryption!12JDeciphering!3 Outputthesecretkeyofencrypti
7、on!4 Outputthesecretkeyofdeciphering!10 Exit!Inputyouroption:3Thesecretkeyofencryptionis(d,n):297408524783981975645726343749770408093018495275191278109223502532115191889372202555813676561121807883883014467853719680755897,4671057836622399358821676807435895505685943915013877595026414692974245678000906
8、22957590430787591249549255449025209916078286999Mainmenu:IEncryption!21Deciphering!3Outputthesecretkeyofencryption!41Outputthesecretkeyofdeciphering!0Exit!Inputyouroption:4Thesecretkeyofdeciperingis(e,n):4082543719868963464700015444415964663456798959120815951767277513544697417167841393815073173315761
9、7416416268925939128541181033,467105783662239935882167680743589550568594391501387759502641469297424567800090622957590430787591249549255449025209916078286999Mainmenu:1 Encryption!2 Deciphering!3 Outputthesecretkeyofencryption!4 Outputthesecretkeyofdeciphering!0Exit!Inputyouroption:IInputamessage:1 ami
10、nYunnanuniversity!Theciphertextisc:65892322566841409776195801550912782251822693109336285457691009427996593558805403245086465142278275028052087684329306032745237Mainmenu:1 Encryption!2 Deciphering!3 Outputthesecretkeyofencryption!4 Outputthesecretkeyofdeciphering!0Exit!Inputyouroption:Inputtheciphert
11、ext:65892322566841409776195801550912782251822693109336285457691009427996593558805403245086465142278275028052087684329306032745237messageis1aminYunnanuniversity!Mainmenu:1 Encryption!2 Deciphering!3 Outputthesecretkeyofencryption!4 Outputthesecretkeyofdeciphering!0Exit!Inputyouroption:(注:绿色字体为输入内容(拷贝
12、到WOrd里后,经手动修改)。五、程序源代码:1 .对gmp测试的源代码:1)加法:#inc1ude#inc1udevoidmain()mpz_ts,n;intij=0,m=10;mpz_init(s);/inits,theva1ueis0mpz_init(n);for(i=1;i1I111111ini+)mpz_add_ui(n,n,I);/setnton+1if(j%m=0)gmp-printf(thenis%Zdn,n);gmp_printf(thesumis%Zdn,s);m=m*10;mpz_addmu1(s,n,n);/addn*ntoSj+;1gmp_printf(thesumi
13、s%Zdn”,s);mpz_c1ear(s);2)乘法,inc1udeinc1udechar*BigMu1(char*m,char*n);intmain()char*p=NU11;char*a=12345678;char*b=23456789;p=BigMu1(a,b);printf(theresu1tis%s.n,p):returnO;)char*BigMu1(char*m,char*n)(inti,j;char*pt=NU11;mpz_ts,p,q;mpz_init(s);i=mpz_init_set_str(p,m,10)getnumberfrommj=mpz_init_set_str(
14、q,n,10);/printf(,ijr%d,%dn,ij);gmp-printf(%Zdn%Zdn,p,q);mpz_addmu1(s,p,q);/ca1cu1ateresu1t/gmp-printf(,theresu1tis%Zdn,s);pt=mpz_get_str(pt,1(),s)getstringfroms/printf(,%sn,pt);mpz_c1ear(s);returnpt;2 .RSA源代码indude#inc1ude#inc1ude#inc1ude#inc1udevoidRSA_gmp(mpz_t*d,mpz_t*e,mpz_t*n,unsignedintI)/generatesecretkeyd,e,nchar*str;intsize;unsigned1ong10,seed;mpz_tp,q,fn,fn_r;0=4*+10;mpzjnit(p);npzjnit(q);mpz-init(fn);mpz_init(fn_r);str=(char*)mai1oc(s