aboutsummaryrefslogtreecommitdiff
path: root/final/rsa-encrypt.py
blob: de9ba1ef34ba407d292641a1815823e05218dd01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
p = 29
q = 17
n = p*q
tot = (p-1)*(q-1)
e = 3 # Many present strictly for convenience's sake

message = 'abcdef'
messagenum = 0
for char in message:
  messagenum += ord(char)
  messagenum *= 128 # Assuming ASCII only characters

messageblocks = []
while messagenum > 0:
  messageblocks.append(messagenum%n)
  messagenum = (messagenum-messagenum%n)//n
print(messageblocks)

def encrypt_block(blk):
  return (blk ** e) % n

encrypted = [encrypt_block(block) for block in messageblocks]
print(encrypted)