Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #define STR_LEN 50
- void decrypt(char* cipher, int n);
- void strRev(char *str);
- int main(void)
- {
- char str[STR_LEN] = { 0 };
- int decKey = 0;
- printf("Enter cipher to decrypt: ");
- fgets(str, STR_LEN, stdin);
- *(str + strlen(str) - 1) = 0;
- printf("Enter decryption key: ");
- scanf("%d", &decKey);
- decrypt(str, decKey);
- printf("Decrypted text: %s", str);
- system("PAUSE");
- }
- void decrypt(char* cipher, int n)
- {
- int i = 0, j = 0;
- strRev(cipher);
- for (; *cipher; cipher += 1)
- {
- *cipher = (((*cipher - 'a') + n) % 26) + 'a';
- }
- }
- void strRev(char *str)
- {
- char tmp;
- int i = 0, j = 0;
- for (i = strlen(str) - 1, j = 0; i > j; i--, j++)
- {
- tmp = *(str + i);
- *(str + i) = *(str + j);
- *(str + j) = tmp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement