#includeusingnamespacestd;charz[28][3]={"計(jì)","算","機(jī)","學(xué)","院","網(wǎng)","絡(luò)","工","程","信","息","安","全",",">
密碼學(xué)課程設(shè)計(jì)仿射密碼

密碼學(xué)課程設(shè)計(jì)仿射密碼

ID:12679777

大?。?9.50 KB

頁(yè)數(shù):5頁(yè)

時(shí)間:2018-07-18

密碼學(xué)課程設(shè)計(jì)仿射密碼_第1頁(yè)
密碼學(xué)課程設(shè)計(jì)仿射密碼_第2頁(yè)
密碼學(xué)課程設(shè)計(jì)仿射密碼_第3頁(yè)
密碼學(xué)課程設(shè)計(jì)仿射密碼_第4頁(yè)
密碼學(xué)課程設(shè)計(jì)仿射密碼_第5頁(yè)
資源描述:

《密碼學(xué)課程設(shè)計(jì)仿射密碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。

1、#include#includeusingnamespacestd;charz[28][3]={"計(jì)","算","機(jī)","學(xué)","院","網(wǎng)","絡(luò)","工","程","信","息","安","全",",","我","們","熱","愛","中","華","人","民","共","和","國(guó)","。","大","家"};intkey[12]={1,3,5,9,11,13,15,17,19,23,25,27};intgcd(intn,intm){intr,temp;if(n

2、;m=temp;}while(m!=0){r=n%m;n=m;m=r;}returnn;}intniyuan(inta){intb;for(b=1;b<28;b++)if((a*b)%28==1){returnb;}return-1;}classfangshe{public:intk[2],kx;charc[200],m[200];voidsetkey(){cout<<"請(qǐng)輸入仿射密碼密鑰的兩部分:";loop:cin>>k[0]>>k[1];kx=niyuan(k[0]);if(kx==-1){cout<<"此密鑰違法!請(qǐng)重新輸入:

3、";gotoloop;}}voidsetkey(inta,intb){k[0]=a;k[1]=b;kx=niyuan(k[0]);}int*getkey(){returnk;}voidencryption(charm[],charc[]){inti=strlen(m),kk=i/2,j;intmm[100],cc[100];ctoi(m,mm);for(j=1;j<=kk;j++)cc[j]=(k[0]*mm[j]+k[1])%28;itoc(cc,c,kk);}voiddecryption(charc[],charm[]){inti

4、=strlen(c),kk=i/2,jj;intmm[100],cc[100];ctoi(c,cc);for(jj=1;jj<=kk;jj++){intzan=cc[jj]-k[1];if(zan<0)zan=zan+28;mm[jj]=(kx*zan)%28;}itoc(mm,m,kk);}voidctoi(charm[],intmm[]){intmi=0,ii=1,j;for(mi=0,ii=1;m[mi]!='