示例2:用默认keygen加解密
char data0[10]={
0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x10,
};
int main(int argc, char *argv[])
{
int i;
unsigned int len;
int j, r, key_num;
unsigned int sync = 0;
unsigned char key[MAX_KEY_REQUEST];
char buf[120]={0};
key_num = 10;
printf("\n--------------采用默认keygen开始加密----------------\n");
reset_keygen();
print_array("\n明文:",data0,key_num);
memset(key,0,sizeof(key));
len = request_key(sync,key_num,key);
print_array("密钥:",key,len);
for(i=0;i<len;i++)
{
buf[i] = data0[i]^key[i];
}
print_array("\n密文:",buf,len);
printf("\n--------------------开始解密--------------------\n");
reset_keygen();
memset(key,0,sizeof(key));
len = request_key(sync,key_num,key);
for(i=0;i<len;i++)
{
buf[i] = buf[i]^key[i];
}
print_array("\n明文:",buf,len);
}
测试结果:
--------------采用默认keygen开始加密----------------
明文: ----[10]
01 02 03 04 05 06 07 08 09 10
密钥: ----[10]
a5 52 c8 14 5d f7 46 5b 89 42
密文: ----[10]
a4 50 cb 10 58 f1 41 53 80 52
--------------------开始解密--------------------
明文: ----[10]
01 02 03 04 05 06 07 08 09 10
|