-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generator.py
87 lines (81 loc) · 1.39 KB
/
Generator.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
os.system("python seed.py")
fo=open("cleaned.txt","r")
n=fo.readline()
fo.close()
le = len(n)
i=40
j=0
arr=[]
while i<le:
arr.append(long(n[j:i]))
j=i+1
i+=40
arr.append(long(n[j:le]))
def fast_power(a,n,m):
result = 1
value = a%m
power = n
while power > 0:
if power % 2 == 1:
result = (result * value)%m
value = (value * value)%m
power = power/2
return result%m
def fermat(x):
for a in arr:
if not fast_power(a,x-1,x)==1:
return False
return True
fo = open("cleaned.txt","r")
s=fo.readline()
fo.close()
n = long(s[:50])
n1 = long(s[-50:])
a=n%6
n=n+(5-a)
a=n1%6
n1=n1+(5-a)
while True:
a = fermat(n)
if a:
p1=n
break
n+=2
a = fermat(n)
if a:
p1=n
break
n+=4
while True:
a = fermat(n1)
if a:
p2=n1
break
n1+=2
a = fermat(n1)
if a:
p2=n1
break
n1+=4
"""fo=open("primem.txt","a")
fo.write(str(p1)+"\n"+str(p2))
fo.close()"""
m=p1*p2
fo = open("final.txt","r")
r=long(fo.readline())
#r=long(raw_input())
fo.close()
fo=open("finalm.txt","w")
fo.close()
i=1L
print "Enter the number of random number to be generated"
ma = long(raw_input())
while i<=ma:
r=(r*r)%m
fo=open("finalm.txt","a")
fo.write(str(r)+"\n")
fo.close()
i+=1
os.system('rm cleaned.txt')
os.system('rm final.txt')