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