Skip to content

Commit c519d2c

Browse files
authored
Add files via upload
1 parent 48ed9dd commit c519d2c

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

aes.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,32 @@ unsigned int gfMul(unsigned int a, unsigned int b){
565565
return r;
566566
}
567567

568+
// this function converts string to unsigned int array 4x4
569+
void convertStringToBlock(char string[BYTES+1], unsigned int block[][BLOCK_SIZE]){
570+
int i, j; // counter for loops
571+
572+
for(i = 0; i < BLOCK_SIZE; i++){
573+
for(j = 0; j < BLOCK_SIZE; j++){
574+
block[j][i] = string[BLOCK_SIZE * i + j];
575+
}
576+
}
577+
578+
return;
579+
}
580+
581+
// this function converts unsigned int array 4x4 to string
582+
void convertBlockToString(unsigned int block[][BLOCK_SIZE], char string[BYTES+1]){
583+
int i, j; // counter for loops
584+
585+
for(i = 0; i < BLOCK_SIZE; i++){
586+
for(j = 0; j < BLOCK_SIZE; j++){
587+
string[BLOCK_SIZE * i + j] = block[j][i];
588+
}
589+
}
590+
591+
return;
592+
}
593+
568594
// this function prints the array
569595
void printArray(unsigned int array[][BLOCK_SIZE]){
570596
int i, j; // counters for the loops

aes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ int hexCharToDec(char);
2727
void get2Bytes(unsigned int, unsigned int *, unsigned int *);
2828
void getRoundKey(unsigned int [], unsigned int [][BLOCK_SIZE], int);
2929
unsigned int gfMul(unsigned int, unsigned int);
30+
void convertStringToBlock(char [], unsigned int [][BLOCK_SIZE]);
31+
void convertBlockToString(unsigned int [][BLOCK_SIZE], char []);
3032

3133
void printArray(unsigned int [][BLOCK_SIZE]);
3234

main.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int main(){
88
unsigned char plainText[BYTES+1]; // plaintext
99
unsigned char cipherText[BYTES+1]; // ciphertext
1010
unsigned char key[BYTES+1]; // encryption key
11-
unsigned char output[BYTES+1]; // strign to prints the results
11+
unsigned char output[BYTES+1]; // string to prints the results
1212

1313
int answer; // user answer
1414

@@ -38,8 +38,8 @@ int main(){
3838
readInput(key);
3939

4040
// convert plaintext and key to 4x4 blocks
41-
convertStringTo4x4Block(plainText, state4x4);
42-
convertStringTo4x4Block(key, key4x4);
41+
convertStringToBlock(plainText, state4x4);
42+
convertStringToBlock(key, key4x4);
4343

4444
// we calculate all round keys 1-10
4545
key_schedule(w, key4x4);
@@ -48,7 +48,7 @@ int main(){
4848
encryption(state4x4, w);
4949

5050
// print the output to user as string
51-
convert4x4BlockToString(state4x4, output);
51+
convertBlockToString(state4x4, output);
5252
output[BYTES] = '\0';
5353
printf("Ciphertext: %s", output);
5454
break;
@@ -63,8 +63,8 @@ int main(){
6363
readInput(key);
6464

6565
// convert ciphertext and key to 4x4 blocks
66-
convertStringTo4x4Block(cipherText, state4x4);
67-
convertStringTo4x4Block(key, key4x4);
66+
convertStringToBlock(cipherText, state4x4);
67+
convertStringToBlock(key, key4x4);
6868

6969
// we calculate all round keys 1-10
7070
key_schedule(w, key4x4);
@@ -73,7 +73,7 @@ int main(){
7373
decryption(state4x4, w);
7474

7575
// print the output to user as string
76-
convert4x4BlockToString(state4x4, output);
76+
convertBlockToString(state4x4, output);
7777
output[BYTES] = '\0';
7878
printf("Plaintext: %s", output);
7979
break;
@@ -88,18 +88,18 @@ int main(){
8888
readInput(key);
8989

9090
// convert plaintext and key to 4x4 blocks
91-
convertStringTo4x4Block(plainText, state4x4);
92-
convertStringTo4x4Block(key, key4x4);
91+
convertStringToBlock(plainText, state4x4);
92+
convertStringToBlock(key, key4x4);
9393

9494
// we calculate all round keys 1-10
9595
key_schedule(w, key4x4);
9696

97-
printf("ENCRYPTION\n");
97+
printf("\nENCRYPTION\n");
9898
// encrypt the plaintext
9999
encryption(state4x4, w);
100100

101101
// print the output to user as string
102-
convert4x4BlockToString(state4x4, output);
102+
convertBlockToString(state4x4, output);
103103
output[BYTES] = '\0';
104104
printf("Ciphertext: %s\n", output);
105105
printf("END OF ENCRYPTION\n");
@@ -109,7 +109,7 @@ int main(){
109109
decryption(state4x4, w);
110110

111111
// print the output to user as string
112-
convert4x4BlockToString(state4x4, output);
112+
convertBlockToString(state4x4, output);
113113
output[BYTES] = '\0';
114114
printf("Plaintext: %s\n", output);
115115
printf("END OF DECRYPTION\n");

read.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "aes.h"
55

66
void readInput(char []);
7-
void convertStringTo4x4Block(char [], unsigned int [][BLOCK_SIZE]);
8-
void convert4x4BlockToString(unsigned int [][BLOCK_SIZE], char []);
97

108
// this function reads the user input
119
void readInput(char input[BYTES+1]){
@@ -25,29 +23,3 @@ void readInput(char input[BYTES+1]){
2523

2624
return;
2725
}
28-
29-
// this function converts string to unsigned int array 4x4
30-
void convertStringTo4x4Block(char string[BYTES+1], unsigned int block[][BLOCK_SIZE]){
31-
int i, j; // counter for loops
32-
33-
for(i = 0; i < BLOCK_SIZE; i++){
34-
for(j = 0; j < BLOCK_SIZE; j++){
35-
block[j][i] = string[BLOCK_SIZE * i + j];
36-
}
37-
}
38-
39-
return;
40-
}
41-
42-
// this function converts unsigned int array 4x4 to string
43-
void convert4x4BlockToString(unsigned int block[][BLOCK_SIZE], char string[BYTES+1]){
44-
int i, j; // counter for loops
45-
46-
for(i = 0; i < BLOCK_SIZE; i++){
47-
for(j = 0; j < BLOCK_SIZE; j++){
48-
string[BLOCK_SIZE * i + j] = block[j][i];
49-
}
50-
}
51-
52-
return;
53-
}

0 commit comments

Comments
 (0)