Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void encode ( char[]);
  5. convert ( char[], char[], char );
  6.  
  7.  
  8. int main( void )
  9. {
  10. int counter, counter2, counter3;
  11. 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'};
  12. char cipher [53] = {0};
  13. char keyword [27] = {0};
  14.  
  15. scanf ( "%s", keyword );
  16. ;
  17. char inputText[ 256 ] = { '\0' };
  18.  
  19. scanf( "%s", inputText );
  20. encode ( keyword );
  21. /* Changes charcters to upper case */
  22. for (counter = 0; keyword[counter] != '\0'; counter++)
  23. { keyword[counter] -= 32; }
  24. /* puts the keyword into the cipher array*/
  25. for ( counter = 0; keyword [counter] != '\0'; counter++ )
  26. { cipher [counter] = keyword [counter]; }
  27. for ( counter2 = 0; alphabet [counter2] != '\0'; counter2++)
  28. { cipher [counter] = alphabet [counter2];
  29. ++counter; }
  30. encode ( cipher );
  31. for ( counter = 0; inputText[counter] != '\0'; counter++ )
  32. {
  33. printf( "%c", convert( alphabet, cipher, inputText [counter] ) );
  34. }
  35.  
  36.  
  37.  
  38. }
  39.  
  40.  
  41.  
  42.  
  43. void encode ( char keyword[] )
  44. {
  45. int counter, counter2;
  46. char keyword2 [27] = {0};
  47. /* Overwrites duplicate letters with spaces*/
  48.  
  49. for (counter2 = 0; keyword [counter2] !='\0'; counter2++)
  50. {
  51.  
  52. for (counter = 0; keyword [counter] !='\0'; counter++)
  53. {
  54. if ( (keyword [counter2] == keyword [counter]) && ( counter != counter2 ) )
  55. { keyword [counter] = ' '; }}}
  56.  
  57.  
  58.  
  59. /* Makes a new array to remove spaces between letters*/
  60. counter2 = 0;
  61. for ( counter = 0; keyword [counter] !='\0'; counter++ )
  62. {
  63. if ( keyword [counter] != ' ' )
  64. { keyword2 [counter2] = keyword [counter];
  65. counter2++; }
  66. }
  67. sprintf ( keyword, "%s", keyword2 );
  68.  
  69.  
  70. }
  71.  
  72. convert ( char alphabet[], char cipher[], char inputText )
  73. {
  74. int counter;
  75. char retchar;
  76.  
  77.  
  78. for (counter = 0; alphabet [counter] != '\0'; counter++ )
  79. {
  80. if (inputText == alphabet [counter])
  81. {retchar = cipher [counter];
  82. return retchar;}
  83.  
  84.  
  85.  
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement