www.pudn.com > CipherSystem.rar > DESCipherSystem.h
#ifndef DES_CIPHER_SYSTEM_H #define DES_CIPHER_SYSTEM_H #include "MyCipherSystem.h" #include "GlobalConstArraysForDes.h" #include "GlobalFunctions.h" #include#include using std::deque; using std::string; typedef deque binary_stream; class DESCipherSystem : public EncryptSystem { public: void GetData(const string& input); void GetKey(const string& key); void Encrypt(); void Decrypt(); private: binary_stream subKeyStream48bit[16]; binary_stream keyWord; private: //初始变换 //return 64 bit binary stream after IP; ok binary_stream IP(const binary_stream& BinaryStream64bit); //逆初始变换 ok binary_stream AthwartIP(const binary_stream& BinaryStream64bit); //乘积变换 //return 64 bit binary stream binary_stream ProductSwitch(const binary_stream& BinaryStream64bit, const binary_stream& keyStream64bit, int mark = 1); //SUB 乘积变换, f函数 // input 32 bit binary stream, and the subKeyStream48bit[16] which is the member of the class // and the subKeyStream48bit displace which named i; // return 32 bit binary stream binary_stream Ffunction(const binary_stream& BinaryStream32bit, int i); //SUB of Ffunction, 扩展置换 //input 32 bit binary stream //return 48 bit binary stream binary_stream Expand(const binary_stream& BinaryStream32bit); //SUB of Ffunction, S盒变换 //input 48 bit binary stream, and a global S table; //return 32 bit binary stream binary_stream SboxPermutation(const binary_stream& BinaryStream48bit); //SUB of Ffunction, P盒变换 //input 32 bit binary stream, and a global p table; //return 32 bit binary stream binary_stream PboxPermutation(const binary_stream& BinaryStream32bit); //SUB 乘积变换, 子密钥的生成 //input: 64 bit binary stream, attention:the 64 bit binary stream should be change into 56 bit in the function //output: no ouput, but set the value of subKeyStream48bit[16] void SubKeyCreation(const binary_stream& keyStream64bit); //SUB 子密钥的生成, 置换选择1 //input: 56 bit binary stream(key), 28 bit binary stream C, 28 bit binary stream D, C and D should be empty // and a PC-1 table; //output: return void, but change the value of C and D above void PC_1(const binary_stream& keyStream56bit, binary_stream& keyStreamC28bit, binary_stream& keyStreamD28bit); //SUB 子密钥的生成, 循环左移计算 //input: 28 bit key binary stream C and D, //output: return void, the C and D's value will be changed void CycleLeftShift(binary_stream& keyStreamC28bit, binary_stream& keyStreamD28bit, int round); //SUB 子密钥的生成, 置换选择2 //input: 28 bit key binary stream C and D, and a PC-2 table //output:return void , but set the value of the subKeyStream48bit[16]; void PC_2(const binary_stream& keyStreamC28bit, const binary_stream& keyStreamD28bit, int displace); }; #endif //DES_CIPHER_SYSTEM_H