Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger #21

Merged
merged 3 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Package containing symmetric and asymmetric key ciphers and attacks

## Installation
<code>pip install crypto-pkg</code>

### Cloned repo
If Installation is done via the GitHub cloned repository

<code>make setup</code>


## Ciphers
<ul>
<li>Asymmetric Key (PKE)</li>
Expand Down Expand Up @@ -35,7 +44,6 @@ Usage examples are provided in the attacks source code files
</ul>

### From CLI
<code>pip install -e .</code>

<code>crypto attacks modifiedAES --help</code>

Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[requires]
python_version = "3.8"
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
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__ = "1.4.4"
__version__ = "1.4.10"

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion src/crypto_pkg/clis/attacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 11 additions & 0 deletions src/crypto_pkg/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading