| RSA加密实例分析 |
|
| 作者:未知 文章来源:网络收集 点击数: 更新时间:2006-3-29 15:22:22
|
现在网上有的大部分都是理论,这里将给出一个简单加密模块的全部源程序(源代码)
至于RSA的理论网上一大把,它是基于公钥加密体制的一种算法。这个实例主要是用来将某一重要文件绑定到一个IP地址上。 把它拷贝下来,存为CODE.C,然后执行
GCC –O CODE CODE.C
然后用./ CODE E [IP ADDRESS] [FILENAME]对文件进行加密。或用
./CODE D [IP ADDRESS] 进行解密整个过程中产生了两个中间文件,至于什么文件,你去试一试就知道啦!
#include "stdio.h"
#include "string.h"
int e,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=argv[3];
}
//printf("%s,",file)
e=iptoint(argv[2]);
//printf("%s,%s",argv[1],argv[2]);
switch (*argv[1])
{
case 'e':
//printf("e=%d",e);
if ((fp2=fopen("encode.htm","w+"))==NULL)
{
printf("can't open file");
exit(0);
}
"code.c" 199L, 3571C
}
n=p*q;fai=(p-1)*(q-1);
if((fp=fopen(file,"r"))==NULL)
{
printf("can't open giving file");
exit(0);
}
else
{
while((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);
}
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",e);
if ((fp2=fopen("decode.html","[1] [2] [3] 下一页
|
|
[ 收藏此页到: 天天|和讯|博采|ViVi|狐摘|我摘|天极 ] 文章录入:kinda 责任编辑:kinda |
|
上一篇文章: SERVER 2000通讯管道后复用劫持 下一篇文章: 开发工具大比拼visual c++ vs delphi---(三) |
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |