作者:finallyliuyu 出处:博客园
注意:整个三重DES加密算法,是在了解DES算法原理的基础上,并且在邹德强先生的源码基础上进行改编。
实现对任意长度明文进行加密
mingwenori的维度为多少,那么datalenori就等于多少。
任意长度明文加密
void main()
{
printf("finish\n");
myDES des;
int datalenori=11;
int datalen=0;
char mingwenori[11]={'a','b','c','d','e',',','0','8','v','A','~'};
char key[24]={'q','w','r','t','y','u','0','b','v','s','a','z','l',';','y','5','?','3','n','m','3','0','a','q'};
for (int i=0;i<datalenori;i++)
{
printf("%c",mingwenori[i]);
}
printf("\n");
if(datalenori%8)
{
datalen=(datalenori/8+1)*8;
}
else
{
datalen=datalenori;
}
char *miwen=new char[datalen];
char*mingwen=new char[datalen];
char *descriptmingwen=new char[datalen];
des.RunPad(mingwenori,datalenori,mingwen);
des.RunDes(true,mingwen,miwen,datalen,key,24);
for (int i=0;i<datalen;i++)
{
printf("%c",miwen[i]);
}
printf("\n");
des.RunDes(false,miwen,descriptmingwen,datalen,key,24);
for (int i=0;i<datalen;i++)
{
printf("%c",descriptmingwen[i]);
}
delete mingwen;
delete miwen;
delete descriptmingwen;
int end;
scanf("%d",&end);
}
{
printf("finish\n");
myDES des;
int datalenori=11;
int datalen=0;
char mingwenori[11]={'a','b','c','d','e',',','0','8','v','A','~'};
char key[24]={'q','w','r','t','y','u','0','b','v','s','a','z','l',';','y','5','?','3','n','m','3','0','a','q'};
for (int i=0;i<datalenori;i++)
{
printf("%c",mingwenori[i]);
}
printf("\n");
if(datalenori%8)
{
datalen=(datalenori/8+1)*8;
}
else
{
datalen=datalenori;
}
char *miwen=new char[datalen];
char*mingwen=new char[datalen];
char *descriptmingwen=new char[datalen];
des.RunPad(mingwenori,datalenori,mingwen);
des.RunDes(true,mingwen,miwen,datalen,key,24);
for (int i=0;i<datalen;i++)
{
printf("%c",miwen[i]);
}
printf("\n");
des.RunDes(false,miwen,descriptmingwen,datalen,key,24);
for (int i=0;i<datalen;i++)
{
printf("%c",descriptmingwen[i]);
}
delete mingwen;
delete miwen;
delete descriptmingwen;
int end;
scanf("%d",&end);
}