Advertisement
avr39ripe

cVizhinerCipher

Mar 3rd, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. const int alphaLength = 26;
  4.  
  5. char* vizhiner(char* str, const char* key, int mode)
  6. {
  7.     char* origStr = str ;
  8.     size_t keyLength = strlen(key);
  9.     int keyPos = 0;
  10.     while (*str)
  11.     {
  12.         *str++ = ('A' + (*str + (mode ? *(key + keyPos++) : alphaLength - *(key + keyPos++))) % alphaLength);
  13.         keyPos %= keyLength;
  14.     }
  15.     return origStr;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21.     char str[] = {"ATTACKATDAWN" };
  22.     char key[] = { "LEMON" };
  23.     printf("Original:\t%s\n", str);
  24.     printf("Encoded:\t%s\n", vizhiner(str, key, 1));
  25.     printf("Decoded:\t%s\n", vizhiner(str, key, 0));
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement