yxyDES2.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef yxyDESH
  2. #define yxyDESH
  3. #include <string>
  4. class yxyDES2
  5. {
  6. public:
  7. //类构造函数
  8. yxyDES2();
  9. //类析构函数
  10. ~yxyDES2();
  11. void InitializeKey(char* srcBytes,unsigned int keyN);
  12. void EncryptData(char* _srcBytes,unsigned int keyN);
  13. void DecryptData(char* _srcBytes,unsigned int keyN);
  14. //功能:加密任意长度字符串
  15. //参数:任意长度字符串,长度,使用Key的序号0-1
  16. //结果:函数将加密后结果存放于private szFCiphertextAnyLength[8192]
  17. // 用户通过属性CiphertextAnyLength得到
  18. void EncryptAnyLength(char* _srcBytes,unsigned int _bytesLength,unsigned int keyN);
  19. //功能:解密任意长度十六进制字符串
  20. //参数:任意长度字符串,长度,使用Key的序号0-1
  21. //结果:函数将加密后结果存放于private szFPlaintextAnyLength[8192]
  22. // 用户通过属性PlaintextAnyLength得到
  23. void DecryptAnyLength(char* _srcBytes,unsigned int _bytesLength, unsigned int keyN);
  24. //功能:Bytes到Bits的转换,
  25. //参数:待变换字符串,处理后结果存放缓冲区指针,Bits缓冲区大小
  26. void Bytes2Bits(char *srcBytes, char* dstBits, unsigned int sizeBits);
  27. //功能:Bits到Bytes的转换,
  28. //参数:待变换字符串,处理后结果存放缓冲区指针,Bits缓冲区大小
  29. void Bits2Bytes(char *dstBytes, char* srcBits, unsigned int sizeBits);
  30. //功能:Int到Bits的转换,
  31. //参数:待变换字符串,处理后结果存放缓冲区指针
  32. void Int2Bits(unsigned int srcByte, char* dstBits);
  33. //功能:Bits到Hex的转换
  34. //参数:待变换字符串,处理后结果存放缓冲区指针,Bits缓冲区大小
  35. void Bits2Hex(char *dstHex, char* srcBits, unsigned int sizeBits);
  36. //功能:Bits到Hex的转换
  37. //参数:待变换字符串,处理后结果存放缓冲区指针,Bits缓冲区大小
  38. void Hex2Bits(char *srcHex, char* dstBits, unsigned int sizeBits);
  39. //szCiphertextInBinary的get函数
  40. char* GetCiphertextInBinary();
  41. //szCiphertextInHex的get函数
  42. char* GetCiphertextInHex();
  43. //Ciphertext的get函数
  44. char* GetCiphertextInBytes();
  45. //Plaintext的get函数
  46. char* GetPlaintext();
  47. //CiphertextAnyLength的get函数
  48. char* GetCiphertextAnyLength();
  49. //PlaintextAnyLength的get函数
  50. char* GetPlaintextAnyLength();
  51. private:
  52. char szSubKeys[2][16][48];//储存2个16组48位密钥,第2个用于3DES
  53. char szCiphertextRaw[64]; //储存二进制密文(64个Bits) int 0,1
  54. char szPlaintextRaw[64]; //储存二进制密文(64个Bits) int 0,1
  55. char szCiphertextInBytes[8];//储存8位密文
  56. char szPlaintextInBytes[8];//储存8位明文字符串
  57. char szCiphertextInBinary[65]; //储存二进制密文(64个Bits) char '0','1',最后一位存'\0'
  58. char szCiphertextInHex[17]; //储存十六进制密文,最后一位存'\0'
  59. char szPlaintext[9];//储存8位明文字符串,最后一位存'\0'
  60. char szFCiphertextAnyLength[8192];//任意长度密文
  61. char szFPlaintextAnyLength[8192];//任意长度明文字符串
  62. void CreateSubKey(char* sz_56key,unsigned int keyN);
  63. void FunctionF(char* sz_Li,char* sz_Ri,unsigned int iKey,unsigned int keyN);
  64. //功能:IP变换
  65. //参数:待处理字符串,处理后结果存放指针
  66. //结果:函数改变第二个参数的内容
  67. void InitialPermuteData(char* _src,char* _dst);
  68. //功能:将右32位进行扩展位48位,
  69. //参数:原32位字符串,扩展后结果存放指针
  70. //结果:函数改变第二个参数的内容
  71. void ExpansionR(char* _src,char* _dst);
  72. //功能:异或函数,
  73. //参数:待异或的操作字符串1,字符串2,操作数长度,处理后结果存放指针
  74. //结果: 函数改变第四个参数的内容
  75. void XOR(char* szParam1,char* szParam2, unsigned int uiParamLength, char* szReturnValueBuffer);
  76. //功能:S-BOX , 数据压缩,
  77. //参数:48位二进制字符串,
  78. //结果:返回结果:32位字符串
  79. void CompressFuncS(char* _src48, char* _dst32);
  80. //功能:IP逆变换,
  81. //参数:待变换字符串,处理后结果存放指针
  82. //结果:函数改变第二个参数的内容
  83. void PermutationP(char* _src,char* _dst);
  84. };
  85. #endif