forked from andrewkiluk/RSA-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
47 lines (40 loc) · 1.2 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include "rsa.h"
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
struct public_key_class pub[1];
struct private_key_class priv[1];
rsa_gen_keys(pub, priv, PRIME_SOURCE_FILE);
printf("Private Key:\n Modulus: %lld\n Exponent: %lld\n", (long long)priv->modulus, (long long) priv->exponent);
printf("Public Key:\n Modulus: %lld\n Exponent: %lld\n", (long long)pub->modulus, (long long) pub->exponent);
char message[] = "123abc";
int i;
printf("Original:\n");
for(i=0; i < strlen(message); i++){
printf("%lld\n", (long long)message[i]);
}
long long *encrypted = rsa_encrypt(message, sizeof(message), pub);
if (!encrypted){
fprintf(stderr, "Error in encryption!\n");
return 1;
}
printf("Encrypted:\n");
for(i=0; i < strlen(message); i++){
printf("%lld\n", (long long)encrypted[i]);
}
char *decrypted = rsa_decrypt(encrypted, 8*sizeof(message), priv);
if (!decrypted){
fprintf(stderr, "Error in decryption!\n");
return 1;
}
printf("Decrypted:\n");
for(i=0; i < strlen(message); i++){
printf("%lld\n", (long long)decrypted[i]);
}
printf("\n");
free(encrypted);
free(decrypted);
return 0;
}