📄 main.cpp
字号:
#include <stdio.h>
#include <iostream.h>
#include "aes.h"
main()
{
/*
//test for multiply() add() div()
cout<<(WORD)a.multiply(87,131);
cout<<"\n";
cout<<(DWORD)a.multiply2(283,7);
cout<<"\n";
cout<<(WORD)a.add2(4,3);
cout<<"\n";
cout<<(WORD)a.div(0x21,0x3);
cout<<"\n";
cout<<(WORD)a.div2(456,13);
cout<<"\n";
*/
/*
//test for subByte()
BYTE c=0xb2,*b;//ff ,00
b=&c;
cout<<(WORD)c<<"\n";
a.subByte(b);
cout<<(WORD)c<<"\n";
a.invSubByte(b);
cout<<(WORD)*b<<"\n";
*/
/*
//test for subByte()
int i;
BYTE c[16];
for(i=0; i<16; i++)
{
c[i]=i;
c[i]^=0xf0; //change with 0x10,0x20.....0xf0
a.subByte(&c[i]);
printf("%x ",c[i]);
a.invSubByte(&c[i]);
}
printf("\n");
for(i=0; i<16; i++)
{
printf("%x\n",c[i]);
}
*/
/*
//test for subDword()
DWORD u[1];
u[0]=0x31ff0011;
a.subDword(u);
printf("%x\n",u[0]);
*/
/*
//test for rotDword()
DWORD u[1];
u[0]=0x31ff0011;
a.rotDword(u);
printf("%x\n",u[0]);
*/
/*
//test for keyExpansion()
int i;
a.KeyExpansion();
for(i=0; i < 16 ; i++)
{
printf("%x\n", a.key[i]);
}
for(i=0; i < a.Nb*(a.Nr + 1); i++)
{
printf("%x\n", a.w[i]);
}
*/
//test for shiftRows() and invShiftRows()
/*
int i;
a.shiftRows(a.key);
a.invShiftRows(a.key);
for(i=0; i< 16; i++)
printf("%x\n", a.key[i]);
*/
//test for mixColumns()
/*
int i;
a.mixColumns(a.key);
a.invMixColumns(a.key);
for(i=0; i<16; i++)
printf("%x\n" , a.key[i]);
*/
//test for addRoundKey()
/*
int i;
BYTE input[16]={0x32 , 0x43 , 0xf6 , 0xa8 ,
0x88 , 0x5a , 0x30 , 0x8d ,
0x31 , 0x31 , 0x98 , 0xa2 ,
0xe0 , 0x37 , 0x07 , 0x34 };
a.KeyExpansion();
for(i=0; i<16; i++)
printf("%x " , input[i]);
printf("\n");
for(i=0; i<16; i++)
printf("%x " , *(((BYTE*)(a.w))+i));
printf("\n");
a.addRoundKey(input , a.w);
for(i=0; i<16; i++)
printf("%x " , input[i]);
printf("\n");
*/
//test for Encipher() and Decipher()
/*
BYTE input[16]={0x32 , 0x43 , 0xf6 , 0xa8 ,
0x88 , 0x5a , 0x30 , 0x8d ,
0x31 , 0x31 , 0x98 , 0xa2 ,
0xe0 , 0x37 , 0x07 , 0x34 };
*/
//plain=00112233445566778899aabbccddeeff
BYTE input[16]={0x00 , 0x11 , 0x22 , 0x33 ,
0x44 , 0x55 , 0x66 , 0x77 ,
0x88 , 0x99 , 0xaa , 0xbb ,
0xcc , 0xdd , 0xee , 0xff };
BYTE key[32]= {0x00,0x01,0x02,0x03,
0x04,0x05,0x06,0x07,
0x08,0x09,0x0a,0x0b,
0x0c,0x0d,0x0e,0x0f,
0x10,0x11,0x12,0x13,
0x14,0x15,0x16,0x17,
0x18,0x19,0x1a,0x1b,
0x1c,0x1d,0x1e,0x1f};
Caes a(8,4,key);
a.Encipher(input);
int i;
for(i=0; i<16; i++)
printf("%x ",input[i]);
printf("\n");
a.Decipher(input);
for(i=0; i<16; i++)
printf("%x " , input[i]);
printf("\n");
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -