aboutsummaryrefslogtreecommitdiff
path: root/final/rsa-decrypt.py
blob: 3bc0a06a1f5d783372c48a152e3665b61ce6a27f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import rsautils as ru
p = int(input('prime 1: '))
q = int(input('prime 2: '))
n = p*q
encrypted = ru.int2list(ru.base642int(input('encrypted message:\n')),n)
tot = (p-1)*(q-1)
e = int(input('e: '))

# Calculate d such that ed == 1 mod tot
d = 1 # Guess
while (e*d % tot != 1):
  d += 1
# Algorithm is currently extremely dumb

def decrypt_block(blk):
  return blk**d % n

decrypted = [decrypt_block(block) for block in encrypted]
messagenum = ru.list2int(decrypted,n,endian="big")
message = ru.int2string(messagenum)

print(message)