Created
February 24, 2015 23:24
-
-
Save theideasmith/39c4f495428c22577eb5 to your computer and use it in GitHub Desktop.
Simple encryption and decryption in C that I once made.
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 <string.h> | |
typedef enum { | |
encrypt, | |
decrypt | |
}intent; | |
int main(int argc, const char*argv[]) { | |
intent which = strncmp(argv[2], "e",1) == 0? encrypt : decrypt; | |
int dir = which == decrypt ? -1 : 1; | |
if (argv[1]) { | |
printf("%s%c",(which==decrypt ? "Decrypted string:" : "Encrypted String:"), argv[1][0]); | |
for(int i = 1; i < strlen(argv[1]); i++) { | |
char puts = argv[1][i] + (i * dir); | |
printf("%c",puts); | |
} | |
printf("\n"); | |
} else | |
printf("Error ~ No preferences specified"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment