From 303437435f4b6ec660a8b289055fa190e1028328 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 22:53:52 -0500 Subject: simpler rsa --- final/rsa-encrypt.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 final/rsa-encrypt.py (limited to 'final/rsa-encrypt.py') diff --git a/final/rsa-encrypt.py b/final/rsa-encrypt.py new file mode 100644 index 0000000..05cf562 --- /dev/null +++ b/final/rsa-encrypt.py @@ -0,0 +1,22 @@ +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 + +def encrypt_block(blk): + return (blk ** e) % n + +encrypted = [encrypt_block(block) for block in messageblocks] +print(encrypted) -- cgit From 0ef3d4cde99a8288339338d3ed9285a71c404236 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 23:03:23 -0500 Subject: fixed endianness bugs --- final/rsa-encrypt.py | 1 + 1 file changed, 1 insertion(+) (limited to 'final/rsa-encrypt.py') diff --git a/final/rsa-encrypt.py b/final/rsa-encrypt.py index 05cf562..de9ba1e 100644 --- a/final/rsa-encrypt.py +++ b/final/rsa-encrypt.py @@ -14,6 +14,7 @@ messageblocks = [] while messagenum > 0: messageblocks.append(messagenum%n) messagenum = (messagenum-messagenum%n)//n +print(messageblocks) def encrypt_block(blk): return (blk ** e) % n -- cgit From eb364b5badef4afb4cc1ce370a36fd089aa61cf7 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 23:18:36 -0500 Subject: added user entry (except for the hardcoded encrypted data) --- final/rsa-encrypt.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'final/rsa-encrypt.py') diff --git a/final/rsa-encrypt.py b/final/rsa-encrypt.py index de9ba1e..a15fe9d 100644 --- a/final/rsa-encrypt.py +++ b/final/rsa-encrypt.py @@ -1,10 +1,12 @@ -p = 29 +'''p = 29 q = 17 n = p*q tot = (p-1)*(q-1) -e = 3 # Many present strictly for convenience's sake +e = 3 # Many present strictly for convenience's sake''' +n = int(input('n: ')) +e = int(input('e (make sure it\'s relatively prime to p-1 and q-1): ')) -message = 'abcdef' +message = input('message:\n') messagenum = 0 for char in message: messagenum += ord(char) @@ -14,7 +16,6 @@ messageblocks = [] while messagenum > 0: messageblocks.append(messagenum%n) messagenum = (messagenum-messagenum%n)//n -print(messageblocks) def encrypt_block(blk): return (blk ** e) % n -- cgit