www.pudn.com > AES > function_E1_E2_E3.cpp
#include "stdio.h"
#define int_64bit double
#define int_32bit float
#define int_16bit short unsigned int
#define int_8bit unsigned char
//////////////////////////////////////function B///////////////////////////////////////////////////
//used in function roundkeygenerate
//Realize Fuction Bi, i=2~17,Bi is a bias vector of Ki
//The Function is
//Bi=B[p][i]= ((45**(45**(17*p+i+1) mod 257) mod 257)mod 256 )
// for i=0~15 p=1~17
//and by p is meant the number of round
//i is defined as the number of K
//The output will be convert to a table
//because the reslut is constant
//it's unnecessary to calculate every time
//to simple the function B , a table is made as following
int_8bit B[17][16]={
0x77,0xf1,0x56,0x24,0x7e,0x47,0x1b,0x86,0xbd,0x70,0x8e,0x1e,0x3b,0x73,0x16,0x03,
0x64,0xac,0x28,0x5a,0xc9,0xb3,0x37,0xc5,0x0a,0x10,0xb7,0xa3,0xba,0xb1,0x97,0x46,
0x3d,0x05,0xdc,0x66,0x6e,0xf6,0x9a,0xf8,0x0d,0x58,0x95,0x67,0xc6,0xaa,0xab,0xec,
0xa0,0x68,0x9b,0x96,0xd4,0xeb,0xbf,0x43,0x49,0x36,0xe9,0x6a,0x89,0xd8,0xc3,0x8a,
0x94,0x63,0x99,0xbc,0x7b,0xbe,0xc1,0x22,0xbb,0x5c,0x71,0xd5,0x1f,0x92,0x57,0x5d,
0x8f,0x44,0x41,0x1d,0x51,0xe6,0x40,0x17,0xfb,0xfd,0x19,0x32,0x34,0xb8,0x61,0x2a,
0xca,0x23,0x6f,0xda,0x39,0xf7,0xa2,0x01,0x7f,0xd6,0x31,0xe7,0xde,0x80,0x04,0xdd,
0x2c,0x59,0x82,0xaf,0xa8,0xe0,0x0f,0xcd,0xa1,0x12,0x3e,0x30,0xd1,0x1c,0xd0,0x3a,
0x33,0x72,0x2e,0x4f,0x90,0x02,0x13,0x06,0x75,0xce,0x87,0xc2,0xef,0xb2,0xad,0x7d,
0x38,0x15,0xe1,0x52,0x9f,0x7a,0x6c,0x2f,0x27,0xc4,0xe2,0x81,0xa9,0xcf,0x8d,0xc0,
0xd7,0xdf,0xff,0x60,0x76,0x14,0x8c,0x5e,0x55,0x09,0xe4,0x08,0xc7,0x42,0x20,0xfc,
0xd2,0x50,0x91,0xd9,0x4c,0x62,0x9e,0xe8,0xb9,0xa6,0xf9,0x1a,0x00,0x21,0x0b,0xfa,
0x35,0x9c,0x4e,0x4b,0x69,0x48,0xcb,0x0e,0xc8,0xa4,0x5b,0xea,0x84,0x07,0xb4,0x18,
0xf4,0xae,0x6b,0xdb,0xa7,0xcc,0x3f,0x8b,0x4a,0x0c,0x3c,0x25,0xe5,0x54,0x4d,0x45,
0x83,0xed,0x11,0xf0,0xb0,0x53,0x93,0xf2,0x74,0x26,0xb5,0x9d,0x6d,0x7c,0xf3,0x2d,
0xf1,0x56,0x24,0x7e,0x47,0x1b,0x86,0xbd,0x70,0x8e,0x1e,0x3b,0x73,0x16,0x03,0xb6,
0xac,0x28,0x5a,0xc9,0xb3,0x37,0xc5,0x0a,0x10,0xb7,0xa3,0xba,0xb1,0x97,0x46,0x88 };
///////////////////////////////////////function B//////////////////////////////////////////////
////////////////////////////////////Funciton e/////////////////////////////////
//This function can realize function e
//function e : ( 45**i (mod 257) ) (mod 256)
//function l is the reverse function of function e
//in the main function it will be made of two table as the etable the and ltable
//this funciton will be used in function roundkeygenerate
int_8bit etable[256];
int_8bit ltable[256];
int_8bit e(int_8bit i)
{
int temp = 1;
int_8bit counter;
for(counter=0;counter