34 Star 68 Fork 28

qingfengfumeng/文件软硬件加解密平台

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AES.h 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
qingfengfumeng 提交于 2024-05-09 20:50 +08:00 . add AES.h
#ifndef AES_H
#define AES_H
/**************************************************
* project name: AES
* author: wang binbin
* completion time: 2024.3.26
*************************************************/
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<iomanip>
#include<cstdio>
#include<bitset>
#include<stack>
#include<cmath>
#include<random>
#include<ctime>
using namespace std;
#define NUMBER 16
#define SECRET_KEY_PATH "key.txt"
class AES
{
public:
AES();
// Generate a random key
void genKey(std::string outputname);
// Get key
void getKey(const std::string filename);
// AES encryption
void encrypt(int ptext[4][4]);
// AES decryption
void decrypt(int ctext[4][4]);
// Encrypt the file
bool encrypt_file(const std::string filename, const std::string outname);
// Decrypt the file
bool decrypt_file(const std::string filename, const std::string outname);
private:
std::string Key;
// Generating S-box
void genSbox(int box[16][16]);
// Generating inverse S-box
void genSbox2(int box[16][16]);
// Multiplication over finite fields
int gfMul(int n, int m);
// Find inverses over finite fields
int invElement(int m);
// Byte move
void leftByte(int word[4]);
// G function for MixColumn
void gFunction(int word[4], int round);
// key expansion
void keyExpansion(int word[4][44]);
// Byte conversion
void subBytes(int m[4][4]);
// Inverse byte conversion
void subBytes2(int m[4][4]);
// Row shift
void shiftRow(int m[4][4]);
// Inverse row shift
void shiftRow2(int m[4][4]);
// Column mix
void mixColumn(int m[4][4]);
// Inverse column mix
void mixColumn2(int m[4][4]);
// RoundKey Add
void addRoundKey(int m[4][4], int key[4][4]);
// Integer to hexadecimal
std::string intToHex(int value);
// Hexadecimal to integer
int hexToInt(const std::string& hexStr);
};
#endif // AES_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/qingfengfumeng/cryptography_file_protection.git
git@gitee.com:qingfengfumeng/cryptography_file_protection.git
qingfengfumeng
cryptography_file_protection
文件软硬件加解密平台
master

搜索帮助