Advertisement
avr39ripe

cVizhenerSimple

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