diff options
Diffstat (limited to 'final/rsa-encrypt.py')
-rw-r--r-- | final/rsa-encrypt.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/final/rsa-encrypt.py b/final/rsa-encrypt.py new file mode 100644 index 0000000..de9ba1e --- /dev/null +++ b/final/rsa-encrypt.py @@ -0,0 +1,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) |