Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void encode ( char[]);
- convert ( char[], char[], char );
- int main( void )
- {
- int counter, counter2, counter3;
- char alphabet [27] = {'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'};
- char cipher [53] = {0};
- char keyword [27] = {0};
- scanf ( "%s", keyword );
- ;
- char inputText[ 256 ] = { '\0' };
- scanf( "%s", inputText );
- encode ( keyword );
- /* Changes charcters to upper case */
- for (counter = 0; keyword[counter] != '\0'; counter++)
- { keyword[counter] -= 32; }
- /* puts the keyword into the cipher array*/
- for ( counter = 0; keyword [counter] != '\0'; counter++ )
- { cipher [counter] = keyword [counter]; }
- for ( counter2 = 0; alphabet [counter2] != '\0'; counter2++)
- { cipher [counter] = alphabet [counter2];
- ++counter; }
- encode ( cipher );
- for ( counter = 0; inputText[counter] != '\0'; counter++ )
- {
- printf( "%c", convert( alphabet, cipher, inputText [counter] ) );
- }
- }
- void encode ( char keyword[] )
- {
- int counter, counter2;
- char keyword2 [27] = {0};
- /* Overwrites duplicate letters with spaces*/
- for (counter2 = 0; keyword [counter2] !='\0'; counter2++)
- {
- for (counter = 0; keyword [counter] !='\0'; counter++)
- {
- if ( (keyword [counter2] == keyword [counter]) && ( counter != counter2 ) )
- { keyword [counter] = ' '; }}}
- /* Makes a new array to remove spaces between letters*/
- counter2 = 0;
- for ( counter = 0; keyword [counter] !='\0'; counter++ )
- {
- if ( keyword [counter] != ' ' )
- { keyword2 [counter2] = keyword [counter];
- counter2++; }
- }
- sprintf ( keyword, "%s", keyword2 );
- }
- convert ( char alphabet[], char cipher[], char inputText )
- {
- int counter;
- char retchar;
- for (counter = 0; alphabet [counter] != '\0'; counter++ )
- {
- if (inputText == alphabet [counter])
- {retchar = cipher [counter];
- return retchar;}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement