des加密解密算法c语言实现,C++实现DES加密算法实例解析

本文所述实例是一个实现DES加密算法的程序代码,在C++中,DES加密是比较常用的加密算法了,且应用非常广泛。本CPP类文件可满足你的DES加密需要,代码中附带了丰富的注释,相信对于大家理解DES可以起到很大的帮助。

具体实现代码如下:

#include "memory.h"

#include "stdio.h"

enum {encrypt,decrypt};//ENCRYPT:加密,DECRYPT:解密

void des_run(char out[8],char in[8],bool type=encrypt);

//设置密钥

void des_setkey(const char key[8]);

static void f_func(bool in[32],const bool ki[48]);//f函数

static void s_func(bool out[32],const bool in[48]);//s盒代替

//变换

static void transform(bool *out, bool *in, const char *table, int len);

static void xor(bool *ina, const bool *inb, int len);//异或

static void rotatel(bool *in, int len, int loop);//循环左移

//字节组转换成位组

static void bytetobit(bool *out,const char *in, int bits);

//位组转换成字节组

static void bittobyte(char *out, const bool *in, int bits);

//置换IP表

const static char ip_table[64]={58,50,42,34,26,18,10,2,60,52,44,36,28,20,12,4,62,54,46,38,30,22,14,6,64,56,48,40,32,24,16,8,57,49,41,33,25,17,9,1,59,51,43,35,27,19,11,3,61,53,45,37,29,21,13,5,63,55,47,39,31,23,15,7};

//逆置换IP-1表

const static char ipr_table[64]={40,8,48,16,56,24,64,32,39,7,47,15,55,23,63,31,38,6,46,14,54,22,62,30,37,5,45,13,53,21,61,29,36,4,44,12,52,20,60,28,35,3,43,11, 51,19,59,27,34,2,42,10,50,18,58,26,33,1,41,9,49,17,57,25};

//E 位选择表

static const char e_table[48]={32,1, 2, 3, 4, 5,4, 5, 6, 7, 8, 9,8, 9, 10,11,12,13,12,13,14,15,16,17,16,17,18,19,20,21,20,21,22,23,24,25,24,25,26,27

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值