#include <stdio.h>
#include <ctype.h>
#define ALPHABET_SIZE 26
void encrypt(char plaintext[], char key[]);
void decrypt(char ciphertext[], char key[]);
int main() {
char plaintext[] = "HELLO";
char key[] = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
printf("Original Text: %s\n", plaintext);
encrypt(plaintext, key);
printf("Encrypted Text: %s\n", plaintext);
decrypt(plaintext, key);
printf("Decrypted Text: %s\n", plaintext);
return 0;
}
void encrypt(char plaintext[], char key[]) {
for (int i = 0; plaintext[i] != '\0'; i++) {
if (isalpha(plaintext[i])) {
char base = isupper(plaintext[i]) ? 'A' : 'a';
plaintext[i] = key[plaintext[i] - base];
}
}
}
void decrypt(char ciphertext[], char key[]) {
char inverseKey[ALPHABET_SIZE];
for (int i = 0; i < ALPHABET_SIZE; i++) {
inverseKey[key[i] - 'A'] = 'A' + i;
}
for (int i = 0; ciphertext[i] != '\0'; i++) {
if (isalpha(ciphertext[i])) {
char base = isupper(ciphertext[i]) ? 'A' : 'a';
ciphertext[i] = inverseKey[ciphertext[i] - base];
}
}
}