C++ 的DES加密程序

来源:百度知道 编辑:UC知道 时间:2024/05/09 20:58:05
其中设置了2个函数对于明文(字符型)和密文(字符型)转换其格式. 字符与01互换...
但是加密之后密文显示为乱码...请问可能是哪些问题?最好可以加下qq研究下.谢谢了....
已经发现是bitstochar函数错误... 程序在调用bitstochar时该函数bts参数是64位01数组没错,但是逐步调用是到输出的ch时..就是乱码..帮忙看下

struct bits{
bool bit[64];
int totalbit;
};
struct chars{
char ch[8];
int totalchar;
};

DESProcess::bitstochar(bits bts,chars *ch)
{
int cnt1,cnt2,pos,power;
for(cnt1=0;cnt1<8;cnt1++)
{
pos=0;
power=128;
for(cnt2=0;cnt2<8;cnt2++)
{
if(bts.bit[cnt1*8+cnt2])
pos+=power;
power/=2;
}
ch->ch[cnt1]=char(pos-28);
}
ch->totalchar=bts.totalbit / 8;
}

我的毕业设计是这个,我有个用MFC做的对文件,des加密。vc 6.0 下的完整工程文件。
由于太长,我就不发了。
我qq:380208702
emai :caojie-jerry@163.com

你是不是用中文啊...

int DES(

unsigned char *bufferin,

unsigned char *bufferout,

unsigned char *key,

long mode)

{

//密钥变换为56字节(去掉校验位)

static unsigned char pc1[56] = {

56, 48, 40, 32, 24, 16, 8,

0, 57, 49, 41, 33, 25, 17,

9, 1, 58, 50, 42, 34, 26,

18, 10, 2, 59, 51, 43, 35,

62, 54, 46, 38, 30, 22, 14,

6, 61, 53, 45, 37, 29, 21,

13, 5, 60, 52, 44, 36, 28,

20, 12, 4, 27, 19, 11, 3 };

//56字节变换为48 字节(数据压缩)

static unsigned char pc2[48] = {

13, 16, 10, 23, 0, 4,

2, 27, 14, 5, 20, 9,

22, 18, 11, 3, 25, 7,

15, 6, 26, 19, 12, 1,

40, 51, 30, 36, 46, 54,

29, 39, 50, 44, 32, 47,

43, 48, 38, 55, 33,