Skip to content

Commit

Permalink
Testing (#11)
Browse files Browse the repository at this point in the history
* testing

* test rsa

* tests
  • Loading branch information
programmingAthlete committed Oct 25, 2022
1 parent 8c3ca3b commit f75fbb0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = "0.0.1"
__version__ = "0.0.2"

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
Expand Down
Binary file modified src/crypto_pkg/DGHV/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified src/crypto_pkg/DGHV/__pycache__/dghv.cpython-38.pyc
Binary file not shown.
10 changes: 4 additions & 6 deletions src/crypto_pkg/rsa/rsa_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ def encrypt_message(message: str, e: int, n: int):
m = str_to_int(message)
if m < 0 or m > n - 1:
raise MessageTooBigError
c = RSA.encrypt(m=m, e=e, n=n)
return int_to_str(int(c))
return RSA.encrypt(m=m, e=e, n=n)

@staticmethod
def decrypt_message(cipher_text: str, d: int, n: int):
c = str_to_int(cipher_text)
m = RSA.decrypt(c=c, d=d, n=n)
return int_to_str(int(m))
def decrypt_message(cipher_text: int, d: int, n: int):
m = RSA.decrypt(c=cipher_text, d=d, n=n)
return int_to_str(m)

@staticmethod
def encrypt(m, e, n):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_rsa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

from crypto_pkg.rsa.rsa_scheme import RSA


class TestRSA(unittest.TestCase):

def test_rsa(self):
rsa = RSA(k=100)
primes = rsa.generate_primes()
message = 'hello'
keys = rsa.generate_keys(primes.q, primes.p)
c = RSA.encrypt_message(message=message, e=keys.public, n=keys.modulus)
m = RSA.decrypt_message(cipher_text=c, d=keys.private, n=keys.modulus)
self.assertEqual(message, m)

0 comments on commit f75fbb0

Please sign in to comment.