?? des.h
字號:
//---------------------------------------------------------------------------
#ifndef DESH
#define DESH
//---------------------------------------------------------------------------
#include <string>
#include <cmath>
#include <fstream>
#include <stdio.h>
#include <windows.h>
using namespace std;
class DES
{
public:
DES(); //類構造函數
~DES(); //類析構函數
//--------------------------------------------------------------
void InitializeKey(string,bool);
//功能:產生16個28位的key
//參數:源8位的字符串(key)
//結果:函數將調用private CreateSubKey將結果存于char SubKeys[16][48]
//--------------------------------------------------------------
//--------------------------------------------------------------
void EncryptData(string,bool,bool);
//功能:加密8位字符串
//參數:8位字符串
//結果:函數將加密后結果存放于private szCiphertext[16]
// 用戶通過屬性Ciphertext得到
//--------------------------------------------------------------
//--------------------------------------------------------------
void DecryptData(string,bool,bool);
//功能:解密16位十六進制字符串
//參數:16位十六進制字符串
//結果:函數將解密候結果存放于private szPlaintext[8]
// 用戶通過屬性Plaintext得到
//--------------------------------------------------------------
//--------------------------------------------------------------
void EncryptAnyLength(string,bool);
//功能:加密任意長度字符串
//參數:任意長度字符串
//結果:函數將加密后結果存放于private szFCiphertextAnyLength[8192]
// 用戶通過屬性CiphertextAnyLength得到
//--------------------------------------------------------------
//--------------------------------------------------------------
void DecryptAnyLength(string,bool);
//功能:解密任意長度十六進制字符串
//參數:任意長度字符串
//結果:函數將加密后結果存放于private szFPlaintextAnyLength[4096]
// 用戶通過屬性PlaintextAnyLength得到
//--------------------------------------------------------------
//--------------------------------------------------------------
void TripleEncryptAnyLength(string);
//功能:使用3DES加密任意長度字符串
//參數:任意長度字符串
//結果:函數將加密后結果存放于private szFCiphertextAnyLength[8192]
// 用戶通過屬性CiphertextAnyLength得到
//--------------------------------------------------------------
//--------------------------------------------------------------
void TripleDecryptAnyLength(string);
//功能:使用3DES解密任意長度十六進制字符串
//參數:任意長度字符串
//結果:函數將加密后結果存放于private szFPlaintextAnyLength[4096]
// 用戶通過屬性PlaintextAnyLength得到
//--------------------------------------------------------------
//--------------------------------------------------------------
void TripleEncrypt(string,bool);
//功能:使用3DES加密8位字符串
//參數:8位字符串
//結果:函數將加密后結果存放于private szCiphertext[16]
// 用戶通過屬性Ciphertext得到
//--------------------------------------------------------------
//--------------------------------------------------------------
void TripleDecrypt(string,bool);
//功能:使用3DES解密16位十六進制字符串
//參數:16位十六進制字符串
//結果:函數將解密候結果存放于private szPlaintext[8]
// 用戶通過屬性Plaintext得到
//--------------------------------------------------------------
//--------------------------------------------------------------
bool FileEncrypt(string,bool);
//功能:文件加密,尚有已知BUG請慎重使用
//參數:文件path,是否使用3DES
//結果:源文件名.DES
//--------------------------------------------------------------
//--------------------------------------------------------------
bool FileDecrypt(string,bool);
//功能:文件解密,尚有已知BUG請慎重使用
//參數:文件path(文件名.DES),是否使用3DES
//結果:源文件名
//--------------------------------------------------------------
//--------------------------------------------------------------
void SetCiphertext(char* value);
//屬性Ciphertext的set函數
//--------------------------------------------------------------
//--------------------------------------------------------------
char* GetCiphertext();
//屬性Ciphertext的get函數
//--------------------------------------------------------------
//--------------------------------------------------------------
void SetPlaintext(char* value);
//屬性Plaintext的set函數
//--------------------------------------------------------------
//--------------------------------------------------------------
char* GetPlaintext();
//屬性Plaintext的get函數
//--------------------------------------------------------------
//--------------------------------------------------------------
char* GetCiphertextAnyLength();
//屬性CiphertextAnyLength的get函數
//--------------------------------------------------------------
//--------------------------------------------------------------
char* GetPlaintextAnyLength();
//屬性PlaintextAnyLength的get函數
//--------------------------------------------------------------
private:
//--------------------------------------------------------------
char SubKeys[16][48];//儲存16組48位密鑰
char SubKeys2[16][48];//儲存16組48位密鑰
char szCiphertext[16];//儲存16位密文(十六進制字符串)
char szPlaintext[8];//儲存8位明文字符串
char szFCiphertextAnyLength[8192];//任意長度密文(十六進制字符串)
char szFPlaintextAnyLength[4096];//任意長度明文字符串
//--------------------------------------------------------------
//--------------------------------------------------------------
void CreateSubKey(char*,char[16][48]);
//功能:生成子密鑰
//參數:經過PC1變換的56位二進制字符串
//結果:將保存于char SubKeys[16][48]
//--------------------------------------------------------------
//--------------------------------------------------------------
void FunctionF(char*,char*,bool,int);
//功能:DES中的F函數,
//參數:左32位,右32位,key序號(0-15)
//結果:均在變換左右32位
//--------------------------------------------------------------
//--------------------------------------------------------------
void InitialPermuteData(string,char*,bool);
//功能:IP變換
//參數:待處理字符串,處理后結果存放指針,加密/解密(true加密,false解密)
//結果:函數改變第二個參數的內容
//--------------------------------------------------------------
//--------------------------------------------------------------
void ExpansionR(char* ,char*);
//功能:將右32位進行擴展位48位,
//參數:原32位字符串,擴展后結果存放指針
//結果:函數改變第二個參數的內容
//--------------------------------------------------------------
//--------------------------------------------------------------
void XOR(char* ,char* ,int ,char*);
//功能:異或函數,
//參數:待異或的操作字符串1,字符串2,操作數長度,處理后結果存放指針
//結果: 函數改變第四個參數的內容
//--------------------------------------------------------------
//--------------------------------------------------------------
string CompressFuncS(char* );
//功能:S-BOX , 數據壓縮,
//參數:48位二進制字符串,
//結果:返回結果:32位字符串
//--------------------------------------------------------------
//--------------------------------------------------------------
void PermutationP(string ,char*);
//功能:IP逆變換,
//參數:待變換字符串,處理后結果存放指針
//結果:函數改變第二個參數的內容
//--------------------------------------------------------------
//--------------------------------------------------------------
string FillToEightBits(string);
//功能:當明文不足8位,使用'$'進行填充,
//參數:原始字符串,
//結果:返回8位字符串
//--------------------------------------------------------------
//--------------------------------------------------------------
void CleanPlaintextMark(int);
//將不足8位而補齊的明文處理還原
//函數將處理szFPlaintextAnyLength
//結果: 例如123$$$$$ 處理后將變為 123'\0'
//--------------------------------------------------------------
//--------------------------------------------------------------
string HexCharToBinary(char);
//功能:16進制字符('0'-'F')到2進制字符串的轉換
//參數:十六進制字符('0'-'F')
//結果:返回二進制字符串("0000"-"1111")
//--------------------------------------------------------------
//--------------------------------------------------------------
string HexIntToBinary(int );
//功能:16進制整數(0-15)到2進制字符串的轉換
//參數:十六進制整數(0-15)
//結果:返回二進制字符串("0000"-"1111")
//--------------------------------------------------------------
//--------------------------------------------------------------
string BinaryToString(char*,int,bool);
//功能:二進制串到字符串的轉換,
//參數:源二進制字符串,二進制字符串長度,類型(true為二進制到hex,false為二進制到ANSCII char),
//結果:返回處理后結果
//--------------------------------------------------------------
//--------------------------------------------------------------
int SingleCharToBinary(char);
//功能:單個char '0'或'1' 到int 0或1的變換
//參數: '0'或'1'
//結果:0或1
//--------------------------------------------------------------
//--------------------------------------------------------------
char SingleBinaryToChar(int);
//功能:將int類型的0或1轉換為char類型的0或1
//參數:0或1
//返回:'0'或'1'
//--------------------------------------------------------------
void TranslateBytes2Bits(string, char*);
void TranslateBits2Bytes(char*, char*);
};
//---------------------------------------------------------------------------
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -