Question: EDIT THE CODE #include #include #include #include lbyec2a.h char encrypt_uppercase_letter(char letter) { /* encrypt_uppercase_letter encrypts the input using the prescribed encrpytion E.g.#1 A -> D
EDIT THE CODE
#include
Input: alphanum (char) = the input character to be encrypted Returns: outchar = character in encrypted form */ if (alphanum >= 'A' && alphanum <= 'Z') { return encrypt_uppercase_letter(alphanum); } else if (alphanum >= 'a' && alphanum <= 'z') { return encrypt_lowercase_letter(alphanum); } else if (alphanum >= '0' && alphanum <= '9') { return encrypt_number(alphanum); } else { return alphanum; } }
void encrypt_message(char message[], int size) { /* encrypt_message would display the message (in encrypted form) using encrypt_alphanumeric so that no one else could understand the message.
Input: message[] (char) = the message that needs encryption size (int) = the size of the given message (which is an array) Returns: None */ int i = 0;
for (i = 0; i < size; i++) { printf("%c", encrypt_alphanumeric(message[i])); } }
int main(void) {
char phrase[100]; int length; printf("Phrase: "); scanf(" %[^ ]s", phrase); //Get string with whitespace
length = strlen(phrase);
encrypt_message(phrase, length);
return 0; }
OUTPUT:
Exercise 2: Message Encryption (lab1_ex2.c)
Create a program that encrypts the message of max. length of 100 by doing the following:
It asks for a message from the user, it should be able to include whitespace characters.
The message shall be encrypted by replacing each character by the character three positions to its right as seen in the ascii table.
The encryption should only work on letters and numbers. Suppose that the character is Z, then it should become C.
The encrypted message shall be displayed to the screen.
| Sample Input | Expected Console Output |
|---|---|
| Hello World!!! | Phrase: Hello World!!! Khoor Zruog!!! |
| Zebra crosSING! | Phrase: Zebra crosSING! Cheud furvVLQJ! |
| f**k you! | Phrase: f**k you! i**n brx! |
| Zebra90 | Phrase: Zebra90 Cheud23 |
Hint:
modulo(remainder) provides you an ability to create "cycles".
example#1: 1 % 26 = 1
example#2: 2 % 26 = 2
example#3: 25 % 26 = 25
example#4: 27 % 26 = 1
example#5: 28 % 26 = 2
example#6: 51 % 26 = 25
Have you found a hidden gem in your repository?
How do you determine if it's not alphanumeric (neither a letter nor a number)? (Hint: either check ctype.h or look at the ASCII table)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
