From 1c34256f21fb04190e91f648fb7f170be61c47eb Mon Sep 17 00:00:00 2001 From: SpaceOddity404 <40719093+SpaceOddity404@users.noreply.github.com> Date: Mon, 11 Nov 2019 22:13:56 -0500 Subject: Update RSA.py --- final/RSA.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/final/RSA.py b/final/RSA.py index c12e94f..82a3211 100644 --- a/final/RSA.py +++ b/final/RSA.py @@ -1,4 +1,5 @@ import random +from math import gcd as bltin_gcd def isPrime(x): pr = True for j in range(2, x): @@ -9,25 +10,33 @@ def remove_char(input_string, index): first_part = input_string[:index] second_part - input_string[index+1:] return first_part + second_part +def coprime(a, b): + return bltin_gcd(a, b) == 1 + primes = [i for i in range(2,1000) if isPrime(i)] p = random.choice(primes) q = random.choice(primes) n = p * q -print(n) +coprimes = [j for j in range(2,n) if coprime(j, ((p-1)*(q-1)))] +e = random.choice(coprimes) string = input() sepChars = list(string) numChars = 0 + for c in sepChars: numChars += ((128**sepChars.index(c))*ord(c)) -print(numChars) -blocks = [] +print("numChars:",numChars) c = 0 -for j in range(0, n-1): - blocks.append(str(numChars)[j:j+1]) -for j in range(n-1, len(str(numChars))): - blocks[(len(str(n))-1)%j] = blocks[(len(str(n))-1)%j] + str(numChars)[j:j+1] +blocks = [] -print(blocks) - +while numChars > 0: + blocks.append(numChars%n) + numChars = (numChars-numChars%n)/n + +print("Blocks:",blocks) +encryptedBlocks = [] +for b in blocks: + encryptedBlocks.append((b**e)%n) +print("Encrypted:",encryptedBlocks) -- cgit 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-decrypt.py | 29 +++++++++++++++++++++++++++++ final/rsa-encrypt.py | 22 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 final/rsa-decrypt.py create mode 100644 final/rsa-encrypt.py diff --git a/final/rsa-decrypt.py b/final/rsa-decrypt.py new file mode 100644 index 0000000..335ed68 --- /dev/null +++ b/final/rsa-decrypt.py @@ -0,0 +1,29 @@ +encrypted = [405, 35, 133, 371, 435, 279] # Directly from demo output of encrypted +p = 29 +q = 17 +n = p*q +tot = (p-1)*(q-1) +e = 3 + +# 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 = 0 +for block in decrypted: + messagenum += block + messagenum *= n + +message = '' +while messagenum > 0: + message += chr(messagenum%128) + messagenum = (messagenum-messagenum%128)//128 + +print(message) 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-decrypt.py | 8 ++++---- final/rsa-encrypt.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/final/rsa-decrypt.py b/final/rsa-decrypt.py index 335ed68..d05b351 100644 --- a/final/rsa-decrypt.py +++ b/final/rsa-decrypt.py @@ -17,13 +17,13 @@ def decrypt_block(blk): decrypted = [decrypt_block(block) for block in encrypted] messagenum = 0 -for block in decrypted: - messagenum += block - messagenum *= n +for blockind in range(len(decrypted)): + block = decrypted[blockind] + messagenum += block * n ** blockind message = '' while messagenum > 0: - message += chr(messagenum%128) + message = chr(messagenum%128) + message messagenum = (messagenum-messagenum%128)//128 print(message) 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 a5f3ad2f4df8653c04096e5fb224a777bae74010 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 23:05:59 -0500 Subject: minor appendix update --- final/appendix.tex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/final/appendix.tex b/final/appendix.tex index 2dc9741..06cc36a 100644 --- a/final/appendix.tex +++ b/final/appendix.tex @@ -1,9 +1,10 @@ -These programs, {\tt rsa.py} and {\tt bridges.py} need to be run with Python3, so install that as suggested by \link{https://www.python.org/downloads/}. +These programs, need to be run with Python3, so install that as suggested by \link{https://www.python.org/downloads/}. The package manager {\tt pip} is also necessary for installation of third party graphics libraries such as {\tt NetworkX}. Install that as described here: \link{https://pip.pypa.io/en/stable\-/installing/}. Now that those tools are available, run the following shell commands to install relevant libraries: {\tt\obeylines\parindent=1in \$ pip install networkx +\$ pip install numpy } -Each file should be executable with ``{\tt python3 \$filename}''. +Each file should be executable with ``{\tt python3 \$filename}'', preferably in its local directory. -- 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-decrypt.py | 8 ++++---- final/rsa-encrypt.py | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/final/rsa-decrypt.py b/final/rsa-decrypt.py index d05b351..39a2720 100644 --- a/final/rsa-decrypt.py +++ b/final/rsa-decrypt.py @@ -1,9 +1,9 @@ -encrypted = [405, 35, 133, 371, 435, 279] # Directly from demo output of encrypted -p = 29 -q = 17 +encrypted = [340, 316, 145, 278, 250, 435, 321, 109, 115, 490, 156, 212, 122, 288, 287, 164, 225] # Directly from demo output of encrypted +p = int(input('prime 1: ')) +q = int(input('prime 2: ')) n = p*q tot = (p-1)*(q-1) -e = 3 +e = int(input('e: ')) # Calculate d such that ed == 1 mod tot d = 1 # Guess 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 From 629d46992fccb4d03d07505b5f17f238fec32a5a Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 23:23:00 -0500 Subject: improved instructions --- final/appendix.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/final/appendix.tex b/final/appendix.tex index 06cc36a..f67d2d6 100644 --- a/final/appendix.tex +++ b/final/appendix.tex @@ -7,4 +7,4 @@ Now that those tools are available, run the following shell commands to install \$ pip install numpy } -Each file should be executable with ``{\tt python3 \$filename}'', preferably in its local directory. +Each file should be executable with ``{\tt python3 \$filename}'', preferably in its local directory. The files can be obtained from the internet with ``{\tt git clone https://github.com/feynmansfedora/appcomb-proj.git}'', assuming {\tt git} is installed. If it is not, it can be cloned from \link{https://github.com/feynmansfedora/appcomb-proj} directly. -- cgit From 71bf935debd3a13265fcbc3eb6a3ecc4bf1186aa Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 23:33:03 -0500 Subject: defined totient --- final/rsa-method.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/final/rsa-method.tex b/final/rsa-method.tex index bf75cd0..af2c15a 100644 --- a/final/rsa-method.tex +++ b/final/rsa-method.tex @@ -6,7 +6,7 @@ The encryption process begins with the selection of two large primes, $p$ and $q \pre{2.} Break the converted message into blocks of size less than $n$. \pre{3.} For each block B, an encrypted block C is created such that $$C \equiv B^e\thinspace(mod\thinspace n)$$. \noindent To decrypt that message: -\pre{1.} Calculate an integer $d$ such that $de \equiv 1 \mod{\phi(n)}$ using the Euclidean algorithm. +\pre{1.} Calculate an integer $d$ such that $de \equiv 1 \mod{\phi(n)}$ using the Euclidean algorithm. Note that $\phi(n)$ is the totient function, or the number of non-coprime integers with $n$ less than $n$. \pre{2.} Convert back using $B \equiv C^d \mod{n}$. The decryption process described above makes use of Euler’s theorem. -- cgit From ae29e0a69c85d1efc2a13779ad959287acb40af0 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 23:36:41 -0500 Subject: added citation --- final/rsa-method.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/final/rsa-method.tex b/final/rsa-method.tex index af2c15a..69bf4b1 100644 --- a/final/rsa-method.tex +++ b/final/rsa-method.tex @@ -1,4 +1,4 @@ -The encryption process begins with the selection of two large primes, $p$ and $q$, their product $n=pq$, and a fourth number $e$ relatively prime to $\phi(n)$. $n$ is public, whereas $p$ and $q$ are secret. +The encryption process begins with the selection of two large primes, $p$ and $q$, their product $n=pq$, and a fourth number $e$ relatively prime to $\phi(n)$. $n$ is public, whereas $p$ and $q$ are secret.\footnote{$^3$}{\link{https://primes.utm.edu/glossary/page.php?sort=RSA}} \def\mod#1{\thinspace(mod\thinspace #1)} \noindent Encryption is accomplished through the following three steps: -- cgit From 0c0eb404aa3c241930d72eaf2ebe94e98fe71f12 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 23:36:53 -0500 Subject: pdf archive --- final/final.pdf | Bin 78363 -> 111456 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/final/final.pdf b/final/final.pdf index 707ee6e..889c90f 100644 Binary files a/final/final.pdf and b/final/final.pdf differ -- cgit From c8e69070fbd09863b563730630e7f60fe44d7dac Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 11 Nov 2019 23:39:19 -0500 Subject: removed note-to-self --- final/networks.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/final/networks.tex b/final/networks.tex index 9f6a9e6..710b84e 100644 --- a/final/networks.tex +++ b/final/networks.tex @@ -1,6 +1,6 @@ Distributed networking describes a number of protocols, systems, and technologies. The most popular amongst them is ``the internet,'' to the extent it can be described as a single entity. -It originates in very centralized institutions: MIT and DARPA, who invented packet switching, a way of transferring data across a group of nodes [POTENTIAL SUBTOPIC?]\footnote{$^1$}{\link{https://networkencyclopedia.com/packet-switching/}}\footnote{$^2$}{\link{https://www.internetsociety.org/internet/history-internet/brief-history-internet/}}. +It originates in very centralized institutions: MIT and DARPA, who invented packet switching, a way of transferring data across a group of nodes \footnote{$^1$}{\link{https://networkencyclopedia.com/packet-switching/}}\footnote{$^2$}{\link{https://www.internetsociety.org/internet/history-internet/brief-history-internet/}}. Packet switching was the birth of the internet, and as such is a central theme of our project. The way that packets (any information transferred across any protocol) maintain their correctness, or proving that the data is untampered, and the way that computers connect to eachother will be explored in this paper. -- cgit