Skip to content

Instantly share code, notes, and snippets.

@idimiter
Last active May 29, 2017 19:35
Show Gist options
  • Save idimiter/4747f1186e7a3788a6c52e5ebdb94299 to your computer and use it in GitHub Desktop.
Save idimiter/4747f1186e7a3788a6c52e5ebdb94299 to your computer and use it in GitHub Desktop.
Basic Public/Private key example in C
#include <stdio.h>
#include <string.h>
const int publicKey = 42;
const int privateKey = 256 - publicKey;
const int m = publicKey + privateKey;
void scramble(char* s, int key) {
for (size_t i = 0; i < strlen(s);i++)
s[i] = (s[i] + key) % m;
}
int main() {
char in[] = "Hello World!";
scramble(in, publicKey);
printf("%s\n", in);
scramble(in, privateKey);
printf("%s\n", in);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment