Last active
May 29, 2017 19:35
-
-
Save idimiter/4747f1186e7a3788a6c52e5ebdb94299 to your computer and use it in GitHub Desktop.
Basic Public/Private key example in C
This file contains hidden or 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> | |
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