Skip to content

Instantly share code, notes, and snippets.

@harveytoro
Created November 19, 2012 13:37
Show Gist options
  • Save harveytoro/4110690 to your computer and use it in GitHub Desktop.
Save harveytoro/4110690 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char *argv[]) {
int e = 1; // variable part of the Modular exponentiation algorithm.
int charInput = 97; // ASCII value of a
//Public keys
int n = 3233;
int k = 17;
//private keys
int j = 2753;
// Modular exponentiation algorithm http://en.wikipedia.org/wiki/Modular_exponentiation
for (int ei = 0; ei < k; ei++) {
e = ((e * charInput) % n);
}
printf("%i\n", e); //Encryption
/*
Descryption
*/
int d = 1; // variable part of the Modular exponentiation algorithm.
for (int ei = 0; ei < j; ei++) {
d = ((d * e) % n);
}
printf("%i\n", d); //Decryption
} // main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment