Advertisement
93aef0ce4dd141ece6f5

substitution cipher

Feb 1st, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4. #include <limits.h>
  5.  
  6. #define ALPHABET 26
  7.  
  8. char encode (int, const char *);
  9. void test_encode (void);
  10.  
  11. int main (int argc, char *argv[]) {
  12.     test_encode();
  13.  
  14.     printf ("Test passed\n");
  15.  
  16.     char permutation[ALPHABET];
  17.  
  18.     int plain_char = getchar();
  19.     while (plain_char != EOF) {
  20.         int encoded_char = encode (plain_char, permutation);
  21.         putchar (encoded_char);
  22.         plain_char = getchar();
  23.     }
  24.  
  25.     return EXIT_SUCCESS;
  26. }
  27.  
  28. void test_encode (void) {
  29.     int i;
  30.     for (i = 0; i < CHAR_MAX; i++) {
  31.         assert (encode ((char)i,"abcdefghijklmnopqrstuvwxyz") == (char)i);
  32.     }
  33.    
  34.     assert (encode ('a',"bcdefghijklmnopqrstuvwxyza") == 'b');
  35.     assert (encode ('m',"bcdefghijklmnopqrstuvwxyza") == 'n');
  36.     assert (encode ('z',"bcdefghijklmnopqrstuvwxyza") == 'a');
  37.  
  38.     assert (encode ('a',"qwertyuiopasdfghjklzxcvbnm") == 'q');
  39.     assert (encode ('b',"qwertyuiopasdfghjklzxcvbnm") == 'w');
  40.     assert (encode ('z',"qwertyuiopasdfghjklzxcvbnm") == 'm');
  41. }
  42.  
  43. char encode (int plain_char, const char *permutation) {
  44.     //todo
  45.     // only need lowercase
  46.  
  47.     return plain_char;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement