-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoly.c
38 lines (30 loc) · 913 Bytes
/
poly.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
33
34
35
36
37
38
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define ALPHABET_SIZE 26
void encryptMonoalphabetic(char plaintext[], char key[]) {
int i;
for (i = 0; i < strlen(plaintext); i++) {
if (isalpha(plaintext[i])) {
int index = tolower(plaintext[i]) - 'a';
if (isupper(plaintext[i])) {
plaintext[i] = toupper(key[index]);
} else {
plaintext[i] = tolower(key[index]);
}
}
}
}
int main() {
char plaintext[1000];
char key[ALPHABET_SIZE] = "QWERTYUIOPASDFGHJKLZXCVBNM";
printf("Enter the plaintext: ");
fgets(plaintext, sizeof(plaintext), stdin);
size_t len = strlen(plaintext);
if (len > 0 && plaintext[len - 1] == '\n') {
plaintext[len - 1] = '\0';
}
encryptMonoalphabetic(plaintext, key);
printf("Encrypted text: %s\n", plaintext);
return 0;
}