资源描述:
《des算法c++源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、DES算法C++源代码文章来源:黑客中国更新时间:2005-12-12Des.cpp/********************************************************************//*DES(DataEncryptionStandard)*//*WrittenbyBunny*//*BanyetSoftLabs.1999*//*ALLRIGHTSRESERVED!*//*注意!版权所有!可以自由转载,但不得加以修改或删除!*//*E-mail:Assassin@ynmai
2、l.comHttp://Assassin.yeah.net*//********************************************************************//**************************************************************************//*注意:这只是标准DES算法的例子,所以速度并不是很快,不适用于大量数据加密的场*//*合.UNIX的密码也采用DES,不过它在里面加了点其它的东西.所以结果和D
3、ES的结果*//*不一样.由于使用了WINDOWS类库,所以必须在WINDOWS环境下编译.*//**************************************************************************/#include#include#include#include#include"Schedle.h"classCShift{public:DWORDLONGmask[16];intstep[16];CShift(){for(inti=0;i<16;i++){step=
4、2;mask=0xc000000;}step[0]=step[1]=step[8]=step[15]=1;mask[0]=mask[1]=mask[8]=mask[15]=0x8000000;}};classCDES{public:CDES(){m_dwlKey=0;m_dwlData=0;ConvertTableToMask(dwlKey_PC_1,64);//PrintTable(dwlKey_PC_1,7,8);ConvertTableToMask(dwlKey_PC_2,56);ConvertTableT
5、oMask(dwlData_IP,64);ConvertTableToMask(dwlData_Expansion,32);ConvertTableToMask(dwlData_FP,64);ConvertTableToMask(dwlData_P,32);Generate_S();}voidPrintBit(DWORDLONG);voidEncryptKey(char*);unsignedchar*EncryptData(unsignedchar*);unsignedchar*DescryptData(unsi
6、gnedchar*);private:voidConvertTableToMask(DWORDLONG*,int);voidGenerate_S(void);voidPrintTable(DWORDLONG*,int,int);DWORDLONGProcessByte(unsignedchar*,BOOL);DWORDLONGPermuteTable(DWORDLONG,DWORDLONG*,int);voidGenerate_K(void);voidEncryptKernel(void);DWORDLONGGe
7、nerate_B(DWORDLONG,DWORDLONG*);/*Forverifyschedulepermutationonly*/DWORDLONGUnPermuteTable(DWORDLONG,DWORDLONG*,int);/**************************************/DWORDLONGdwlData_S[9][4][16];CShiftm_shift;DWORDLONGm_dwlKey;DWORDLONGm_dwlData;DWORDLONGm_dwl_K[17];}
8、;voidCDES::EncryptKey(char*key){printf("OriginalKey:%s",key);m_dwlKey=ProcessByte((unsignedchar*)key,TRUE);//PrintBit(m_dwlKey);m_dwlKey=PermuteTable(m_dwlKey,dwlKey_PC_1,56);//PrintBit