-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsa.c
25 lines (23 loc) · 621 Bytes
/
rsa.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
#include <stdio.h>
#include <stdlib.h>
#define E 1547
#define M 91261
#define X 75634
#define ulong unsigned long
// Modular exponentiation, via Wikipedia and Schneier's "Applied Cryptography"
inline ulong expt_mod(ulong b, ulong e, ulong m){
register ulong r = 1;
while (e) {
if (e & 1) r = (r * b) % m;
e >>= 1;
b = (b * b) % m;
}
return r;
}
int main(int argc, char *argv[]) {
register ulong x = argc > 1 ? atol(argv[1]) : X;
register int i = argc > 2 ? atoi(argv[2]) : 10;
while (i--) printf("%lu", (x = expt_mod(x, E, M)) % 2);
printf("\n");
return 0;
}