Advertisement
CmdEngineer

Untitled

May 10th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1.  
  2. /*
  3. Function decrypts a cipher with key n. (Flips the word before.)
  4. input: string cipher, int n.
  5. output: none.
  6. */
  7. void decrypt(char* cipher, int n)
  8. {
  9.     int i = 0;
  10.     char newStr[SIZE] = { 0 };
  11.    
  12.     while (*(cipher + i) != '\0')
  13.     {
  14.         // This line is crazy... It gets the i left most char removes 'a' from it adds the key n and module it by 26 and returns the 'a'.
  15.         *(newStr + i) = 'a' + ((*((cipher + (strlen(cipher) - 1)) - i) - 'a' + n) % ABC_SIZE);
  16.         i++;
  17.     }
  18.     strcpy(cipher, newStr);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement