Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- complexity = int(input())
- inp = input()
- soobsh1 = int(inp)
- def evkl(a, b, x, y):
- if a == 0:
- x = 0
- y = 1
- return (b, (x, y))
- x_tmp = 0.5
- y_tmp = 0.5
- d, (x_tmp, y_tmp) = evkl(b % a, a, x_tmp, y_tmp)
- x = y_tmp - (b // a) * x_tmp
- y = x_tmp
- return (d, (x, y))
- prost = [2]
- for i in range(3, complexity + 1, 2):
- if (i > 10) and (i % 10 == 5):
- continue
- for j in prost:
- if j * j - 1 > i:
- prost.append(i)
- break
- if (i % j == 0):
- break
- else:
- prost.append(i)
- dlin = len(prost)
- fir = prost[random.randint(dlin - 20, dlin) - 1]
- sec = prost[random.randint(dlin - 20, dlin) - 1]
- while fir == sec:
- sec = random.randint(dlin // 2, dlin)
- mod = fir * sec
- counter = 0
- while mod <= soobsh1:
- fir = random.randint(dlin // 2, dlin)
- while fir == sec:
- sec = random.randint(dlin // 2, dlin)
- counter += 1
- if counter == 1000:
- print("Too much information in text. Increase complexity.")
- exit(0)
- fi = (fir - 1) * (sec - 1)
- exp = []
- for i in range(dlin - 1, 0, -1):
- tmp = prost[i]
- if tmp >= fi or math.gcd(fi, tmp) != 1:
- continue
- exp.append(tmp)
- e = exp[random.randint(0, len(exp) - 1)]
- open = [e, mod]
- print("OpenKey =", open)
- tmp1, tmp2, tmp3 = e, fi, 1
- d1, k = 0.5, 0.5
- tmp4, (d1, k) = evkl(tmp1, tmp2, d1, k)
- if tmp3 % (tmp1 * d1 + tmp2 * k) != 0:
- print("wrong e")
- exit(0)
- d = d1 * (tmp3 // (tmp1 * d1 + tmp2 * k))
- d = d + random.randint(1, complexity) * fi
- '''
- d = 1
- while (d * e) % fi != 1:
- d += 1
- d = d + random.randint(1, complexity) * fi
- '''
- hidden = [d, mod]
- print("HiddenKey =", hidden)
- shifred1 = pow(soobsh1, e, mod)
- print("Shifred1 =", shifred1)
- deshifred1 = pow(shifred1, d, mod)
- print("Deshifred1 =", deshifred1)
- print()
- deshifred = deshifred1
- print("Deshifred =", deshifred)
Advertisement
Add Comment
Please, Sign In to add comment