Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Thu Nov 7 17:41:55 2019
- @author: Rabeles
- """
- import random
- import itertools as it
- import sympy
- import math
- def computeGCD(x, y):
- while(y):
- x, y = y, x % y
- return x
- def modulo_multiplicative_inverse(A, M):
- return fast_power(A, M-2, M)
- def fast_power(base, power, MOD):
- result = 1
- while power > 0:
- # If power is odd
- if power % 2 == 1:
- result = (result * base) % MOD
- # Divide the power by 2
- power = power // 2
- # Multiply base to itself
- base = (base * base) % MOD
- return result
- p = next(i for i in map(lambda x: random.randint(1000000000000000000,9999999999999999999) |1,it.count()) if sympy.isprime(i))
- print(p)
- q = next(i for i in map(lambda x: random.randint(1000000000000000000,9999999999999999999) |1,it.count()) if sympy.isprime(i))
- print(q)
- n = (p*q)
- print(n)
- fí_n = (p-1)*(q-1)
- print("tohle je eulerova fce",fí_n)
- while(True):
- e = random.randint(1,fí_n-1)
- if(computeGCD(e, fí_n) == 1):
- break
- print ("tohle je koef E po GCD",e)
- d = modulo_multiplicative_inverse(e, fí_n)
- print (d)
- print("veřejny klič je (",n,",",e,")")
- print("privátní klič je (",n,",",d,")")
- s = "AHOJ"
- h = ''.join(str(ord(c)) for c in s)
- h = int(h)
- print(h)
- prevodlistu = ""
- for c in s:
- prevod = ord(c)
- x = f'{prevod:011b}'
- prevodlistu += x
- # print(x)
- cisloslovahoj = int(prevodlistu,2)
- print(cisloslovahoj)
- c = fast_power(cisloslovahoj,e,n)
- m = fast_power(c,d,n)
- #print("binárí hodnota je " ,f'{h:011b}')
- #x = f'{h:011b}'
- #x1 = ''.join(str(ord(c)) for c in x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement