AES加密算法实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验报告

学号:姓名:专业:班级:第 10 周

static void SubBytes(unsigned char p[16]);

static void inSubBytes(unsigned char p[16]);

static void ShiftRows(unsigned char e[]);

static void inShiftRows(unsigned char e[]);

static void MatrixToByte(unsigned char e[]);

static void inMatrixToByte(unsigned char e[]);

static unsigned char FFmul(unsigned char a, unsigned char b);

static void KeyAdding(unsigned char state[16], unsigned char k[][4]);

static void KeyExpansion(unsigned char* key, unsigned char w[][4][4]);

~plaintext();

private:

};

#include""

using namespace std;

static unsigned char sBox[] = {};/定义加密S盒/

unsigned char insBox[256] ={};//定义解密S盒

plaintext::plaintext()

{

}

void plaintext::createplaintext(unsigned char a[])//创建明文

{

int i = 0;

unsigned int p[16];

for (int j = 0; j<200; j++)

{

if (a[j] == 0)

{

break;

}

}

for (; i<16; i++)

{

p[i] = a[i];

a[i] = a[i + 16];

}

}

void plaintext::SubBytes(unsigned char p[16])//字节变换函数

{

unsigned char b[16];

for (int i = 0; i<16; i++)

{

b[i] = sBox[(int)p[i]];

}

}

void plaintext::inSubBytes(unsigned char p[16])//逆字节变换函数{

unsigned char b[16];

for (int i = 0; i<16; i++)

{

b[i] = insBox[(int)p[i]];

}

}

void plaintext::ShiftRows(unsigned char e[])//行移位变换函数

{

unsigned char t[4];

for (int i = 1; i<4; i++)

{

for (int x = 0; x<4; x++)

t[x] = e[x + i * 4];

for (int y = 0; y<4; y++)

e[(y + 4 - i) % 4 + i * 4] = t[y];

}

}

void plaintext::inShiftRows(unsigned char e[])//逆行移位变换函数{

unsigned char t[4];

for (int i = 1; i<4; i++)

{

for (int x = 0; x<4; x++)

t[x] = e[x + i * 4];

for (int y = 0; y<4; y++)

e[(y + i) % 4 + i * 4] = t[y];

}

}

void plaintext::MatrixToByte(unsigned char e[])//列混合变换函数

{

unsigned char t[4];

int r, c;

for (c = 0; c< 4; c++)

{

for (r = 0; r<4; r++)

{

t[r] = e[r * 4 + c];

}

for (r = 0; r<4; r++)

{

e[r * 4 + c] = FFmul(0x02, t[r])

^ FFmul(0x03, t[(r + 1) % 4])

^ FFmul(0x01, t[(r + 2) % 4])

^ FFmul(0x01, t[(r + 3) % 4]);

}

}

}

void plaintext::inMatrixToByte(unsigned char e[])//逆列混合变换函数{

unsigned char t[4];

int r, c;

for (c = 0; c< 4; c++)

{

for (r = 0; r<4; r++)

{

t[r] = e[r * 4 + c];

}

for (r = 0; r<4; r++)

{

相关文档
最新文档