网站大量收购独家精品文档,联系QQ:2885784924

【VC】DES算法用C++實现的源代码.doc

  1. 1、本文档共5页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
【VC】DES算法用C實现的源代码

DES算法用C++实现的源代码 ? 用C++实现的源代码 #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表 conststatic 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,28,29,28,29,30,31,32,1}; //P换位表 const static char p_table[32]={16,7,20,21,29,12,28,17,1,15,23,26,5,18,31,10,2,8,24,14,32,27,3,9,19,13,30,6,22,11,4,25}; //pc1选位表 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 }; //pc2选位表 const static char pc2_table[48]={ ?????? ???????????????????????????? 14,17,11,24,1,5,3,28, ??????????????????????????????????? 15,6,21,10,23,19,12,4, ??

您可能关注的文档

文档评论(0)

df9v4fzI + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档