Skip to content

Commit

Permalink
adds diffie hellman
Browse files Browse the repository at this point in the history
  • Loading branch information
anishLearnsToCode committed Jan 15, 2021
1 parent b9c38e4 commit aeba2c9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
6 changes: 3 additions & 3 deletions diffie-hellman/discrete-log-brute-force.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
34 changes: 17 additions & 17 deletions notebooks/3-symmetric-key-ciphers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -40,7 +40,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -100,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -110,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -147,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -357,7 +357,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -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"
]
}
],
Expand All @@ -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)"
]
},
Expand All @@ -478,7 +478,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -506,7 +506,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -525,7 +525,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1198,7 +1198,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.7.9"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.7.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
numpy
pandas
matplotlib
opencv-python
9 changes: 5 additions & 4 deletions rsa/rsa_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from ciphers.utils import *
import numpy as np
import math
import tensorflow

print(tensorflow.version.VERSION)

print(is_prime(59))

0 comments on commit aeba2c9

Please sign in to comment.