Untitled
unknown
plain_text
2 years ago
736 B
11
Indexable
#include <stdio.h>
void encrypte(char current_char, char *key);
int main(int argc, char *argv[])
{
if (argc <= 1 || argc > 2) {
return 0;
}
char *substituted_alphabet = argv[1];
char current_char;
printf("Enter text:\n");
while((current_char = getchar()) != EOF) {
encrypte(current_char, substituted_alphabet);
}
return 0;
}
void encrypte(char current_char, char *key) {
char result_char;
int index = 0;
if (current_char >= 'A' && current_char <= 'Z') {
index = current_char - 'A';
result_char = key[index] - 'a' + 'A';
}
else if(current_char >= 'a' && current_char <= 'z') {
index = current_char - 'a';
result_char = key[index];
}
else {
result_char = current_char;
}
putchar(result_char);
}Editor is loading...
Leave a Comment