Created
October 6, 2011 10:32
-
-
Save inactive123/1267085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define caesar(x) rot(13, x) | |
#define decaesar(x) rot(13, x) | |
#define decrypt_rot(x, y) rot((26-x), y) | |
void rot(int c, char *str) | |
{ | |
int l = strlen(str); | |
char alpha[2][27] = { "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; | |
int i; | |
for (i = 0; i < l; i++) | |
{ | |
if (!isalpha(str[i]) || (str[i] == ' ')) | |
continue; | |
str[i] = alpha[isupper(str[i])][((int)(tolower(str[i])-'a')+c)%26]; | |
} | |
} | |
int main() | |
{ | |
char str[100] = "This is a top secret text message!"; | |
printf("Original: %s\n", str); | |
caesar(str); | |
printf("Encrypted: %s\n", str); | |
decaesar(str); | |
printf("Decrypted: %s\n", str); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment