I have this simple program that ciphers text.
Original Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Substitution Alphabet: GHIJKLMNOPQRSTUVWXYZABCDEF
The program works for me but im having trouble editing my output.
For example if I input the following statement:
I came, I saw, I conquered!
My current output is:
O igsk, O ygc, O iutwakxkj!
But I need to find a way to ignore the white space, and all of the punctuation, and then i also need to group the characters into 5.
In other words i need the output to be:
Oigsk OygcO iutwa kxkj
Any tips on how to do this? I just started C programming and this is allready way out of my league!
Can someone also look at my code to see if everything i have down is needed. I just put alot of stuff down, and im not sure if it all needs to be there, but it works :)
Code:
#include <stdio.h>
#include <ctype.h>
#define ESC 27
int main(){ /* function main */
int i; /* declare a variable named i of type int */
char ch = 0; /* declare a variable named ch of type char */
char *alpha = "abcdefghijklmnopqrstuvwxyz"; /* declare a char pointer to the beginning of the alphabet */
char *key = "ghijklmnopqrstuvwxyzabcdef"; /* declare a char pointer to the beginning of the key */
while( ch != ESC ){ /* do the following while the escape character is not present */
ch = fgetc( stdin ); /* store a character entered from standard input into ch */
if( isalpha( ch ) ) { /* do the following if ch is a letter */
for( i = 0 ; i < 26 ; ++i ){ /* for( INIT ; LOOP WHILE THIS IS TRUE ; MANIPULATE ) */
if( alpha[ i ] == tolower( ch ) ){ /* if the character residing at alpha + offset i = ch */
ch = /* we're going to assign something to ch */
( isupper( ch ) ) ? /* is ch uppercase? */
( toupper( key[ i ] ) ) : /* if so assign to ch the upercase version of key at offset i */
key[ i ]; /* otherwise use the already lowercase defualt */
break; /* break because we found it and no longer need to search */
} /* end if block */
} /* end for block */
} /* end of if block */
fputc( ch, stdout ); /* put the character back to standard output */
}
return( 0 ); /* return control to the operating system */
} /* end main block */