5 static void print_by_16s (const byteArray b, std::string name)
9 std::cout << "\nPrinting: " << name << std::endl;
11 for (i=0; i<b.size()/16; ++i)
14 std::printf ("%.2x ", b.at(i*16+j));
21 int main (int argc, char *argv[])
28 //#define AES_128_EXAMPLE 1
29 #define AES_128_EXAMPLE2 1
38 key.push_back (getchar());
40 /* Create the AES object */
43 /* Read all characters of input */
46 for (char c=getchar(); c != EOF; c=getchar())
50 if (input.size() == 16)
52 byteArray ciphertext = aes.encrypt (input);
53 byteArray plaintext = aes.decrypt (ciphertext);
56 for (i=0; i<plaintext.size(); ++i)
57 std::printf ("%c", plaintext.at(i));
66 std::ifstream fin ("Problem3.out", ios::binary);
72 key.push_back (fin.get());
74 /* Create the AES Object */
79 /* Read the input and decrypt */
80 for (char c=fin.get(); !fin.eof(); c=fin.get())
84 if (input.size() == 16)
86 byteArray plaintext = aes.decrypt (input);
89 for (i=0; i<plaintext.size(); ++i)
90 std::printf ("%c", plaintext.at(i));
98 const int inputSize = 4096;
100 byteArray key (16, 2);
101 byteArray input (inputSize, 0);
104 for (i=0; i<inputSize; ++i)
109 print_by_16s (input, "Input");
111 byteArray ciphertext = aes.encrypt (input);
113 print_by_16s (ciphertext, "Ciphertext");
115 byteArray plaintext = aes.decrypt (ciphertext);
117 print_by_16s (plaintext, "Plaintext");
123 byteArray key (16, 0);
128 print_by_16s (key, "Key");
130 byteArray plaintext (16, 0);
133 plaintext.at (i) = (i << 4) | i;
135 print_by_16s (plaintext, "Plaintext");
139 byteArray ciphertext = aes.encrypt (plaintext);
141 print_by_16s (ciphertext, "Ciphertext");
146 byteArray key (16, 0);
147 byteArray plaintext (16, 0);
153 plaintext.at (i) = (i) | (i<<4);
156 byteArray ciphertext = aes.encrypt (plaintext);
158 print_by_16s (key, "Key");
159 print_by_16s (plaintext, "Plaintext");
160 print_by_16s (ciphertext, "Ciphertext");
161 #endif // AES_128_EXAMPLE
165 byteArray key (16, 0);
166 byteArray plaintext (16, 0);
195 plaintext[10] = 0x98;
196 plaintext[11] = 0xa2;
197 plaintext[12] = 0xe0;
198 plaintext[13] = 0x37;
199 plaintext[14] = 0x07;
200 plaintext[15] = 0x34;
203 byteArray ciphertext = aes.encrypt (plaintext);
205 print_by_16s (key, "Key");
206 print_by_16s (plaintext, "Plaintext");
207 print_by_16s (ciphertext, "Ciphertext");
208 #endif // AES_128_EXAMPLE
213 /* vim: set ts=4 sts=4 sw=4 noet tw=120 nowrap: */