From 4a756d023f08f0b2875a001bbdee1f3d37598592 Mon Sep 17 00:00:00 2001 From: programmingAthlete Date: Sat, 23 Dec 2023 17:35:50 +0100 Subject: [PATCH 1/3] deco --- .../power_analysis/correlation_power_analysis.py | 5 +++-- src/crypto_pkg/clis/attacks.py | 2 +- src/crypto_pkg/utils/logging.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/crypto_pkg/attacks/power_analysis/correlation_power_analysis.py b/src/crypto_pkg/attacks/power_analysis/correlation_power_analysis.py index 828e150..024ae8b 100644 --- a/src/crypto_pkg/attacks/power_analysis/correlation_power_analysis.py +++ b/src/crypto_pkg/attacks/power_analysis/correlation_power_analysis.py @@ -10,7 +10,7 @@ import matplotlib.pyplot as plt from crypto_pkg.ciphers.symmetric.aes import sbox_table -from crypto_pkg.utils.logging import get_logger +from crypto_pkg.utils.logging import get_logger, set_level log = get_logger(__name__) @@ -178,8 +178,9 @@ def attack_byte(self, byte_position: int = 0, plot: bool = False, log.info(f"[Process {byte_position}] Process {byte_position} finished") return byte_position, np.unravel_index(np.argmax(c), c.shape)[0] + @set_level(logger=log) def attack_full_key(self, show_plot_correlations: bool = False, store_correlation_matrices: bool = False, - re_calculate_correlation_matrices: bool = True): + re_calculate_correlation_matrices: bool = True, verbose: bool = False): cores = multiprocessing.cpu_count() log.info(f"Number of cores: {cores}. The program wil run in chunks of {cores} byte positions\n") diff --git a/src/crypto_pkg/clis/attacks.py b/src/crypto_pkg/clis/attacks.py index abc32dd..1580405 100644 --- a/src/crypto_pkg/clis/attacks.py +++ b/src/crypto_pkg/clis/attacks.py @@ -203,7 +203,7 @@ def attack_correlation_power_analysis( print(f"Key byte found: {hex(key_byte[1])[2:]}") return key = attack.attack_full_key(store_correlation_matrices=False, re_calculate_correlation_matrices=False, - show_plot_correlations=False) + show_plot_correlations=False, verbose=True) print("Key Found") print(key) os.remove(filename) diff --git a/src/crypto_pkg/utils/logging.py b/src/crypto_pkg/utils/logging.py index da87eb6..42ff69e 100644 --- a/src/crypto_pkg/utils/logging.py +++ b/src/crypto_pkg/utils/logging.py @@ -7,3 +7,14 @@ def get_logger(location: str = __name__): log = logging.getLogger(location) log.setLevel(settings.log_level) return log + + +def set_level(logger): + def deco(func): + def wrapper( *args, **kwargs): + if kwargs.get('verbose') and kwargs.get('verbose') is True: + logger.setLevel(logging.DEBUG) + return func(*args, **kwargs) + return wrapper + + return deco From cc7dda59842f891a6a3c4492807e48d38ea4ffe3 Mon Sep 17 00:00:00 2001 From: programmingAthlete Date: Sat, 23 Dec 2023 21:18:59 +0100 Subject: [PATCH 2/3] DS version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 12e0e0f..be86af8 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -__version__ = "1.4.4" +__version__ = "1.4.5" with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() From a134116104eafea709c8987c5a16ff8d452a5883 Mon Sep 17 00:00:00 2001 From: programmingAthlete Date: Sat, 23 Dec 2023 22:51:26 +0100 Subject: [PATCH 3/3] logger --- Makefile | 16 ++++++++++++++++ README.md | 10 +++++++++- pyproject.toml | 7 +++++-- requirements.txt | 8 ++++---- setup.py | 2 +- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ab9189f..a755fd2 100644 --- a/Makefile +++ b/Makefile @@ -15,3 +15,19 @@ coverage: $(info $(M) coverage testing package...) ## test coverage package .PHONY: deps deps: $(info $(M) install required packages...) pip install -r requirements.txt + +.PHONY: setup +deps: $(info $(M) install required packages...) + pip install -e . + +.PHONY: build +build: $(info $(M) install required packages...) + python -m build + +.PHONY: publishtest +publishtest: $(info $(M) install required packages...) + python -m twine upload --repository testpypi dist/* + +.PHONY: publish +publish: $(info $(M) install required packages...) + python -m twine upload dist/* diff --git a/README.md b/README.md index 1d95c1a..3d8f7d3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ Package containing symmetric and asymmetric key ciphers and attacks +## Installation +pip install crypto-pkg + +### Cloned repo +If Installation is done via the GitHub cloned repository + +make setup + + ## Ciphers
  • Asymmetric Key (PKE)
  • @@ -35,7 +44,6 @@ Usage examples are provided in the attacks source code files
### From CLI -pip install -e . crypto attacks modifiedAES --help diff --git a/pyproject.toml b/pyproject.toml index f5b211d..a48e487 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ [build-system] -requires = ["setuptools>=61.0", "wheel"] -build-backend = "setuptools.build_meta" \ No newline at end of file +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[requires] +python_version = "3.8" diff --git a/requirements.txt b/requirements.txt index e106539..6d24d54 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -pycryptodome==3.19.0 +pycryptodome>=3.19.0 typer[all] -pydantic<2 -numpy==1.24.2 -matplotlib==3.7.1 +pydantic>=1.8,<2 +numpy>=1.24.2 +matplotlib>=3.7.1 diff --git a/setup.py b/setup.py index be86af8..1a847c1 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -__version__ = "1.4.5" +__version__ = "1.4.10" with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read()