forked from jye-hollier/proj1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskFour.c
32 lines (24 loc) · 854 Bytes
/
taskFour.c
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
void taskFour(void) {
char originalText[1000];
char key[26];
printf("\nPlease enter text to be decrypted:\n");
scanf (" %[^\n]%*c", originalText);
printf("\nPlease enter the encryption key used in capitals:\n(E.g.: QWERTYUIOPASDFGHJKLZXCVBNM)\n");
scanf(" %[^\n]%*c", key);
int stringLength = strlen(originalText);
char decryptedText[stringLength];
int i;
int c;
for (i = 0; i < stringLength + 1; i++) {
if (originalText[i] > 64 && originalText[i] < 91) {
for (c = 0; c < 26; c++) {
if (originalText[i] == key[c]) {
decryptedText[i] = c + 65;
}
}
}
else
decryptedText[i] = originalText[i];
}
printf("\nDecrypted text:\n%s", decryptedText);
}