利用c++语言实现des算法,DES加密算法C++实现

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#include

#include

#include

#define ENCRYPT 1

#define DECRYPT 0

static void printHex ( char *cmd,int len );

static void printArray ( const char *In,int len );

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 ); // 位组转换成字节组

// 16位子密钥

static bool SubKey[16][48];

// 64位经过PC1转换为56位 (PC-1)

const static char PC1_Table[56] =

{

57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4

};

// 左移

const static char LOOP_Table[16] =

{

1,1

};

// 排列选择 2 (PC-2)

const static char PC2_Table[48] =

{

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

};

// Ri_1(32位)经过变换E后膨胀为48位 (E) void F_func

static const char E_Table[48] =

{

32,32,1

};

// 8个4比特合并为32比特的排列 P

const static char P_Table[32] =

{

16,};

// 经过S盒 S-Boxes

const static char S_Box[8][

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值