📄 encode.c
字号:
#include "encode.h"
int main()
{
FILE *pf1,*pf2,*pf3;
unsigned long n,e;
unsigned char PText[2],CText[3];
pf1=fopen("PK.bin","r"); //取公钥
fscanf(pf1,"%X-%X",&n,&e);
fclose(pf1);
pf2=fopen("plaint.txt","rb");
pf3=fopen("Cipher.txt","wb");
PText[0]=0;
PText[1]=0;
while(fread(PText,1,1,pf2)!=0)
{
encode(PText,CText,n,e); //加密一段明文
PText[0]=0;
PText[1]=0;
fwrite(CText,1,2,pf3);
}
fclose(pf2);
fclose(pf3);
return 0;
}
void encode(unsigned char *pT,unsigned char *cT,unsigned long n,unsigned long e)
{
unsigned long i;
unsigned long p,c;
p=(unsigned long)(pT[0]);
c=1;
for (i=0;i<16;i++) //快速幂模求法
{
if ((e&0x0001)!=0)
c=(c*p)%n;
p=(p*p)%n;
e=e>>1;
}
cT[0]=(unsigned char)(c&0xff);
cT[1]=(unsigned char)((c&0xff00)>>8);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -