From aeba2c99e4b043bf5201c9af8a295ff9c51e69a3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 15 Jan 2021 23:19:02 +0530 Subject: [PATCH] adds diffie hellman --- diffie-hellman/discrete-log-brute-force.py | 6 ++-- notebooks/3-symmetric-key-ciphers.ipynb | 34 +++++++++---------- ...cs-cryptography-algebraic-structures.ipynb | 2 +- requirements.txt | 2 ++ rsa/rsa_sample.py | 9 ++--- test.py | 4 +-- 6 files changed, 30 insertions(+), 27 deletions(-) diff --git a/diffie-hellman/discrete-log-brute-force.py b/diffie-hellman/discrete-log-brute-force.py index 2c8750e..a718e1f 100644 --- a/diffie-hellman/discrete-log-brute-force.py +++ b/diffie-hellman/discrete-log-brute-force.py @@ -6,7 +6,7 @@ b = 7 m = 9 -# table = pandas.DataFrame(discrete_log_table(7)) -# print(table) +table = pandas.DataFrame(discrete_log_table(7)) +print(table) -print(discrete_log(9, 2, 11)) +# print(discrete_log(9, 2, 11)) diff --git a/notebooks/3-symmetric-key-ciphers.ipynb b/notebooks/3-symmetric-key-ciphers.ipynb index ef5b056..ab1674d 100644 --- a/notebooks/3-symmetric-key-ciphers.ipynb +++ b/notebooks/3-symmetric-key-ciphers.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -100,7 +100,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -110,7 +110,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -147,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -357,7 +357,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -426,14 +426,14 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "ECGQBX\n" + "NTUBQGBPIZCFOPVEVIVNST\n" ] } ], @@ -446,25 +446,25 @@ " ['z', 'y', 'w', 't', 'p']]\n", ")\n", "\n", - "ciphertext = playfair_cipher.encrypt('hello')\n", + "ciphertext = playfair_cipher.encrypt('iwillattacktomorrow')\n", "print(ciphertext)" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "helmlo\n" + "iwilmlatutacktomorsrow\n" ] } ], "source": [ - "plaintext = playfair_cipher.decrypt('ECGQBX')\n", + "plaintext = playfair_cipher.decrypt('NTUBQGBPIZCFOPVEVIVNST')\n", "print(plaintext)" ] }, @@ -478,7 +478,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -506,7 +506,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -525,7 +525,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -1198,7 +1198,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/notebooks/4-mathematics-cryptography-algebraic-structures.ipynb b/notebooks/4-mathematics-cryptography-algebraic-structures.ipynb index c396dd6..d735204 100644 --- a/notebooks/4-mathematics-cryptography-algebraic-structures.ipynb +++ b/notebooks/4-mathematics-cryptography-algebraic-structures.ipynb @@ -374,7 +374,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/requirements.txt b/requirements.txt index 5da331c..817901a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ numpy pandas +matplotlib +opencv-python diff --git a/rsa/rsa_sample.py b/rsa/rsa_sample.py index 13b1e1b..c9af8e7 100644 --- a/rsa/rsa_sample.py +++ b/rsa/rsa_sample.py @@ -2,22 +2,23 @@ import random -p, q = 5, 11 +p, q = 7, 11 n = p * q print('n:', n) phi_n = totient(n) print('totient:', phi_n) phi_n_list = relatively_prime_numbers(phi_n) -print(phi_n_list) +print('relatively prime numbers to phi(n):', phi_n_list) # e = phi_n_list[random.randint(0, len(phi_n_list))] -e = 17 +e = 13 print('e:', e) d = multiplicative_inverse(e, phi_n) print('d:', d) # m = random.randint(0, n) m = 8 -c = pow(m, e, n) +# c = pow(m, e, n) +c = 20 print('plaintext:', m) print('ciphertext:', c) diff --git a/test.py b/test.py index 6faf433..92f82a9 100644 --- a/test.py +++ b/test.py @@ -3,6 +3,6 @@ from ciphers.utils import * import numpy as np import math -import tensorflow -print(tensorflow.version.VERSION) + +print(is_prime(59))