Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64
- import math
- def isPrime(n):
- d = 2
- while n % d != 0:
- d += 1
- return d == n
- #
- print("print P")
- while True:
- p = int(input())
- if isPrime(p):
- print("P is prime")
- break
- else:
- print("P is not prime")
- print("print Q")
- while True:
- q = int(input())
- if isPrime(q):
- print("Q is prime")
- break
- else:
- print("Q is not prime")
- n=p*q
- phi=(q-1)*(p-1)
- e= 7
- # def egcd(a, b):
- # if a == 0:
- # return (b, 0, 1)
- # else:
- # g, x, y = egcd(b % a, a)
- # return (g, y - (b // a) * x, x)
- #
- #
- # def mulinv(b, n):
- # g, x, _ = egcd(b, n)
- # if g == 1:
- # return x % n
- d = 531
- for i in range(1000):
- if i*e%phi==1:
- d = i
- break
- print("Write a message")
- message=input()
- message_symbols = []
- private_symbols=[]
- decoded_message = []
- for s in message:
- message_symbols.append(ord(s))
- for o in message_symbols:
- l = o**e%n
- b = str(l).encode("UTF-8")
- private_symbols.append(b)
- print(private_symbols)
- for r in private_symbols:
- b = int(r.decode())
- l = b**d%n
- decoded_message.append(chr(l))
- print(f"Decoded message: {''.join(decoded_message)}")
Add Comment
Please, Sign In to add comment