forked from shivaylamba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshamirSharing.py
58 lines (44 loc) · 1.05 KB
/
shamirSharing.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
import random
import functools
import operator
import math
arr = list(map(int, input().split()))
points = []
print(arr)
while arr:
n = arr[0]
r = random.randint(1,256)
# eq: f(x) = n + r*x
print("eq : f(x) = {} + {}x".format(n,r))
pointsArr = []
for i in range(1, 5):
f = ( n + (r*i) )
p = (i, f)
pointsArr.append(p)
points.append(pointsArr)
arr.pop(0)
print(points)
print(arr)
while points:
a = points[0]
p = random.sample(a,2)
d = {}
X = {}
Y = {}
for i in range(2):
d["p{}".format(i)] = p[i]
X["x{}".format(i)] = d["p{}".format(i)][0]
Y["y{}".format(i)] = d["p{}".format(i)][1]
r = 0
prod = functools.reduce(operator.mul, X.values(), 1)
for i in range(2):
s = Y["y{}".format(i)] * ((-(prod/X["x{}".format(i)]))/(X["x{}".format(i)] - (sum(X.values())-X["x{}".format(i)])))
r += math.ceil(s)
print(p)
print(d)
print(X)
print(Y)
arr.append(r)
points.pop(0)
print(points)
print(arr)