Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code and Decode your secrete message in C language. Type some text message in input.txt, then read the input.txt, shift each alphabet forward by 3

Code and Decode your secrete message in C language.

Type some text message in input.txt, then read the input.txt, shift each alphabet forward by 3 position. The shifted message should be saved in a file output.txt.

*************************************************

The Shifted Alphabet Code is very very easy to do. Begin by writing down the alphabet in order on a piece of paper (or use the one below). A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Now pick a number between 1 and 25. Got it? I picked the number 3. Now, when you write down your coded message, instead of writing the real letter, you find that letter in the alphabet and count forward - as many letters as the number you picked.

So, if my message was "HI, HOW ARE YOU?" I would begin by finding the letter H, then counting forward three letters, to get the letter K. Then, since the next letter is I, find the I and count forward to get the letter L. Keep going through the whole message like that.

Uh oh...what about punctuation (like that question mark at the end of "Hi, HOW ARE YOU?"? Just leave that exactly the way it is. So you need to check first if the character is letter or not. Consider switch statements in C. Uh oh again! what happens when I get to the letter Y? I can't count forward 3 letters, because there aren't enough letters in the alphabet! That's okay...just start over at the beginning, after you count the Z. So Y becomes B! Is this code difficult to decode? In order to decode it, you need to know how many letters the message was shifted in the first place! Of course, if you don't know, it's not impossible...you just have to "unshift" it one letter at a time, until you get a message that makes sense! Do you think people use this code for things they need to keep secret? No, they don't. Because it's too easy to decode. But it's still fun to play with.

Here is the ASCII table for all letters.

https://simple.wikipedia.org/wiki/ASCII (Links to an external site.)

In C programming, a character variable holds ASCII value (an integer number between 0 and 127) rather than that character itself. This integer value is the ASCII code of the character.

For example, the ASCII value of 'A' is 65.

What this means is that, if you assign 'A' to a character variable, 65 is stored in the variable rather than 'A' itself.

Now, let's see how we can shifted a letter by 3 by adding 3 to ASCII value in this example.

#include  int main() { char c; printf("Enter a character: "); scanf("%c", &c); c = c + 3; // %d displays the integer value of a character // %c displays the actual character printf("shifted letter %c has a ASCII value of %d ", c, c); return 0; } 

Output

Enter a character: A shifted letter D has a ASCII value of 68. ******************************************************** Some C program to read and write to file. Read and write file sample: https://repl.it/@zhumi/ReadContentFromFile#main.c ********************************************************* Switch statement to group multiple cases together. You may also choose to use if else statement for the same purposes. 
#include  int main () { /* local variable definition */ char grade = 'B'; switch(grade) { case 'A' : printf("Excellent! " ); break; case 'B' : case 'C' : printf("Well done " ); break; case 'D' : printf("You passed " ); break; case 'F' : printf("Better try again " ); break; default : printf("Invalid grade " ); } printf("Your grade is %c ", grade ); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

ISBN: 1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

Is it appropriate to your goal and audience?

Answered: 1 week ago