📄 aescryptosystem.h
字号:
#pragma once
//#include "utils.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <fcntl.h>
#include <windows.h>
#include <string>
//#include "utils.h"
#define BYTE_SIZE 8
#define CHAR_TO_COMPLETE_TEXT 0
unsigned char gmul(unsigned char a, unsigned char b);
class AESCryptoSystem
{
public:
typedef unsigned char byte;
typedef unsigned char word[4];
typedef byte state[4][4];
private:
const int m_ciNb; // nr of block collumns;
int m_iNk; // nr of key collumns;
int m_iNr; // nr of rounds, base in Nb and Nk;
byte* m_pKey; // key
DWORD m_iOriginalTextSize;
DWORD m_iPlainTextSize;
byte* m_pPlainText; // input text
byte* m_pCryptedText; // crypted input text
DWORD m_iCryptoTextSize;
byte* m_pCryptoText;
byte* m_pDecryptedText;
//state m_state; // current state;
word* m_pExpandedKey;
public:
static const byte st_cSBox[256];
static const byte st_cSBoxInv[256];
static const byte st_cXtime2SBox[256];
static const byte st_cXtime3SBox[256];
static const byte st_cXtime2[256];
static const byte st_cXtime3[256];
static const byte st_cXtime9[256];
static const byte st_cXtimeB[256];
static const byte st_cXtimeD[256];
static const byte st_cXtimeE[256];
static const byte st_cRcon[15];
public:
AESCryptoSystem(void);
~AESCryptoSystem(void);
private:
//void SaveText(const std::string& s, int fileSize, byte* text);
void ErrorExit(LPTSTR lpszFunction) const;
void SetFile(const std::string& sFileName, DWORD& fileSize, byte** ppSrcText, byte** ppDstText, bool bIsCryptoText);
void SaveFile(const std::string& sFileName, DWORD bytesToWrite, const byte* pText, bool bIsCryptedText) const;
word& operator = (const word& w1);
void PrintToScreen(const byte* pT, DWORD size);
void PrintToScreen(const word& w);
void PrintToScreen(const state& s);
void PrintToScreenKey(const word* pW);
private:
void CalculateRoundKey();
void RotByte(word& w);
void SubBytes(word& w);
void Encode(state& currState);
void AddRoundKey(state& s, const word* key);
void SubBytes(state& s);
void ShiftRows(state& s);
void MixColumns(state& s);
void Decode(state& currState);
void InvSubBytes(state& s);
void InvShiftRows(state& s);
void InvMixColumns(state& s);
public:
void SetKeyFile(const std::string& s);
void SetPlainTextFile(const std::string& s);
void SetCryptoTextFile(const std::string& s);
void SaveCryptedTextToFile(const std::string& s);
void SaveDecryptedTextToFile(const std::string& s);
void Encrypt();
void Decrypt();
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -