Can someone please help me with this assignment:
1. In cryptography, one of the simplest ciphers is known as a mono-alphabetic shift cipher. In this cipher, each time a letter appears in the original message (called the plaintext), it is replaced by a unique letter from the substitution alphabet, in which the letters are shifted to the right by a certain number of positions. For example, the alphabet may be shifted by 6 positions:
Original alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Substitution alphabet: GHIJKLMNOPQRSTUVWXYZABCDEF
The resulting message is called the cipher text. To make things more difficult for an
eavesdropper, punctuation is removed and the cipher text is written in groups of five letters (to
hide the spaces that indicate individual words). Write a program that will take its input (until
EOF), remove all non-letters, and then print the cipher text equivalent using the above alphabets.
Example:
Enter the message: I came, I saw, I Conquered !,
Oigsk OygcO Iutwa kxkj
Make sure the ’shift’ amount is handled as a symbolic constant, so the encryption scheme can be easily changed. Note that the shift works separately for the upper and the lower case alphabets.
Here's my code thus far:
The problem is that when I type in the statement "I came, I saw, I conquered!" I get multiple spaces between every five characters when I only want one space. It has to do with taking newline into account. Can someone tell me how to make my program recognize newline and make it so it doesn't put multiple spaces between every five characters?Code:#include <stdio.h> main() { int c, d, count=0; printf("Enter the Message:"); do{ c = getchar(); if (( c >= 'u' && c <='z' ) || ( c >= 'U' && c <= 'Z')) {d = c-20; putchar(d); count++;} else if (( c >= 'a' && c <= 't' ) || ( c >= 'A' && c <= 'T' )) {d = c+6; putchar(d); count++;} if ((count%5)==0) printf(" "); } while (c != EOF); /* ^D is EOF*/ return 0; }



LinkBack URL
About LinkBacks


