現(xiàn)在網(wǎng)上有的大部分都是理論_第1頁
現(xiàn)在網(wǎng)上有的大部分都是理論_第2頁
現(xiàn)在網(wǎng)上有的大部分都是理論_第3頁
現(xiàn)在網(wǎng)上有的大部分都是理論_第4頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、現(xiàn)在網(wǎng)上有的大部分都是理論,這里將給出一個簡單加密模塊的全部源程序(源代碼)至于 RSA 的理論網(wǎng)上一大把, 它是基于公鑰加密體制的一種算法。 這個實(shí)例主要是用來將某一重要文件綁定到一個 IP 地址上。把它拷貝下來,存為 CODE.C ,然后執(zhí)行GCC O CODE CODE.C然后用 ./ CODE E IP ADDRESS FILENAME對文件進(jìn)行加密?;蛴?/CODE D IP ADDRESS進(jìn)行解密整個過程中產(chǎn)生了兩個中間文件,至于什么文件,你去試一試就知道啦!#include "stdio.h"#include "string.h"int e

2、,d=1,n;main(int argc,char *argv)int ip,fai,p=43,q=59,ch1,i=0,j=0,edch,dech=0;char *num,*cha,ch,*file="index.html"FILE *fp,*fp2;if (argc<2)printf("paramater error!");exit(0);if (argc>3)file=argv3;/printf("%s,",file)e=iptoint(argv2);/printf("%s,%s",argv1,a

3、rgv2);switch (*argv1)case 'e':/printf("e=%d",e);if (fp2=fopen("encode.htm","w+")=NULL)printf("can't open file");exit(0);"code.c" 199L, 3571Cn=p*q;fai=(p-1)*(q-1);if(fp=fopen(file,"r")=NULL)printf("can't open giving file

4、");exit(0);elsewhile(ch1=fgetc(fp)!=EOF)edch=fmod(ch1,e,n);if (edch>0 && edch<10) fprintf(fp2,"%s","000"); fprintf(fp2,"%d",edch);else if (edch<100 && edch>10) fprintf(fp2,"%s","00"); fprintf(fp2,"%d",edch);

5、else if (edch<1000 && edch>100) fprintf(fp2,"%s","0"); fprintf(fp2,"%d",edch);else if (edch<10000 && edch>1000) fprintf(fp2,"%d",edch);else fputc('n',fp2);close(fp);close(fp2);break;case 'd':/ printf("d=%d"

6、,e);if (fp2=fopen("decode.html","w+")=NULL)if (fp2=fopen("decode.html","w+")=NULL)printf("can't open file");exit(0);n=p*q;fai=(p-1)*(q-1);while(d*e)%fai)!=1)d+;if(fp=fopen("encode.htm","r")=NULL)printf("can't open fil

7、e");exit(0);else i=0;/ printf("e=%d,d=%d,n=%d,",e,d,n);while(ch=fgetc(fp)!=EOF)if (i=4)/dech=(int)num0)*1000+(int)num1)*100+(int)num2)*10+(int)num3;/printf("yuan=%d,",dech);dech=fmod(dech,d,n);/printf("new=%d,",dech);fprintf(fp2,"%c",dech);i=0;dech=0;/swi

8、tch (ch)case '9':dech=dech*10+9;break;case '1':dech=dech*10+1;break;case '2':dech=dech*10+2;break;case '3':dech=dech*10+3;break;case '4':dech=dech*10+4;break;case '3':dech=dech*10+3;break;case '4':dech=dech*10+4;break;case '5':dech=dech

9、*10+5;break;case '6':dech=dech*10+6;break;case '7':dech=dech*10+7;break;case '8':dech=dech*10+8;break;default:dech=dech*10;/ printf("dech=%d,",dech);numi=ch;i+;dech=fmod(dech,d,n);fprintf(fp2,"%c",dech);close(fp);close(fp2);break;default:printf("Usage

10、:code option.Ip Address.n"); printf("List information about the optionn"); printf("e bind ip address to index.htmln");printf("d decode from the encodeing file to index2.html");int iptoint(ip)char *ip;int i,ei=0,len;int prime=0;len=strlen(ip);len=strlen(ip);for(i=0;i<len;i+)if(ipi>'0' && ipi<'9')ei=ei+i*(int)ipi);ei=ei/1000+(ei/100)%10+(ei/10)%10+ei%10;/printf("%d",ei);/len=ei/2;/while(prime=0)/indent: Standard input:2: Error:Unexpected end of filewhile (ei % 2)= 0) | (ei % 3) = 0) ei=ei+1;/* prime=1;for

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論