-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt_text.c
46 lines (37 loc) · 923 Bytes
/
encrypt_text.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
#include "stdio.h"
#include "stdlib.h"
#define BUZZ_SIZE 1024
unsigned long long int modpow(int base, int power, int mod)
{
int i;
unsigned long long int result = 1;
for (i = 0; i < power; i++)
{
result = (result * base) % mod;
}
return result;
}
int main (int argc, char *argv[])
{
int m, n, e;
unsigned long long int c;
FILE *inp = fopen("public.txt", "r");
fscanf(inp, "%d %d", &n, &e);
fclose(inp);
printf("ciphertext c = ");
int i;
FILE *outp = fopen("ciphertext.txt", "w");
FILE *input = fopen("key.txt", "r");
char key [BUZZ_SIZE];
fscanf(input, "%s",key);
fclose(input);
for (i = 0; key[i] != '\0'; i++)
{
c = modpow(key[i],e,n);
printf("%llu ", c);
fprintf(outp, "%llu\n", c);
}
printf("\n");
fclose(outp);
return 0;
}