C语言实现:
下面仅仅是用8 bytes 16进制的data和8 bytes 16进制的key,做个简单测试,
并顺手做了个解密,并把结果打印出来。
在此种情形下,网络上各种网页版的DES加密、解密工具的结果和下文的代码是不同的。
举例:(16进制8 bytes)
key: 1234567812345678
data: 61B6EF78C6435CCD
ciphertext: FEDFDAA09E53547B
/*ONLY support 8 bytes input */
int des_encrypt_decrypt(const unsigned char *data, const unsigned char *key, unsigned char *ciphertext)
{
DES_cblock output, o_de;
DES_key_schedule schedule;
DES_set_key_unchecked(key, &schedule);
printf("set key unchecked!\n");
DES_ecb_encrypt(data, &output, &schedule, DES_ENCRYPT);
printf("DES ecb encrypt done!\n");
printf("ciphertext: ");
for(int i=0; i<8; i++)
{
printf("%02X", output[i]);
ciphertext[i] = output[i];
}
printf("\n");
DES_ecb_encrypt(ciphertext, &o_de, &schedule, DES_DECRYPT);
printf("DES ecb decrypt done!\n");
printf("clea

本文分别介绍了如何使用C语言和Python实现DES ECB加解密。在C语言中,展示了简单的8 bytes 16进制数据和密钥的加密解密过程。而在Python环境下,通过pyDes库进行操作,需要注意进制转换和padmode设置。提供的代码在特定条件下运行正常。
最低0.47元/天 解锁文章
603

被折叠的 条评论
为什么被折叠?



