Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- #include <limits.h>
- #define ALPHABET 26
- char encode (int, const char *);
- void test_encode (void);
- int main (int argc, char *argv[]) {
- test_encode();
- printf ("Test passed\n");
- char permutation[ALPHABET];
- int plain_char = getchar();
- while (plain_char != EOF) {
- int encoded_char = encode (plain_char, permutation);
- putchar (encoded_char);
- plain_char = getchar();
- }
- return EXIT_SUCCESS;
- }
- void test_encode (void) {
- int i;
- for (i = 0; i < CHAR_MAX; i++) {
- assert (encode ((char)i,"abcdefghijklmnopqrstuvwxyz") == (char)i);
- }
- assert (encode ('a',"bcdefghijklmnopqrstuvwxyza") == 'b');
- assert (encode ('m',"bcdefghijklmnopqrstuvwxyza") == 'n');
- assert (encode ('z',"bcdefghijklmnopqrstuvwxyza") == 'a');
- assert (encode ('a',"qwertyuiopasdfghjklzxcvbnm") == 'q');
- assert (encode ('b',"qwertyuiopasdfghjklzxcvbnm") == 'w');
- assert (encode ('z',"qwertyuiopasdfghjklzxcvbnm") == 'm');
- }
- char encode (int plain_char, const char *permutation) {
- //todo
- // only need lowercase
- return plain_char;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement