Skip to content

Instantly share code, notes, and snippets.

@theideasmith
Created February 24, 2015 23:24
Show Gist options
  • Save theideasmith/39c4f495428c22577eb5 to your computer and use it in GitHub Desktop.
Save theideasmith/39c4f495428c22577eb5 to your computer and use it in GitHub Desktop.
Simple encryption and decryption in C that I once made.
#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