#includeusingnamespacestd;charz[28][3]={"計(jì)","算","機(jī)","學(xué)","院","網(wǎng)","絡(luò)","工","程","信","息","安","全",",">
密碼學(xué)課程設(shè)計(jì)仿射密碼
資源描述:
《密碼學(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(n2、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)重新輸入:";gotoloop;}}voidsetkey(inta,i
3、ntb){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=strlen(c),kk=i/2,jj;intmm[100],cc[100];ctoi(
4、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]!='