-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
46 lines (39 loc) · 951 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
AES encryption implementation
Made by: Jens Ekenblad
Based on: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf
https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
Length of key (K): 128 bits ->
Key length Nk = 4
Block size Nb = 4
Rounds Nr = 10
*/
#include <cstdio>
#include <iostream>
#include "aes.h"
using namespace std;
int main()
{
// Create AES object with matrix of 4x4 and start read key then continue reading blocks
AES aes;
int res = fread(aes.key, 4, 4, stdin);
if (res > 0)
{
aes.keyExpansion();
while (!feof(stdin))
{
res = fread(aes.block, 4, 4, stdin);
if (res > 0)
{
aes.encrypt();
(void)fwrite(aes.block, 4, 4, stdout);
}
}
}
else
{
cout << "Error reading key" << endl;
return 1;
}
return 0;
}