AES CodeC++
AES CodeC++
cpp
* Performs decryption using AES 128-bit
*/
#include <iostream>
#include <cstring>
#include <fstream>
#include <sstream>
#include "structures.h"
/* Column 1 */
tmp[0] = state[0];
tmp[1] = state[13];
tmp[2] = state[10];
tmp[3] = state[7];
/* Column 2 */
tmp[4] = state[4];
tmp[5] = state[1];
tmp[6] = state[14];
tmp[7] = state[11];
/* Column 3 */
tmp[8] = state[8];
tmp[9] = state[5];
tmp[10] = state[2];
tmp[11] = state[15];
/* Column 4 */
tmp[12] = state[12];
tmp[13] = state[9];
tmp[14] = state[6];
tmp[15] = state[3];
InitialRound(state, expandedKey+160);
int numberOfRounds = 9;
int main() {
if (infile.is_open())
{
getline(infile, msgstr); // The first line of file is the message
cout << "Read in encrypted message from message.aes" << endl;
infile.close();
}
strcpy(msg, msgstr.c_str());
// Free memory
delete[] msg;
if (keyfile.is_open())
{
getline(keyfile, keystr); // The first line of file should be the key
cout << "Read in the 128-bit key from keyfile" << endl;
keyfile.close();
}
istringstream hex_chars_stream(keystr);
unsigned char key[16];
int i = 0;
unsigned int c;
while (hex_chars_stream >> hex >> c)
{
key[i] = c;
i++;
}
KeyExpansion(key, expandedKey);
return 0;
}