diff --git a/.github/workflows/codecipher_package_checker.yml b/.github/workflows/codecipher_package_checker.yml index cce7cb0..8371608 100755 --- a/.github/workflows/codecipher_package_checker.yml +++ b/.github/workflows/codecipher_package_checker.yml @@ -34,4 +34,4 @@ jobs: # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=79 --statistics --max-doc-length 127 \ No newline at end of file + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=150 --statistics --max-doc-length 150 \ No newline at end of file diff --git a/.github/workflows/codecipher_python3_build.yml b/.github/workflows/codecipher_python3_build.yml index 58e29ec..17afe0a 100644 --- a/.github/workflows/codecipher_python3_build.yml +++ b/.github/workflows/codecipher_python3_build.yml @@ -6,7 +6,6 @@ on: - 'codecipher/**' - 'MANIFEST.in' - 'pyproject.toml' - - 'setup.cfg' - 'setup.py' pull_request: branches: [ main ] @@ -14,7 +13,6 @@ on: - 'codecipher/**' - 'MANIFEST.in' - 'pyproject.toml' - - 'setup.cfg' - 'setup.py' jobs: deploy: diff --git a/.github/workflows/codecipher_python_checker.yml b/.github/workflows/codecipher_python_checker.yml index e9b437a..43bfd1a 100644 --- a/.github/workflows/codecipher_python_checker.yml +++ b/.github/workflows/codecipher_python_checker.yml @@ -22,12 +22,12 @@ jobs: run: | modules_ok=0 modules=($(find codecipher/ tests/ -type f -name '*.py' -exec echo '{}' \;)) - for mod in "${modules[@]}"; do line_length=$(wc -L < "${mod}"); [[ $line_length -gt 127 ]] && modules_ok=1; done + for mod in "${modules[@]}"; do line_length=$(wc -L < "${mod}"); [[ $line_length -gt 150 ]] && modules_ok=1; done [[ $modules_ok -eq 0 ]] && echo ok || exit 1 - name: Check max number of lines in modules id: num_line_checker run: | modules_ok=0 modules=($(find codecipher/ tests/ -type f -name '*.py' -exec echo '{}' \;)) - for mod in "${modules[@]}"; do line_numbers=$(wc -l < "${mod}"); [[ $line_numbers -gt 300 ]] && modules_ok=1; done + for mod in "${modules[@]}"; do line_numbers=$(wc -l < "${mod}"); [[ $line_numbers -gt 500 ]] && modules_ok=1; done [[ $modules_ok -eq 0 ]] && echo ok || exit 1 \ No newline at end of file diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..9cd6700 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,20 @@ +[MASTER] +# Optimization level. 0 is the highest, 2 is the lowest. +jobs=0 + +[MESSAGES CONTROL] +# Disable unnecessary-pass +# Centralized place for ignore / warning management. +disable=unnecessary-pass,line-too-long,too-many-arguments,too-few-public-methods,too-many-function-args + +[DESIGN] +# Maximum number of arguments for function / method defining. +max-args=10 +max-locals=25 +max-returns=10 +max-branches=15 +max-statements=60 +max-parents=10 +max-attributes=12 +max-public-methods=25 +max-positional-arguments=10 \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 4ab28f7..b06ae13 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,14 @@ { - "files.exclude": { - "*.pyc": true, - "**/*.pyc": true, - "__pycache__": true, - "**/__pycache__": true - }, - "cmake.configureOnOpen": false -} + "files.exclude": { + "**/*.pyc": true, + "**/__pycache__": true + }, + + "pylint.args": [ + "--rcfile=${workspaceFolder}/.pylintrc" + ], + + "pylint.importStrategy": "useBundled", + "pylint.cwd": "${workspaceFolder}", + "flake8.enabled": false +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7ae54a4..30ff6d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,58 +1,58 @@ -# Copyright 2021 - 2024 Vladimir Roncevic -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -FROM debian:12 -RUN apt-get update -RUN DEBIAN_FRONTEND=noninteractive \ - apt-get install -yq --no-install-recommends \ - vim \ - nano \ - tree \ - htop \ - wget \ - curl \ - unzip \ - ca-certificates \ - openssl \ - python3 \ - python3-dev \ - libyaml-dev - -RUN wget https://bootstrap.pypa.io/get-pip.py -RUN python3 get-pip.py -RUN python3 -m pip install --upgrade setuptools -RUN python3 -m pip install --upgrade pip -RUN python3 -m pip install --upgrade build -RUN rm -f get-pip.py -RUN mkdir /codecipher/ -COPY codecipher /codecipher/ -COPY pyproject.toml / -COPY MANIFEST.in / -COPY setup.py / -COPY README.md / -COPY LICENSE / -COPY requirements.txt / -RUN pip3 install -r requirements.txt -RUN rm -f requirements.txt -RUN python3 -m build --no-isolation --wheel -RUN pip install /dist/codecipher-*.whl -RUN rm -rf /codecipher* -RUN rm -rf dist/ -RUN rm -rf tests/ -RUN rm -f pyproject.toml -RUN rm -f MANIFEST.in -RUN rm -f setup.py -RUN rm -f README.md -RUN rm -f LICENSE +# Copyright 2021 - 2026 Vladimir Roncevic +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +FROM debian:12 +RUN apt-get update +RUN DEBIAN_FRONTEND=noninteractive \ + apt-get install -yq --no-install-recommends \ + vim \ + nano \ + tree \ + htop \ + wget \ + curl \ + unzip \ + ca-certificates \ + openssl \ + python3 \ + python3-dev \ + libyaml-dev + +RUN wget https://bootstrap.pypa.io/get-pip.py +RUN python3 get-pip.py +RUN python3 -m pip install --upgrade setuptools +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install --upgrade build +RUN rm -f get-pip.py +RUN mkdir /codecipher/ +COPY codecipher /codecipher/ +COPY pyproject.toml / +COPY MANIFEST.in / +COPY setup.py / +COPY README.md / +COPY LICENSE / +COPY requirements.txt / +RUN pip3 install -r requirements.txt +RUN rm -f requirements.txt +RUN python3 -m build --no-isolation --wheel +RUN pip install /dist/codecipher-*.whl +RUN rm -rf /codecipher* +RUN rm -rf dist/ +RUN rm -rf tests/ +RUN rm -f pyproject.toml +RUN rm -f MANIFEST.in +RUN rm -f setup.py +RUN rm -f README.md +RUN rm -f LICENSE diff --git a/README.md b/README.md index b88a544..56904f7 100644 --- a/README.md +++ b/README.md @@ -104,15 +104,15 @@ You can use Dockerfile to create image/container. ### Usage ```python -from codecipher.a1z52n62 import A1z52N62 -from codecipher.atbs import AlephTawBetShin -from codecipher.b64 import B64 -from codecipher.caesar import Caesar -from codecipher.vigenere import Vigenere -from codecipher.vernam import Vernam +from codecipher.a1z52n62 import A1Z52N62 +from codecipher.atbs.engine import ATBS +from codecipher.b64.engine import B64 +from codecipher.caesar.engine import Caesar +from codecipher.vigenere.engine import Vigenere +from codecipher.vernam.engine import Vernam print("A1z52N62 cipher") -cipher = A1z52N62() +cipher = A1Z52N62() data = "More Human Than Human01 Is Our Motto" # encoding data cipher.encode(data) @@ -124,8 +124,8 @@ cipher.decode(cipher.encode_data) print(cipher.decode_data) print(50*'=') -print("AlephTawBetShin cipher") -cipher = AlephTawBetShin() +print("ATBS cipher") +cipher = ATBS() data = "More Human Than Human01 Is Our Motto" # encoding data cipher.encode(data) @@ -201,66 +201,172 @@ Package structure ```bash codecipher/ - ├── a1z52n62/ - │   ├── decode.py - │   ├── encode.py + ├── a1z52n62/ + │   ├── config.py + │   ├── decode/ + │   │   ├── decode_algorithm.py + │   │   ├── decoder.py + │   │   └── __init__.py + │   ├── encode/ + │   │   ├── encode_algorithm.py + │   │   ├── encoder.py + │   │   └── __init__.py + │   ├── engine.py + │   └── __init__.py + ├── abstracts/ + │   ├── ialgorithm.py + │   ├── icharacter_validator.py + │   ├── icipher_engine.py + │   ├── iconfig.py + │   ├── idata_validator.py + │   ├── idecoder.py + │   ├── iencoder.py + │   ├── __init__.py + │   └── ivalidation_engine.py + ├── atbs/ + │   ├── config.py + │   ├── decode/ + │   │   ├── decode_algorithm.py + │   │   ├── decoder.py + │   │   └── __init__.py + │   ├── encode/ + │   │   ├── encode_algorithm.py + │   │   ├── encoder.py + │   │   └── __init__.py + │   ├── engine.py + │   └── __init__.py + ├── b64/ + │   ├── config.py + │   ├── decode/ + │   │   ├── decode_algorithm.py + │   │   ├── decoder.py + │   │   └── __init__.py + │   ├── encode/ + │   │   ├── encode_algorithm.py + │   │   ├── encoder.py + │   │   └── __init__.py + │   ├── engine.py + │   └── __init__.py + ├── caesar/ + │   ├── config.py + │   ├── decode/ + │   │   ├── decode_algorithm.py + │   │   ├── decoder.py + │   │   └── __init__.py + │   ├── encode/ + │   │   ├── encode_algorithm.py + │   │   ├── encoder.py + │   │   └── __init__.py + │   ├── engine.py + │   └── __init__.py + ├── __init__.py + ├── py.typed + ├── validation/ + │   ├── character_validator.py + │   ├── data_validator.py + │   ├── __init__.py + │   └── validation_engine.py + ├── vernam/ + │   ├── config.py + │   ├── decode/ + │   │   ├── decode_algorithm.py + │   │   ├── decoder.py + │   │   └── __init__.py + │   ├── encode/ + │   │   ├── encode_algorithm.py + │   │   ├── encoder.py + │   │   └── __init__.py + │   ├── engine.py + │   └── __init__.py + └── vigenere/ + ├── config.py + ├── decode/ + │   ├── decode_algorithm.py + │   ├── decoder.py │   └── __init__.py - ├── atbs/ - │   ├── decode.py - │   ├── encode.py - │   ├── __init__.py - │   └── lookup_table.py - ├── b64/ - │   ├── decode.py - │   ├── encode.py + ├── encode/ + │   ├── encode_algorithm.py + │   ├── encoder.py │   └── __init__.py - ├── caesar/ - │   ├── decode.py - │   ├── encode.py - │   └── __init__.py - ├── __init__.py - ├── py.typed - ├── vernam/ - │   ├── decode.py - │   ├── encode.py - │   └── __init__.py - └── vigenere/ - ├── decode.py - ├── encode.py - ├── __init__.py - ├── key_generator.py - └── lookup_table.py - - 7 directories, 23 files + ├── engine.py + └── __init__.py + + 21 directories, 69 files ``` ### Code coverage | Name | Stmts | Miss | Cover | |------|-------|------|-------| -| `codecipher/__init__.py` | 0 | 0 | 100%| -| `codecipher/a1z52n62/__init__.py` | 16 | 0 | 100%| -| `codecipher/a1z52n62/decode.py` | 32 | 2 | 94%| -| `codecipher/a1z52n62/encode.py` | 32 | 2 | 94%| -| `codecipher/atbs/__init__.py` | 16 | 0 | 100%| -| `codecipher/atbs/decode.py` | 29 | 2 | 93%| -| `codecipher/atbs/encode.py` | 29 | 2 | 93%| -| `codecipher/atbs/lookup_table.py` | 10 | 0 | 100%| -| `codecipher/b64/__init__.py` | 16 | 0 | 100%| -| `codecipher/b64/decode.py` | 24 | 2 | 92%| -| `codecipher/b64/encode.py` | 24 | 2 | 92%| -| `codecipher/caesar/__init__.py` | 16 | 0 | 100%| -| `codecipher/caesar/decode.py` | 41 | 2 | 95%| -| `codecipher/caesar/encode.py` | 41 | 2 | 95%| -| `codecipher/vernam/__init__.py` | 16 | 0 | 100%| -| `codecipher/vernam/decode.py` | 36 | 2 | 94%| -| `codecipher/vernam/encode.py` | 36 | 2 | 94%| -| `codecipher/vigenere/__init__.py` | 17 | 0 | 100%| -| `codecipher/vigenere/decode.py` | 37 | 2 | 95%| -| `codecipher/vigenere/encode.py` | 37 | 2 | 95%| -| `codecipher/vigenere/key_generator.py` | 37 | 2 | 95%| -| `codecipher/vigenere/lookup_table.py` | 16 | 0 | 100%| -| **Total** | 558 | 26 | 95% | +| `codecipher/__init__.py` | 9 | 0 | 100%| +| `codecipher/a1z52n62/__init__.py` | 9 | 0 | 100%| +| `codecipher/a1z52n62/config.py` | 26 | 0 | 100%| +| `codecipher/a1z52n62/decode/__init__.py` | 9 | 0 | 100%| +| `codecipher/a1z52n62/decode/decode_algorithm.py` | 41 | 6 | 85%| +| `codecipher/a1z52n62/decode/decoder.py` | 30 | 2 | 93%| +| `codecipher/a1z52n62/encode/__init__.py` | 9 | 0 | 100%| +| `codecipher/a1z52n62/encode/encode_algorithm.py` | 32 | 2 | 94%| +| `codecipher/a1z52n62/encode/encoder.py` | 30 | 2 | 93%| +| `codecipher/a1z52n62/engine.py` | 36 | 0 | 100%| +| `codecipher/abstracts/__init__.py` | 9 | 0 | 100%| +| `codecipher/abstracts/ialgorithm.py` | 16 | 1 | 94%| +| `codecipher/abstracts/icharacter_validator.py` | 14 | 1 | 93%| +| `codecipher/abstracts/icipher_engine.py` | 17 | 2 | 88%| +| `codecipher/abstracts/iconfig.py` | 23 | 0 | 100%| +| `codecipher/abstracts/idata_validator.py` | 14 | 1 | 93%| +| `codecipher/abstracts/idecoder.py` | 10 | 2 | 80%| +| `codecipher/abstracts/iencoder.py` | 10 | 2 | 80%| +| `codecipher/abstracts/ivalidation_engine.py` | 18 | 2 | 89%| +| `codecipher/atbs/__init__.py` | 9 | 0 | 100%| +| `codecipher/atbs/config.py` | 26 | 0 | 100%| +| `codecipher/atbs/decode/__init__.py` | 9 | 0 | 100%| +| `codecipher/atbs/decode/decode_algorithm.py` | 28 | 3 | 89%| +| `codecipher/atbs/decode/decoder.py` | 30 | 2 | 93%| +| `codecipher/atbs/encode/__init__.py` | 9 | 0 | 100%| +| `codecipher/atbs/encode/encode_algorithm.py` | 28 | 3 | 89%| +| `codecipher/atbs/encode/encoder.py` | 30 | 2 | 93%| +| `codecipher/atbs/engine.py` | 36 | 1 | 97%| +| `codecipher/b64/__init__.py` | 9 | 0 | 100%| +| `codecipher/b64/config.py` | 26 | 0 | 100%| +| `codecipher/b64/decode/__init__.py` | 9 | 0 | 100%| +| `codecipher/b64/decode/decode_algorithm.py` | 32 | 7 | 78%| +| `codecipher/b64/decode/decoder.py` | 30 | 2 | 93%| +| `codecipher/b64/encode/__init__.py` | 9 | 0 | 100%| +| `codecipher/b64/encode/encode_algorithm.py` | 27 | 3 | 89%| +| `codecipher/b64/encode/encoder.py` | 30 | 2 | 93%| +| `codecipher/b64/engine.py` | 36 | 2 | 94%| +| `codecipher/caesar/__init__.py` | 9 | 0 | 100%| +| `codecipher/caesar/config.py` | 26 | 0 | 100%| +| `codecipher/caesar/decode/__init__.py` | 9 | 0 | 100%| +| `codecipher/caesar/decode/decode_algorithm.py` | 41 | 2 | 95%| +| `codecipher/caesar/decode/decoder.py` | 30 | 2 | 93%| +| `codecipher/caesar/encode/__init__.py` | 9 | 0 | 100%| +| `codecipher/caesar/encode/encode_algorithm.py` | 41 | 2 | 95%| +| `codecipher/caesar/encode/encoder.py` | 30 | 2 | 93%| +| `codecipher/caesar/engine.py` | 36 | 2 | 94%| +| `codecipher/validation/__init__.py` | 9 | 0 | 100%| +| `codecipher/validation/character_validator.py` | 17 | 1 | 94%| +| `codecipher/validation/data_validator.py` | 19 | 1 | 95%| +| `codecipher/validation/validation_engine.py` | 24 | 4 | 83%| +| `codecipher/vernam/__init__.py` | 9 | 0 | 100%| +| `codecipher/vernam/config.py` | 26 | 0 | 100%| +| `codecipher/vernam/decode/__init__.py` | 9 | 0 | 100%| +| `codecipher/vernam/decode/decode_algorithm.py` | 44 | 5 | 89%| +| `codecipher/vernam/decode/decoder.py` | 30 | 2 | 93%| +| `codecipher/vernam/encode/__init__.py` | 9 | 0 | 100%| +| `codecipher/vernam/encode/encode_algorithm.py` | 44 | 5 | 89%| +| `codecipher/vernam/encode/encoder.py` | 30 | 2 | 93%| +| `codecipher/vernam/engine.py` | 36 | 0 | 100%| +| `codecipher/vigenere/__init__.py` | 9 | 0 | 100%| +| `codecipher/vigenere/config.py` | 26 | 0 | 100%| +| `codecipher/vigenere/decode/__init__.py` | 9 | 0 | 100%| +| `codecipher/vigenere/decode/decode_algorithm.py` | 40 | 3 | 92%| +| `codecipher/vigenere/decode/decoder.py` | 30 | 2 | 93%| +| `codecipher/vigenere/encode/__init__.py` | 9 | 0 | 100%| +| `codecipher/vigenere/encode/encode_algorithm.py` | 40 | 3 | 92%| +| `codecipher/vigenere/encode/encoder.py` | 30 | 2 | 93%| +| `codecipher/vigenere/engine.py` | 36 | 0 | 100%| +| **Total** | 1541 | 90 | 94% | ### Docs diff --git a/codecipher/__init__.py b/codecipher/__init__.py index 3292b26..c050a7f 100644 --- a/codecipher/__init__.py +++ b/codecipher/__init__.py @@ -15,4 +15,17 @@ See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . + + Initialization for codecipher package. ''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/a1z52n62/__init__.py b/codecipher/a1z52n62/__init__.py index 79b46cf..44b2388 100644 --- a/codecipher/a1z52n62/__init__.py +++ b/codecipher/a1z52n62/__init__.py @@ -16,47 +16,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . Info - Defines class A1z52N62 with attribute(s) and method(s). - Creates container class with aggregate backend API. + Initialization for codecipher.a1z52n62 package. ''' -import sys from typing import List -try: - from codecipher.a1z52n62.encode import A1z52N62Encode - from codecipher.a1z52n62.decode import A1z52N62Decode -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' - - -class A1z52N62(A1z52N62Encode, A1z52N62Decode): - ''' - Defines class A1z52N62 with attribute(s) and method(s). - Creates container class with aggregate backend API. - - It defines: - - :attributes: - | None. - :methods: - | __init__ - Initials A1z52N62 constructor. - ''' - - def __init__(self) -> None: - ''' - Initials A1z52N62 constructor. - - :exceptions: None - ''' - super().__init__() diff --git a/codecipher/a1z52n62/config.py b/codecipher/a1z52n62/config.py new file mode 100644 index 0000000..646c436 --- /dev/null +++ b/codecipher/a1z52n62/config.py @@ -0,0 +1,73 @@ +# -*- coding: UTF-8 -*- + +''' +Module + config.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines configuration for cipher A1z52N62 logic. +''' + +from typing import Dict, List, Optional, Set +from string import ascii_lowercase, ascii_uppercase, digits, whitespace +from dataclasses import dataclass, field +from codecipher.abstracts.iconfig import IConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass(frozen=True) +class A1z52N62Config(IConfig): + ''' + Defines class A1z52N62Config with attribute(s). + + It defines: + + :attributes: + | key - Controls transformation during encoding and decoding (default None). + | shift - Controls transformation during encoding and decoding (default 0). + | upper_case_offset - Offset for uppercase letters (default 64). + | lower_case_offset - Offset for lowercase letters (default 96). + | lower_case_base - Base index for lowercase letters (default 27). + | numeric_base - Base index for numeric characters (default 53). + | alphabet_size - Size of alphabet (default 26). + | code_splitter - Code splitter (default ' - '). + | altchars - Defines replacements for '+' and '/' (default None). + | padding - Adds to end '=' (default False). + | allowed_chars - Strict set of allowed characters (default ascii_lowercase + ascii_uppercase + digits + whitespace). + | lookup_table - Lookup table for cipher set (default None). + :methods: None + ''' + + key: Optional[str] = None + shift: int = 0 + upper_case_offset: int = 64 + lower_case_offset: int = 96 + lower_case_base: int = 27 + numeric_base: int = 53 + alphabet_size: int = 26 + code_splitter: Optional[str] = ' - ' + altchars: Optional[bytes] = None + padding: bool = False + allowed_chars: Optional[Set[str]] = field( + default_factory=lambda: set(ascii_lowercase + ascii_uppercase + digits + whitespace) + ) + lookup_table: Optional[Dict[str, str]] = None diff --git a/codecipher/a1z52n62/decode.py b/codecipher/a1z52n62/decode.py deleted file mode 100644 index 33b24b6..0000000 --- a/codecipher/a1z52n62/decode.py +++ /dev/null @@ -1,99 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - decode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class A1z52N62Decode with attribute(s) and method(s). - Creates decode class with backend API. -''' - -from dataclasses import dataclass, field -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class A1z52N62Decode: - ''' - Defines class A1z52N62Decode with attribute(s) and method(s). - Creates decode class with backend API. - - It defines: - - :attributes: - | _decode_data - Data decode container. - :methods: - | decode_data - Property methods for decode data. - | decode - Decode data from A1z52N62 format. - ''' - - _decode_data: Optional[str] = field(default=None) - - @property - def decode_data(self) -> Optional[str]: - ''' - Property method for getting decode data. - - :return: Decode data in str format | None - :rtype: - :exceptions: None - ''' - return self._decode_data - - @decode_data.setter - def decode_data(self, decode_data: Optional[str]) -> None: - ''' - Property method for setting decode data. - - :param decode_data: Decoded data | None - :type decode_data: - :return: None - :exceptions: None - ''' - if bool(decode_data): - self._decode_data = decode_data - - def decode(self, data: Optional[str]) -> None: - ''' - Decoding data from A1z52N62 format. - - :param data: Data which should be decoded | None - :type data: - :return: None - :exceptions: None - ''' - if bool(data): - decode_list: List[str] = [] - for element in data.split(' - '): - if element.isnumeric(): - if int(element) <= 52: - if int(element) <= 26: - decode_list.append(chr(int(element) + 64)) - else: - decode_list.append(chr(int(element) + 96 - 27)) - else: - decode_list.append(str(int(element) - 53)) - else: - decode_list.append(element) - self._decode_data = ''.join(decode_list) diff --git a/codecipher/a1z52n62/decode/.editorconfig b/codecipher/a1z52n62/decode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/a1z52n62/decode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/a1z52n62/decode/__init__.py b/codecipher/a1z52n62/decode/__init__.py new file mode 100644 index 0000000..47dc4a7 --- /dev/null +++ b/codecipher/a1z52n62/decode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.a1z52n62.decode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/a1z52n62/decode/decode_algorithm.py b/codecipher/a1z52n62/decode/decode_algorithm.py new file mode 100644 index 0000000..61a1d71 --- /dev/null +++ b/codecipher/a1z52n62/decode/decode_algorithm.py @@ -0,0 +1,115 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class DecodeAlgorithm with default cipher A1z52N62 implementation. +''' + +from typing import List, Optional +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.a1z52n62.config import A1z52N62Config + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class DecodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class DecodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher A1z52N62. + :methods: + | __init__ - Initializes DecodeAlgorithm constructor. + | encoded_data - Property method for getting decoded data. + | encode - Execute cipher A1z52N62 logic. + ''' + + def __init__(self) -> None: + ''' + Initializes DecodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher A1z52N62 logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or A1z52N62Config() + + if not self.__config: + return None + + splitter: str = getattr(self.__config, 'code_splitter', ' - ') or ' - ' + + try: + tokens: List[str] = data.split(splitter) + decode_list: List[str] = [] + + for token in tokens: + + if not token: + continue + + if token.isdigit(): + val = int(token) + + # Range 1 to 26: big letters (A-Z) + if 1 <= val <= self.__config.alphabet_size: + decode_list.append(chr(val + self.__config.upper_case_offset)) + + # Range 27 to 52: small letters (a-z) + elif self.__config.lower_case_base <= val <= (self.__config.lower_case_base + self.__config.alphabet_size - 1): + decode_list.append(chr(val - (self.__config.lower_case_base - 1) + self.__config.lower_case_offset)) + + # Range 53 to 62: digits (0-9) + elif val >= self.__config.numeric_base: + decode_list.append(str(val - self.__config.numeric_base)) + + # Defanse step: any token out of range, append as string + else: + decode_list.append(token) + else: + # All others (ex. space ' ', dot '.'), append without changes to decode list + decode_list.append(token) + + # Join decoded list without splitters and spaces + return "".join(decode_list) + except (AttributeError, ValueError, TypeError): + return None diff --git a/codecipher/a1z52n62/decode/decoder.py b/codecipher/a1z52n62/decode/decoder.py new file mode 100644 index 0000000..42db5ac --- /dev/null +++ b/codecipher/a1z52n62/decode/decoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class decoder with cipher A1z52N62 logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.idecoder import IDecoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.a1z52n62.config import A1z52N62Config +from codecipher.a1z52n62.decode.decode_algorithm import DecodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Decoder(IDecoder): + ''' + Defines class Decoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher A1z52N62 logic. + | _strategy - Strategy for cipher A1z52N62 logic. + | _decoded_data - Container for decoded data. + :methods: + | decoded_data - Property method for getting decoded data. + | decode - Decode data by cipher A1z52N62 logic. + ''' + + _config: IConfig = field(default_factory=A1z52N62Config) + _strategy: IAlgorithm[IConfig] = field(default_factory=DecodeAlgorithm) + _decoded_data: Optional[str] = field(default=None, init=False) + + @property + def decoded_data(self) -> Optional[str]: + ''' + Property method for getting decoded data. + + :return: Decoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._decoded_data + + def decode(self, data: Optional[str] = None) -> bool: + ''' + Decode data by cipher A1z52N62 logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher A1z52N62 logic with configuration parameters + self._decoded_data = self._strategy.execute(data, self._config) + + if not self._decoded_data: + return False + + return True diff --git a/codecipher/a1z52n62/encode.py b/codecipher/a1z52n62/encode.py deleted file mode 100644 index 0b854ac..0000000 --- a/codecipher/a1z52n62/encode.py +++ /dev/null @@ -1,99 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - encode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class A1z52N62Encode with attribute(s) and method(s). - Creates encode class with backend API. -''' - -from dataclasses import dataclass, field -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class A1z52N62Encode: - ''' - Defines class A1z52N62Encode with attribute(s) and method(s). - Creates encode class with backend API. - - It defines: - - :attributes: - | _encode_data - Data encode container. - :methods: - | encode_data - Property methods for encode data. - | encode - Encode data to A1z52N62 format. - ''' - - _encode_data: Optional[str] = field(default=None) - - @property - def encode_data(self) -> Optional[str]: - ''' - Property method for getting encode data. - - :return: Encoded data - :rtype: - :exceptions: None - ''' - return self._encode_data - - @encode_data.setter - def encode_data(self, encode_data: Optional[str]) -> None: - ''' - Property method for setting encode data. - - :param encode_data: Encode data | None - :type encode_data: - :return: None - :exceptions: None - ''' - if bool(encode_data): - self._encode_data = encode_data - - def encode(self, data: Optional[str]) -> None: - ''' - Encoding data to A1z52N62 format. - - :param data: Data which should be encoded | None - :type data: - :return: None - :exceptions: None - ''' - if bool(data): - encode_list: List[str] = [] - for element in data: - if element.isalpha(): - if element.isupper(): - encode_list.append(str(ord(element) - 64)) - else: - encode_list.append(str(ord(element) - 96 + 27)) - else: - if element.isnumeric(): - encode_list.append(str(int(element) + 53)) - else: - encode_list.append(element) - self._encode_data = ' - '.join(encode_list) diff --git a/codecipher/a1z52n62/encode/.editorconfig b/codecipher/a1z52n62/encode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/a1z52n62/encode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/a1z52n62/encode/__init__.py b/codecipher/a1z52n62/encode/__init__.py new file mode 100644 index 0000000..3fea7f7 --- /dev/null +++ b/codecipher/a1z52n62/encode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.a1z52n62.encode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/a1z52n62/encode/encode_algorithm.py b/codecipher/a1z52n62/encode/encode_algorithm.py new file mode 100644 index 0000000..e2c4de8 --- /dev/null +++ b/codecipher/a1z52n62/encode/encode_algorithm.py @@ -0,0 +1,101 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class EncodeAlgorithm with default cipher A1z52N62 implementation. +''' + +from typing import List, Optional +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.a1z52n62.config import A1z52N62Config + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class EncodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class EncodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher A1z52N62. + :methods: + | __init__ - Initializes EncodeAlgorithm constructor. + | encoded_data - Property method for getting encoded data. + | encode - Execute cipher A1z52N62 logic. + ''' + + def __init__(self) -> None: + ''' + Initializes EncodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher A1z52N62 logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or A1z52N62Config() + + if not self.__config: + return None + + splitter = getattr(self.__config, 'code_splitter', ' - ') or ' - ' + + encode_list: List[str] = [] + + for element in data: + if element.isalpha(): + if element.isupper(): + # 'A' -> 65 - 64 = 1. + encode_list.append(str(ord(element) - self.__config.upper_case_offset)) + else: + # lower_case_base = 27, a ord('a') - 96 = 1, 'a' -> (1 + 26 = 27). + encode_list.append( + str(ord(element) - self.__config.lower_case_offset + (self.__config.lower_case_base - 1)) + ) + elif element.isnumeric(): + # '0' -> 0 + 53 = 53, '9' -> 9 + 53 = 62. + encode_list.append(str(int(element) + self.__config.numeric_base)) + else: + # All other characters (spaces, punctuation) remain unchanged. + encode_list.append(element) + + # Join encoded list with splitters + return splitter.join(encode_list) diff --git a/codecipher/a1z52n62/encode/encoder.py b/codecipher/a1z52n62/encode/encoder.py new file mode 100644 index 0000000..bbcc16b --- /dev/null +++ b/codecipher/a1z52n62/encode/encoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class encoder with cipher A1z52N62 logic. +''' + +from typing import List, Optional +from dataclasses import dataclass, field +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.a1z52n62.config import A1z52N62Config +from codecipher.a1z52n62.encode.encode_algorithm import EncodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Encoder(IEncoder): + ''' + Defines class Encoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher A1z52N62 logic. + | _strategy - Strategy for cipher A1z52N62 logic. + | _encoded_data - Container for encoded data. + :methods: + | encoded_data - Property method for getting encoded data. + | encode - Encode data by cipher A1z52N62 logic. + ''' + + _config: IConfig = field(default_factory=A1z52N62Config) + _strategy: IAlgorithm[IConfig] = field(default_factory=EncodeAlgorithm) + _encoded_data: Optional[str] = field(default=None, init=False) + + @property + def encoded_data(self) -> Optional[str]: + ''' + Property method for getting encoded data. + + :return: Encoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._encoded_data + + def encode(self, data: Optional[str] = None) -> bool: + ''' + Encode data by cipher A1z52N62 logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher A1z52N62 logic with configuration parameters + self._encoded_data = self._strategy.execute(data, self._config) + + if not self._encoded_data: + return False + + return True diff --git a/codecipher/a1z52n62/engine.py b/codecipher/a1z52n62/engine.py new file mode 100644 index 0000000..dabe30c --- /dev/null +++ b/codecipher/a1z52n62/engine.py @@ -0,0 +1,126 @@ +# -*- coding: UTF-8 -*- + +''' +Module + a1z52n62.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class A1Z52N62 with attribute(s) and method(s). +''' + +from typing import List, Optional +from codecipher.abstracts.icipher_engine import ICipherEngine +from codecipher.abstracts.iconfig import IConfig +from codecipher.abstracts.ivalidation_engine import IValidationEngine +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.idecoder import IDecoder +from codecipher.validation.validation_engine import ValidationEngine +from codecipher.a1z52n62.encode.encoder import Encoder +from codecipher.a1z52n62.decode.decoder import Decoder +from codecipher.a1z52n62.config import A1z52N62Config + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class A1Z52N62(ICipherEngine): + ''' + Defines class A1Z52N62 with attribute(s) and method(s). + + It defines: + + :attributes: + | __config - Configuration for cipher A1Z52N62. + | __validation_engine - Engine for data validation. + | __encoder - Encoder for cipher A1Z52N62. + | __decoder - Decoder for cipher A1Z52N62. + :methods: + | __init__ - Initializes A1Z52N62 constructor. + | encode - Encoding data to A1Z52N62 format. + | decode - Decoding data from A1Z52N62 format. + ''' + + def __init__( + self, + config: Optional[IConfig] = None, + validation_engine: Optional[IValidationEngine] = None, + encoder: Optional[IEncoder] = None, + decoder: Optional[IDecoder] = None, + ) -> None: + ''' + Initializes A1Z52N62 constructor. + + :param config: Configuration for cipher A1Z52N62 | None + :type config: + :param validation_engine: Engine for data validation | None + :type validation_engine: + :param encoder: Encoder for cipher | None + :type encoder: + :param decoder: Decoder for cipher | None + :type decoder: + :exceptions: None + ''' + # Dependency injection or use default implementations + self.__config: IConfig = config or A1z52N62Config() + self.__validation_engine: IValidationEngine = validation_engine or ValidationEngine( + allowed_chars=self.__config.allowed_chars + ) + self.__encoder: IEncoder = encoder or Encoder(_config=self.__config) + self.__decoder: IDecoder = decoder or Decoder(_config=self.__config) + + def encode(self, data: Optional[str]) -> Optional[str]: + ''' + Encoding data to A1Z52N62 format. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking and validation data for process of encoding + if not data or not self.__validation_engine.is_valid(data): + return None + + # Checking process of encoding data + if not self.__encoder.encode(data): + return None + + return self.__encoder.encoded_data + + def decode(self, data: Optional[str]) -> Optional[str]: + ''' + Decoding data from A1Z52N62 format. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking data and process of decoding data + if not data or not self.__decoder.decode(data): + return None + + # Checking and validation decoded data + if not self.__validation_engine.is_valid(self.__decoder.decoded_data): + return None + + return self.__decoder.decoded_data diff --git a/codecipher/atbs/lookup_table.py b/codecipher/abstracts/__init__.py similarity index 57% rename from codecipher/atbs/lookup_table.py rename to codecipher/abstracts/__init__.py index 17f8f5e..203b981 100644 --- a/codecipher/atbs/lookup_table.py +++ b/codecipher/abstracts/__init__.py @@ -1,8 +1,9 @@ + # -*- coding: UTF-8 -*- ''' Module - lookup_table.py + __init__.py Copyright Copyright (C) 2021 - 2026 Vladimir Roncevic codecipher is free software: you can redistribute it and/or modify it @@ -16,32 +17,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . Info - Defines dict LOOKUP_TABLE for AlephTawBetShin format. + Initialization for codecipher.abstracts package. ''' -from typing import List, Dict +from typing import List __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' - -LOOKUP_TABLE: Dict[str, str] = { - 'A': 'Z', 'B': 'Y', 'C': 'X', 'D': 'W', 'E': 'V', - 'F': 'U', 'G': 'T', 'H': 'S', 'I': 'R', 'J': 'Q', - 'K': 'P', 'L': 'O', 'M': 'N', 'N': 'M', 'O': 'L', - 'P': 'K', 'Q': 'J', 'R': 'I', 'S': 'H', 'T': 'G', - 'U': 'F', 'V': 'E', 'W': 'D', 'X': 'C', 'Y': 'B', - 'Z': 'A', 'a': 'z', 'b': 'y', 'c': 'x', 'd': 'w', - 'e': 'v', 'f': 'u', 'g': 't', 'h': 's', 'i': 'r', - 'j': 'q', 'k': 'p', 'l': 'o', 'm': 'n', 'n': 'm', - 'o': 'l', 'p': 'k', 'q': 'j', 'r': 'i', 's': 'h', - 't': 'g', 'u': 'f', 'v': 'e', 'w': 'd', 'x': 'c', - 'y': 'b', 'z': 'a', ' ': ' ', '\n': '\n', '0': '9', - '1': '8', '2': '7', '3': '6', '4': '5', '5': '4', - '6': '3', '7': '2', '8': '1', '9': '0' -} diff --git a/codecipher/abstracts/ialgorithm.py b/codecipher/abstracts/ialgorithm.py new file mode 100644 index 0000000..38dd9c7 --- /dev/null +++ b/codecipher/abstracts/ialgorithm.py @@ -0,0 +1,63 @@ +# -*- coding: UTF-8 -*- + +''' +Module + ialgorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class IAlgorithm for cipher algorithms. +''' + +from typing import List, Optional, TypeVar, Generic +from abc import ABC, abstractmethod +from codecipher.abstracts.iconfig import IConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + +# Generic type for algorithm configuration +ConfigT = TypeVar('ConfigT', bound=IConfig) + + +class IAlgorithm(ABC, Generic[ConfigT]): + ''' + Defines interface IAlgorithm with abstract method. + + It defines: + + :attributes: None + :methods: + | execute - Execute chipher logic for processing data. + ''' + + @abstractmethod + def execute(self, data: Optional[str] = None, config: Optional[ConfigT] = None) -> Optional[str]: + ''' + Execute cipher logic for processing data. + + :param data: Data in string format which should to be processed | None + :type data: + :param config: Configuration parameters for cipher | None + :type config: + :return: Processed data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + raise NotImplementedError('Method execute() must be implemented.') diff --git a/codecipher/vigenere/lookup_table.py b/codecipher/abstracts/icharacter_validator.py similarity index 51% rename from codecipher/vigenere/lookup_table.py rename to codecipher/abstracts/icharacter_validator.py index 2686853..d4ecdc9 100644 --- a/codecipher/vigenere/lookup_table.py +++ b/codecipher/abstracts/icharacter_validator.py @@ -2,7 +2,7 @@ ''' Module - lookup_table.py + icharacter_validator.py Copyright Copyright (C) 2021 - 2026 Vladimir Roncevic codecipher is free software: you can redistribute it and/or modify it @@ -16,43 +16,42 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . Info - Defines class LookUpTable with attribute(s). - Creates lookup table class with support for encoding/decoding. + Defines interface ICharacterValidator for character validators. ''' -from typing import List, Dict +from typing import List, Optional +from abc import ABC, abstractmethod __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' -class LookUpTable: +class ICharacterValidator(ABC): ''' - Defines class LookUpTable with attribute(s) and method(s). - Creates lookup table class with support for encoding/decoding. + Defines interface ICharacterValidator with abstract method. It defines: - :attributes: - | ALPHA - Define alphabet for encoding/decoding. - | NUM - Defines numeric for encoding/decoding. - | WHITE_SPACE - Defines white space for encoding/decoding. - | ALPHANUM - Aggregated chars for encoding/decoding. - | LETTER_TO_INDEX - Indexed letters for encoding/decoding. - | INDEX_TO_LETTER - Indexed letters for encoding/decoding. + :attributes: None :methods: - | None + | is_valid_char - Validates if a single character belongs to cipher charcter set. ''' - ALPHA: str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' - NUM: str = '0123456789' - WHITE_SPACE: str = ' ' - ALPHANUM: str = ''.join([ALPHA, NUM, WHITE_SPACE]) - LETTER_TO_INDEX: Dict[str, int] = dict(zip(ALPHANUM, range(len(ALPHANUM)))) - INDEX_TO_LETTER: Dict[int, str] = dict(zip(range(len(ALPHANUM)), ALPHANUM)) + @abstractmethod + def is_valid_char(self, character: Optional[str]) -> bool: + ''' + Validates if a single character belongs to cipher charcter set. + + :param character: Single character in string format to be validated | None + :type character: + :return: True (valid) | False (invalid) + :rtype: + :exceptions: NotImplementedError + ''' + raise NotImplementedError("Method is_valid_char() must be implemented.") diff --git a/codecipher/abstracts/icipher_engine.py b/codecipher/abstracts/icipher_engine.py new file mode 100644 index 0000000..f0025d9 --- /dev/null +++ b/codecipher/abstracts/icipher_engine.py @@ -0,0 +1,71 @@ +# -*- coding: UTF-8 -*- + +''' +Module + icipher_engine.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines interface ICipherEngine for cipher class with encoders and decoders. +''' + +from abc import ABC, abstractmethod +from typing import List, Optional + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class ICipherEngine(ABC): + ''' + Defines interface ICipherEngine with method(s). + + It defines: + + :attributes: None + :methods: + | encode - Encoding data in string format to CIPHER format. + | decode - Decoding data in string format from CIPHER format. + ''' + + @abstractmethod + def encode(self, data: Optional[str]) -> Optional[str]: + ''' + Encoding data in string format to CIPHER format. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: NotImplementedError + ''' + raise NotImplementedError('Method encode() must be implemented.') + + @abstractmethod + def decode(self, data: Optional[str]) -> Optional[str]: + ''' + Decoding data in string format from CIPHER format. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: NotImplementedError + ''' + raise NotImplementedError('Method decode() must be implemented.') diff --git a/codecipher/abstracts/iconfig.py b/codecipher/abstracts/iconfig.py new file mode 100644 index 0000000..b6ca131 --- /dev/null +++ b/codecipher/abstracts/iconfig.py @@ -0,0 +1,68 @@ +# -*- coding: UTF-8 -*- + +''' +Module + iconfig.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines abstract class IConfig for cipher configurations. +''' + +from typing import Dict, List, Optional, Set +from abc import ABC + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class IConfig(ABC): + ''' + Defines interface IConfig with attribute(s). + + It defines: + + :attributes: + | key - Controls transformation during encoding and decoding. + | shift - Controls transformation during encoding and decoding. + | upper_case_offset - Offset for uppercase letters in cipher set. + | lower_case_offset - Offset for lowercase letters in cipher set. + | lower_case_base - Base index for lowercase letters in cipher set. + | numeric_base - Base index for numeric characters in cipher set. + | alphabet_size - Size of alphabet in cipher set. + | code_splitter - Code splitter in cipher set. + | altchars - Defines replacements for '+' and '/' in cipher set. + | padding - Adds to end '=' in cipher set. + | allowed_chars - Strict set of allowed characters in cipher set. + | lookup_table - Lookup table for cipher set. + :methods: None + ''' + + key: Optional[str] + shift: int + upper_case_offset: int + lower_case_offset: int + lower_case_base: int + numeric_base: int + alphabet_size: int + code_splitter: Optional[str] + altchars: Optional[bytes] + padding: bool + allowed_chars: Optional[Set[str]] + lookup_table: Optional[Dict[str, str]] diff --git a/codecipher/abstracts/idata_validator.py b/codecipher/abstracts/idata_validator.py new file mode 100644 index 0000000..90b3f6b --- /dev/null +++ b/codecipher/abstracts/idata_validator.py @@ -0,0 +1,57 @@ +# -*- coding: UTF-8 -*- + +''' +Module + idata_validator.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines interface IDataValidator for data validators. +''' + +from typing import List, Optional +from abc import ABC, abstractmethod + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class IDataValidator(ABC): + ''' + Defines interface IDataValidator with abstract method. + + It defines: + + :attributes: None + :methods: + | is_valid - Validates if data belongs to cipher data set. + ''' + + @abstractmethod + def is_valid(self, data: Optional[str]) -> bool: + ''' + Validates if data belongs to cipher data set. + + :param data: Data in string format which should to be validated | None + :type data: + :return: True (valid) | False (invalid) + :rtype: + :exceptions: None + ''' + raise NotImplementedError('Method is_valid() must be implemented.') diff --git a/codecipher/abstracts/idecoder.py b/codecipher/abstracts/idecoder.py new file mode 100644 index 0000000..c40082d --- /dev/null +++ b/codecipher/abstracts/idecoder.py @@ -0,0 +1,59 @@ +# -*- coding: UTF-8 -*- + +''' +Module + idecoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines interface IDecoder for algorithm decoders. +''' + +from abc import ABC, abstractmethod +from typing import Optional + +class IDecoder(ABC): + ''' + Defines interface IDecoder with method(s). + + It defines: + :attributes: None. + :methods: + | decoded_data - Property method for getting decoded data. + | decode - Decode data using decoder cipher. + ''' + + @property + @abstractmethod + def decoded_data(self) -> Optional[str]: + ''' + Property method for getting decoded data. + + :return: Decoded data in string format | None + :rtype: + :exceptions: NotImplementedError + ''' + raise NotImplementedError('Method decoded_data() must be implemented.') + + @abstractmethod + def decode(self, data: Optional[str] = None) -> bool: + ''' + Decode data using decoder cipher. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: NotImplementedError + ''' + raise NotImplementedError('Method decode() must be implemented.') diff --git a/codecipher/abstracts/iencoder.py b/codecipher/abstracts/iencoder.py new file mode 100644 index 0000000..cbe539a --- /dev/null +++ b/codecipher/abstracts/iencoder.py @@ -0,0 +1,59 @@ +# -*- coding: UTF-8 -*- + +''' +Module + iencoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines interface IEncoder for algorithm encoders. +''' + +from abc import ABC, abstractmethod +from typing import Optional + +class IEncoder(ABC): + ''' + Defines interface IEncoder with method(s). + + It defines: + :attributes: None + :methods: + | encoded_data - Property method for getting encoded data. + | encode - Encode data using encoder cipher. + ''' + + @property + @abstractmethod + def encoded_data(self) -> Optional[str]: + ''' + Property method for getting encoded data. + + :return: Encoded data in str format | None + :rtype: + :exceptions: NotImplementedError + ''' + raise NotImplementedError('Method encoded_data() must be implemented.') + + @abstractmethod + def encode(self, data: Optional[str] = None) -> bool: + ''' + Encode data using encoder cipher. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: NotImplementedError + ''' + raise NotImplementedError('Method encode() must be implemented.') diff --git a/codecipher/abstracts/ivalidation_engine.py b/codecipher/abstracts/ivalidation_engine.py new file mode 100644 index 0000000..6af7487 --- /dev/null +++ b/codecipher/abstracts/ivalidation_engine.py @@ -0,0 +1,71 @@ +# -*- coding: UTF-8 -*- + +''' +Module + ivalidation_engine.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines interface IValidationEngine for validation engines. +''' + +from typing import List, Optional +from abc import ABC, abstractmethod +from codecipher.abstracts.idata_validator import IDataValidator + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class IValidationEngine(ABC): + ''' + Defines interface IValidationEngine with abstract method(s). + + It defines: + + :attributes: None + :methods: + | add_validator - Adds a new data validator to the validation engine. + | is_valid - Validates data using all registered validators. + ''' + + @abstractmethod + def add_validator(self, validator: Optional[IDataValidator]) -> None: + ''' + Adds a new data validator to the validation engine. + + :param validator: Data validator instance to be added | None + :type validator: + :return: None + :exceptions: NotImplementedError + ''' + raise NotImplementedError('Method add_validator() must be implemented.') + + @abstractmethod + def is_valid(self, data: Optional[str]) -> bool: + ''' + Validates data using all registered validators. + + :param data: Data in string format which should to be validated | None + :type data: + :return: True (valid) | False (invalid) + :rtype: + :exceptions: NotImplementedError + ''' + raise NotImplementedError('Method is_valid() must be implemented.') diff --git a/codecipher/atbs/__init__.py b/codecipher/atbs/__init__.py index cfc3382..0b53e2e 100644 --- a/codecipher/atbs/__init__.py +++ b/codecipher/atbs/__init__.py @@ -16,47 +16,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . Info - Defines class AlephTawBetShin with attribute(s) and method(s). - Creates container class with aggregate backend API. + Initialization for codecipher.atbs package. ''' -import sys from typing import List -try: - from codecipher.atbs.encode import AlephTawBetShinEncode - from codecipher.atbs.decode import AlephTawBetShinDecode -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' - - -class AlephTawBetShin(AlephTawBetShinEncode, AlephTawBetShinDecode): - ''' - Defines class AlephTawBetShin with attribute(s) and method(s). - Creates container class with aggregate backend API. - - It defines: - - :attributes: - | None. - :methods: - | __init__ - Initials AlephTawBetShin constructor. - ''' - - def __init__(self) -> None: - ''' - Initials AlephTawBetShin constructor. - - :exceptions: None - ''' - super().__init__() diff --git a/codecipher/atbs/config.py b/codecipher/atbs/config.py new file mode 100644 index 0000000..8919651 --- /dev/null +++ b/codecipher/atbs/config.py @@ -0,0 +1,89 @@ +# -*- coding: UTF-8 -*- + +''' +Module + config.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines configuration for cipher ATBS logic. +''' + +from typing import Dict, List, Optional, Set +from string import ascii_lowercase, ascii_uppercase, digits, whitespace +from dataclasses import dataclass, field +from codecipher.abstracts.iconfig import IConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass(frozen=True) +class ATBSConfig(IConfig): + ''' + Defines class ATBSConfig with attribute(s). + + It defines: + + :attributes: + | key - Controls transformation during encoding and decoding (default None). + | shift - Controls transformation during encoding and decoding (default 0). + | upper_case_offset - Offset for uppercase letters (default 0). + | lower_case_offset - Offset for lowercase letters (default 0). + | lower_case_base - Base index for lowercase letters (default 0). + | numeric_base - Base index for numeric characters (default 0). + | alphabet_size - Size of alphabet (default 0). + | code_splitter - Code splitter (default None). + | altchars - Defines replacements for '+' and '/' (default None). + | padding - Adds to end '=' (default False). + | allowed_chars - Strict set of allowed characters (default ascii_lowercase + ascii_uppercase + digits + whitespace). + | lookup_table - Lookup table for cipher set. + :methods: None + ''' + + key: Optional[str] = None + shift: int = 0 + upper_case_offset: int = 0 + lower_case_offset: int = 0 + lower_case_base: int = 0 + numeric_base: int = 0 + alphabet_size: int = 0 + code_splitter: Optional[str] = None + altchars: Optional[bytes] = None + padding: bool = False + allowed_chars: Optional[Set[str]] = field( + default_factory=lambda: set(ascii_lowercase + ascii_uppercase + digits + whitespace) + ) + lookup_table: Optional[Dict[str, str]] = field( + default_factory=lambda: { + 'A': 'Z', 'B': 'Y', 'C': 'X', 'D': 'W', 'E': 'V', + 'F': 'U', 'G': 'T', 'H': 'S', 'I': 'R', 'J': 'Q', + 'K': 'P', 'L': 'O', 'M': 'N', 'N': 'M', 'O': 'L', + 'P': 'K', 'Q': 'J', 'R': 'I', 'S': 'H', 'T': 'G', + 'U': 'F', 'V': 'E', 'W': 'D', 'X': 'C', 'Y': 'B', + 'Z': 'A', 'a': 'z', 'b': 'y', 'c': 'x', 'd': 'w', + 'e': 'v', 'f': 'u', 'g': 't', 'h': 's', 'i': 'r', + 'j': 'q', 'k': 'p', 'l': 'o', 'm': 'n', 'n': 'm', + 'o': 'l', 'p': 'k', 'q': 'j', 'r': 'i', 's': 'h', + 't': 'g', 'u': 'f', 'v': 'e', 'w': 'd', 'x': 'c', + 'y': 'b', 'z': 'a', ' ': ' ', '\n': '\n', '0': '9', + '1': '8', '2': '7', '3': '6', '4': '5', '5': '4', + '6': '3', '7': '2', '8': '1', '9': '0' + } + ) diff --git a/codecipher/atbs/decode.py b/codecipher/atbs/decode.py deleted file mode 100644 index 813adbf..0000000 --- a/codecipher/atbs/decode.py +++ /dev/null @@ -1,97 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - decode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class AlephTawBetShinDecode with attribute(s) and method(s). - Creates decode class with backend API. -''' - -import sys -from dataclasses import dataclass, field -from typing import List, Optional - -try: - from codecipher.atbs.lookup_table import LOOKUP_TABLE -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class AlephTawBetShinDecode: - ''' - Defines class AlephTawBetShinDecode with attribute(s) and method(s). - Creates decode class with backend API. - - It defines: - - :attributes: - | _decode_data - Data decode container. - :methods: - | decode_data - Property methods for decode data. - | decode - Decode data from AlephTawBetShin format. - ''' - - _decode_data: Optional[str] = field(default=None) - - @property - def decode_data(self) -> Optional[str]: - ''' - Property method for getting decode data. - - :return: Decode data in str format | None - :rtype: - :exceptions: None - ''' - return self._decode_data - - @decode_data.setter - def decode_data(self, decode_data: Optional[str]) -> None: - ''' - Property method for setting decode data. - - :param decode_data: Decoded data | None - :type decode_data: - :return: None - :exceptions: None - ''' - if bool(decode_data): - self._decode_data = decode_data - - def decode(self, data: Optional[str]) -> None: - ''' - Decoding data from AlephTawBetShin format. - - :param data: Data which should be decoded | None - :type data: - :return: None - :exceptions: None - ''' - if bool(data): - decode_list: List[str] = [] - for element in data: - decode_list.append(LOOKUP_TABLE[element]) - self._decode_data = ''.join(decode_list) diff --git a/codecipher/atbs/decode/.editorconfig b/codecipher/atbs/decode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/atbs/decode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/atbs/decode/__init__.py b/codecipher/atbs/decode/__init__.py new file mode 100644 index 0000000..fe881dc --- /dev/null +++ b/codecipher/atbs/decode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.atbs.decode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/atbs/decode/decode_algorithm.py b/codecipher/atbs/decode/decode_algorithm.py new file mode 100644 index 0000000..504dd03 --- /dev/null +++ b/codecipher/atbs/decode/decode_algorithm.py @@ -0,0 +1,89 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class DecodeAlgorithm with default cipher ATBS implementation. +''' + +from typing import Dict, List, Optional +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.atbs.config import ATBSConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class DecodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class DecodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher ATBS. + :methods: + | __init__ - Initializes DecodeAlgorithm constructor. + | encoded_data - Property method for getting decoded data. + | encode - Execute cipher ATBS logic. + ''' + + def __init__(self) -> None: + ''' + Initializes DecodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher ATBS logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or ATBSConfig() + + if not self.__config: + return None + + lookup: Optional[Dict[str, str]] = getattr(self.__config, 'lookup_table', None) + + if not lookup: + return None + + decode_list: List[str] = [] + + for element in data: + decode_list.append(lookup.get(element, element)) + + return ''.join(decode_list) diff --git a/codecipher/atbs/decode/decoder.py b/codecipher/atbs/decode/decoder.py new file mode 100644 index 0000000..58adf31 --- /dev/null +++ b/codecipher/atbs/decode/decoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class decoder with cipher ATBS logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.idecoder import IDecoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.atbs.config import ATBSConfig +from codecipher.atbs.decode.decode_algorithm import DecodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Decoder(IDecoder): + ''' + Defines class Decoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher ATBS logic. + | _strategy - Strategy for cipher ATBS logic. + | _decoded_data - Container for decoded data. + :methods: + | decoded_data - Property method for getting decoded data. + | decode - Decode data by cipher ATBS logic. + ''' + + _config: IConfig = field(default_factory=ATBSConfig) + _strategy: IAlgorithm[IConfig] = field(default_factory=DecodeAlgorithm) + _decoded_data: Optional[str] = field(default=None, init=False) + + @property + def decoded_data(self) -> Optional[str]: + ''' + Property method for getting decoded data. + + :return: Decoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._decoded_data + + def decode(self, data: Optional[str] = None) -> bool: + ''' + Decode data by cipher ATBS logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher ATBS logic with configuration parameters + self._decoded_data = self._strategy.execute(data, self._config) + + if not self._decoded_data: + return False + + return True diff --git a/codecipher/atbs/encode.py b/codecipher/atbs/encode.py deleted file mode 100644 index d35d989..0000000 --- a/codecipher/atbs/encode.py +++ /dev/null @@ -1,97 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - encode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class AlephTawBetShinEncode with attribute(s) and method(s). - Creates encode class with backend API. -''' - -import sys -from dataclasses import dataclass, field -from typing import List, Optional - -try: - from codecipher.atbs.lookup_table import LOOKUP_TABLE -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class AlephTawBetShinEncode: - ''' - Defines class AlephTawBetShinEncode with attribute(s) and method(s). - Creates encode class with backend API. - - It defines: - - :attributes: - | _encode_data - Data encode container. - :methods: - | encode_data - Property methods for encode data. - | encode - Encode data to AlephTawBetShin format. - ''' - - _encode_data: Optional[str] = field(default=None) - - @property - def encode_data(self) -> Optional[str]: - ''' - Property method for getting encode data. - - :return: Encoded data | None - :rtype: - :exceptions: None - ''' - return self._encode_data - - @encode_data.setter - def encode_data(self, encode_data: Optional[str]) -> None: - ''' - Property method for setting encode data. - - :param encode_data: Encode data | None - :type encode_data: - :return: None - :exceptions: None - ''' - if bool(encode_data): - self._encode_data = encode_data - - def encode(self, data: Optional[str]) -> None: - ''' - Encoding data to AlephTawBetShin format. - - :param data: Data which should be encoded | None - :type data: - :return: None - :exceptions: None - ''' - if bool(data): - encode_list: List[str] = [] - for element in data: - encode_list.append(LOOKUP_TABLE[element]) - self._encode_data = ''.join(encode_list) diff --git a/codecipher/atbs/encode/.editorconfig b/codecipher/atbs/encode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/atbs/encode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/atbs/encode/__init__.py b/codecipher/atbs/encode/__init__.py new file mode 100644 index 0000000..e7000e5 --- /dev/null +++ b/codecipher/atbs/encode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.atbs.encode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/atbs/encode/encode_algorithm.py b/codecipher/atbs/encode/encode_algorithm.py new file mode 100644 index 0000000..e3ef3de --- /dev/null +++ b/codecipher/atbs/encode/encode_algorithm.py @@ -0,0 +1,89 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class EncodeAlgorithm with default cipher ATBS implementation. +''' + +from typing import Dict, List, Optional +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.atbs.config import ATBSConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class EncodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class EncodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher ATBS. + :methods: + | __init__ - Initializes EncodeAlgorithm constructor. + | encoded_data - Property method for getting encoded data. + | encode - Execute cipher ATBS logic. + ''' + + def __init__(self) -> None: + ''' + Initializes EncodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher ATBS logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or ATBSConfig() + + if not self.__config: + return None + + lookup: Optional[Dict[str, str]] = getattr(self.__config, 'lookup_table', None) + + if not lookup: + return None + + encode_list: List[str] = [] + + for element in data: + encode_list.append(lookup.get(element, element)) + + return ''.join(encode_list) diff --git a/codecipher/atbs/encode/encoder.py b/codecipher/atbs/encode/encoder.py new file mode 100644 index 0000000..d33efdc --- /dev/null +++ b/codecipher/atbs/encode/encoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class encoder with cipher ATBS logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.atbs.config import ATBSConfig +from codecipher.atbs.encode.encode_algorithm import EncodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Encoder(IEncoder): + ''' + Defines class Encoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher ATBS logic. + | _strategy - Strategy for cipher ATBS logic. + | _encoded_data - Container for encoded data. + :methods: + | encoded_data - Property method for getting encoded data. + | encode - Encode data by cipher ATBS logic. + ''' + + _config: IConfig = field(default_factory=ATBSConfig) + _strategy: IAlgorithm[IConfig] = field(default_factory=EncodeAlgorithm) + _encoded_data: Optional[str] = field(default=None, init=False) + + @property + def encoded_data(self) -> Optional[str]: + ''' + Property method for getting encoded data. + + :return: Encoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._encoded_data + + def encode(self, data: Optional[str] = None) -> bool: + ''' + Encode data by cipher ATBS logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher ATBS logic with configuration parameters + self._encoded_data = self._strategy.execute(data, self._config) + + if not self._encoded_data: + return False + + return True diff --git a/codecipher/atbs/engine.py b/codecipher/atbs/engine.py new file mode 100644 index 0000000..d5dfe0a --- /dev/null +++ b/codecipher/atbs/engine.py @@ -0,0 +1,126 @@ +# -*- coding: UTF-8 -*- + +''' +Module + atbs.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class ATBS with attribute(s) and method(s). +''' + +from typing import Optional, List +from codecipher.abstracts.icipher_engine import ICipherEngine +from codecipher.abstracts.iconfig import IConfig +from codecipher.abstracts.ivalidation_engine import IValidationEngine +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.idecoder import IDecoder +from codecipher.validation.validation_engine import ValidationEngine +from codecipher.atbs.encode.encoder import Encoder +from codecipher.atbs.decode.decoder import Decoder +from codecipher.atbs.config import ATBSConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class ATBS(ICipherEngine): + ''' + Defines class ATBS with attribute(s) and method(s). + + It defines: + + :attributes: + | __config - Configuration for cipher ATBS. + | __validation_engine - Engine for data validation. + | __encoder - Encoder for cipher ATBS. + | __decoder - Decoder for cipher ATBS. + :methods: + | __init__ - Initializes ATBS constructor. + | encode - Encoding data to ATBS format. + | decode - Decoding data from ATBS format. + ''' + + def __init__( + self, + config: Optional[IConfig] = None, + validation_engine: Optional[IValidationEngine] = None, + encoder: Optional[IEncoder] = None, + decoder: Optional[IDecoder] = None, + ) -> None: + ''' + Initializes ATBS constructor. + + :param config: Configuration for cipher ATBS | None + :type config: + :param validation_engine: Engine for data validation | None + :type validation_engine: + :param encoder: Encoder for cipher | None + :type encoder: + :param decoder: Decoder for cipher | None + :type decoder: + :exceptions: None + ''' + # Dependency injection or use default implementations + self.__config: IConfig = config or ATBSConfig() + self.__validation_engine: IValidationEngine = validation_engine or ValidationEngine( + allowed_chars=self.__config.allowed_chars + ) + self.__encoder: IEncoder = encoder or Encoder(_config=self.__config) + self.__decoder: IDecoder = decoder or Decoder(_config=self.__config) + + def encode(self, data: Optional[str]) -> Optional[str]: + ''' + Encoding data to ATBS format. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking and validation data for process of encoding + if not data or not self.__validation_engine.is_valid(data): + return None + + # Checking process of encoding data + if not self.__encoder.encode(data): + return None + + return self.__encoder.encoded_data + + def decode(self, data: Optional[str]) -> Optional[str]: + ''' + Decoding data from ATBS format. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking data and process of decoding data + if not data or not self.__decoder.decode(data): + return None + + # Checking and validation decoded data + if not self.__validation_engine.is_valid(self.__decoder.decoded_data): + return None + + return self.__decoder.decoded_data diff --git a/codecipher/b64/__init__.py b/codecipher/b64/__init__.py index 303c96e..2a040c1 100644 --- a/codecipher/b64/__init__.py +++ b/codecipher/b64/__init__.py @@ -16,47 +16,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . Info - Defines class B64 with attribute(s) and method(s). - Creates container class with aggregate backend API. + Initialization for codecipher.b64 package. ''' -import sys from typing import List -try: - from codecipher.b64.encode import B64Encode - from codecipher.b64.decode import B64Decode -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' - - -class B64(B64Encode, B64Decode): - ''' - Defines class B64 with attribute(s) and method(s). - Creates container class with aggregate backend API. - - It defines: - - :attributes: - | None. - :methods: - | __init__ - Initials B64 constructor. - ''' - - def __init__(self) -> None: - ''' - Initials B64 constructor. - - :exceptions: None - ''' - super().__init__() diff --git a/codecipher/b64/config.py b/codecipher/b64/config.py new file mode 100644 index 0000000..bbea682 --- /dev/null +++ b/codecipher/b64/config.py @@ -0,0 +1,73 @@ +# -*- coding: UTF-8 -*- + +''' +Module + config.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines configuration for cipher B64 logic. +''' + +from typing import Dict, List, Optional, Set +from string import ascii_lowercase, ascii_uppercase, digits, whitespace +from dataclasses import dataclass, field +from codecipher.abstracts.iconfig import IConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass(frozen=True) +class B64Config(IConfig): + ''' + Defines class B64Config with attribute(s). + + It defines: + + :attributes: + | key - Controls transformation during encoding and decoding (default None). + | shift - Controls transformation during encoding and decoding (default 0). + | upper_case_offset - Offset for uppercase letters (default 0). + | lower_case_offset - Offset for lowercase letters (default 0). + | lower_case_base - Base index for lowercase letters (default 0). + | numeric_base - Base index for numeric characters (default 0). + | alphabet_size - Size of alphabet (default 0). + | code_splitter - Code splitter (default None). + | altchars - Defines replacements for '+' and '/' (default None). + | padding - Adds to end '=' (default True). + | allowed_chars - Strict set of allowed characters (default ascii_lowercase + ascii_uppercase + digits + whitespace). + | lookup_table - Lookup table for cipher set (default None). + :methods: None + ''' + + key: Optional[str] = None + shift: int = 0 + upper_case_offset: int = 0 + lower_case_offset: int = 0 + lower_case_base: int = 0 + numeric_base: int = 0 + alphabet_size: int = 0 + code_splitter: Optional[str] = None + altchars: Optional[bytes] = None + padding: bool = True + allowed_chars: Optional[Set[str]] = field( + default_factory=lambda: set(ascii_lowercase + ascii_uppercase + digits + whitespace) + ) + lookup_table: Optional[Dict[str, str]] = None diff --git a/codecipher/b64/decode.py b/codecipher/b64/decode.py deleted file mode 100644 index f272424..0000000 --- a/codecipher/b64/decode.py +++ /dev/null @@ -1,88 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - decode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class AlephTawBetShinDecode with attribute(s) and method(s). - Creates decode class with backend API. -''' - -from dataclasses import dataclass, field -from base64 import b64decode -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class B64Decode: - ''' - Defines class AlephTawBetShinDecode with attribute(s) and method(s). - Creates decode class with backend API. - - It defines: - - :attributes: - | _decode_data - Data decode container. - :methods: - | decode_data - Property methods for decode data. - | decode - Decode data from AlephTawBetShin format. - ''' - - _decode_data: Optional[str] = field(default=None) - - @property - def decode_data(self) -> Optional[str]: - ''' - Property method for getting decode data. - - :return: Decode data in str format | None - :rtype: - :exceptions: None - ''' - return self._decode_data - - @decode_data.setter - def decode_data(self, decode_data: Optional[str]) -> None: - ''' - Property method for setting decode data. - - :param decode_data: Decoded data - :type decode_data: - :return: None - :exceptions: None - ''' - if bool(decode_data): - self._decode_data = decode_data - - def decode(self, data: Optional[str]) -> None: - ''' - Decoding data from AlephTawBetShin format. - - :param data: Data which should be decoded | None - :type data: - :return: None - :exceptions: None - ''' - if bool(data): - self._decode_data = b64decode(data).decode() diff --git a/codecipher/b64/decode/.editorconfig b/codecipher/b64/decode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/b64/decode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/b64/decode/__init__.py b/codecipher/b64/decode/__init__.py new file mode 100644 index 0000000..aa911a8 --- /dev/null +++ b/codecipher/b64/decode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.b64.decode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/b64/decode/decode_algorithm.py b/codecipher/b64/decode/decode_algorithm.py new file mode 100644 index 0000000..4e18699 --- /dev/null +++ b/codecipher/b64/decode/decode_algorithm.py @@ -0,0 +1,95 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class DecodeAlgorithm with default cipher B64 implementation. +''' + +from typing import List, Optional +from base64 import b64decode +from binascii import Error +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.b64.config import B64Config + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class DecodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class DecodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher B64. + :methods: + | __init__ - Initializes DecodeAlgorithm constructor. + | encoded_data - Property method for getting decoded data. + | encode - Execute cipher B64 logic. + ''' + + def __init__(self) -> None: + ''' + Initializes DecodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher B64 logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or B64Config() + + if not self.__config: + return None + + if not self.__config.padding: + missing_padding: int = len(data) % 4 + + if missing_padding: + data += '=' * (4 - missing_padding) + + try: + decoded_bytes: bytes = b64decode(data.encode('utf-8'), altchars=self.__config.altchars) + + return decoded_bytes.decode('utf-8') + except (Error, UnicodeDecodeError, ValueError): + # binascii->Error: invalid base64 input + # UnicodeDecodeError: decoded bytes are not valid UTF-8 + # ValueError: defensive catch for other decode-related errors + return None diff --git a/codecipher/b64/decode/decoder.py b/codecipher/b64/decode/decoder.py new file mode 100644 index 0000000..9ba7e67 --- /dev/null +++ b/codecipher/b64/decode/decoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class decoder with cipher B64 logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.idecoder import IDecoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.b64.config import B64Config +from codecipher.b64.decode.decode_algorithm import DecodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Decoder(IDecoder): + ''' + Defines class Decoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher B64 logic. + | _strategy - Strategy for cipher B64 logic. + | _decoded_data - Container for decoded data. + :methods: + | decoded_data - Property method for getting decoded data. + | decode - Decode data by cipher B64 logic. + ''' + + _config: IConfig = field(default_factory=B64Config) + _strategy: IAlgorithm[IConfig] = field(default_factory=DecodeAlgorithm) + _decoded_data: Optional[str] = field(default=None, init=False) + + @property + def decoded_data(self) -> Optional[str]: + ''' + Property method for getting decoded data. + + :return: Decoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._decoded_data + + def decode(self, data: Optional[str] = None) -> bool: + ''' + Decode data by cipher B64 logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher B64 logic with configuration parameters + self._decoded_data = self._strategy.execute(data, self._config) + + if not self._decoded_data: + return False + + return True diff --git a/codecipher/b64/encode.py b/codecipher/b64/encode.py deleted file mode 100644 index cdb7e42..0000000 --- a/codecipher/b64/encode.py +++ /dev/null @@ -1,88 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - encode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class B64Encode with attribute(s) and method(s). - Creates encode class with backend API. -''' - -from dataclasses import dataclass, field -from base64 import b64encode -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class B64Encode: - ''' - Defines class B64Encode with attribute(s) and method(s). - Creates encode class with backend API. - - It defines: - - :attributes: - | _encode_data - Data encode container. - :methods: - | encode_data - Property methods for encode data. - | encode - Encode data to AlephTawBetShin format. - ''' - - _encode_data: Optional[str] = field(default=None) - - @property - def encode_data(self) -> Optional[str]: - ''' - Property method for getting encode data. - - :return: Encoded data | None - :rtype: - :exceptions: None - ''' - return self._encode_data - - @encode_data.setter - def encode_data(self, encode_data: Optional[str]) -> None: - ''' - Property method for setting encode data. - - :param encode_data: Encode data | None - :type encode_data: - :return: None - :exceptions: None - ''' - if bool(encode_data): - self._encode_data = encode_data - - def encode(self, data: Optional[str]) -> None: - ''' - Encoding data to AlephTawBetShin format. - - :param data: Data which should be encoded | None - :type data: - :return: None - :exceptions: None - ''' - if bool(data): - self._encode_data = (b64encode(data.encode())).decode() diff --git a/codecipher/b64/encode/.editorconfig b/codecipher/b64/encode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/b64/encode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/b64/encode/__init__.py b/codecipher/b64/encode/__init__.py new file mode 100644 index 0000000..c31003f --- /dev/null +++ b/codecipher/b64/encode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.b64.encode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/b64/encode/encode_algorithm.py b/codecipher/b64/encode/encode_algorithm.py new file mode 100644 index 0000000..720cbc2 --- /dev/null +++ b/codecipher/b64/encode/encode_algorithm.py @@ -0,0 +1,86 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class EncodeAlgorithm with default cipher B64 implementation. +''' + +from typing import List, Optional +from base64 import b64encode +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.b64.config import B64Config + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class EncodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class EncodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher B64. + :methods: + | __init__ - Initializes EncodeAlgorithm constructor. + | encoded_data - Property method for getting encoded data. + | encode - Execute cipher B64 logic. + ''' + + def __init__(self) -> None: + ''' + Initializes EncodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher B64 logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or B64Config() + + if not self.__config: + return None + + encoded_bytes: bytes = b64encode(data.encode('utf-8'), altchars=self.__config.altchars) + encoded_str: str = encoded_bytes.decode('utf-8') + + if not self.__config.padding: + encoded_str = encoded_str.rstrip('=') + + return encoded_str diff --git a/codecipher/b64/encode/encoder.py b/codecipher/b64/encode/encoder.py new file mode 100644 index 0000000..7cd36db --- /dev/null +++ b/codecipher/b64/encode/encoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class encoder with cipher B64 logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.b64.config import B64Config +from codecipher.b64.encode.encode_algorithm import EncodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Encoder(IEncoder): + ''' + Defines class Encoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher B64 logic. + | _strategy - Strategy for cipher B64 logic. + | _encoded_data - Container for encoded data. + :methods: + | encoded_data - Property method for getting encoded data. + | encode - Encode data by cipher B64 logic. + ''' + + _config: IConfig = field(default_factory=B64Config) + _strategy: IAlgorithm[IConfig] = field(default_factory=EncodeAlgorithm) + _encoded_data: Optional[str] = field(default=None, init=False) + + @property + def encoded_data(self) -> Optional[str]: + ''' + Property method for getting encoded data. + + :return: Encoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._encoded_data + + def encode(self, data: Optional[str] = None) -> bool: + ''' + Encode data by cipher B64 logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher B64 logic with configuration parameters + self._encoded_data = self._strategy.execute(data, self._config) + + if not self._encoded_data: + return False + + return True diff --git a/codecipher/b64/engine.py b/codecipher/b64/engine.py new file mode 100644 index 0000000..c75ef1b --- /dev/null +++ b/codecipher/b64/engine.py @@ -0,0 +1,126 @@ +# -*- coding: UTF-8 -*- + +''' +Module + b64.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class B64 with attribute(s) and method(s). +''' + +from typing import List, Optional +from codecipher.abstracts.icipher_engine import ICipherEngine +from codecipher.abstracts.iconfig import IConfig +from codecipher.abstracts.ivalidation_engine import IValidationEngine +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.idecoder import IDecoder +from codecipher.validation.validation_engine import ValidationEngine +from codecipher.b64.encode.encoder import Encoder +from codecipher.b64.decode.decoder import Decoder +from codecipher.b64.config import B64Config + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class B64(ICipherEngine): + ''' + Defines class B64 with attribute(s) and method(s). + + It defines: + + :attributes: + | __config - Configuration for cipher B64. + | __validation_engine - Engine for data validation. + | __encoder - Encoder for cipher B64. + | __decoder - Decoder for cipher B64. + :methods: + | __init__ - Initializes B64 constructor. + | encode - Encoding data to B64 format. + | decode - Decoding data from B64 format. + ''' + + def __init__( + self, + config: Optional[IConfig] = None, + validation_engine: Optional[IValidationEngine] = None, + encoder: Optional[IEncoder] = None, + decoder: Optional[IDecoder] = None, + ) -> None: + ''' + Initializes B64 constructor. + + :param config: Configuration for cipher B64 | None + :type config: + :param validation_engine: Engine for data validation | None + :type validation_engine: + :param encoder: Encoder for cipher | None + :type encoder: + :param decoder: Decoder for cipher | None + :type decoder: + :exceptions: None + ''' + # Dependency injection or use default implementations + self.__config: IConfig = config or B64Config() + self.__validation_engine: IValidationEngine = validation_engine or ValidationEngine( + allowed_chars=self.__config.allowed_chars + ) + self.__encoder: IEncoder = encoder or Encoder(_config=self.__config) + self.__decoder: IDecoder = decoder or Decoder(_config=self.__config) + + def encode(self, data: Optional[str]) -> Optional[str]: + ''' + Encoding data to B64 format. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking and validation data for process of encoding + if not data or not self.__validation_engine.is_valid(data): + return None + + # Checking process of encoding data + if not self.__encoder.encode(data): + return None + + return self.__encoder.encoded_data + + def decode(self, data: Optional[str]) -> Optional[str]: + ''' + Decoding data from B64 format. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking data and process of decoding data + if not data or not self.__decoder.decode(data): + return None + + # Checking and validation decoded data + if not self.__validation_engine.is_valid(self.__decoder.decoded_data): + return None + + return self.__decoder.decoded_data diff --git a/codecipher/caesar/__init__.py b/codecipher/caesar/__init__.py index eaec418..85e76d8 100644 --- a/codecipher/caesar/__init__.py +++ b/codecipher/caesar/__init__.py @@ -16,47 +16,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . Info - Defines class Caesar with attribute(s) and method(s). - Creates container class with aggregate backend API. + Initialization for codecipher.caesar package. ''' -import sys from typing import List -try: - from codecipher.caesar.encode import CaesarEncode - from codecipher.caesar.decode import CaesarDecode -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' - - -class Caesar(CaesarEncode, CaesarDecode): - ''' - Defines class Caesar with attribute(s) and method(s). - Creates container class with aggregate backend API. - - It defines: - - :attributes: - | None. - :methods: - | __init__ - Initials Caesar constructor. - ''' - - def __init__(self) -> None: - ''' - Initials Caesar constructor. - - :exceptions: None - ''' - super().__init__() diff --git a/codecipher/caesar/config.py b/codecipher/caesar/config.py new file mode 100644 index 0000000..66c5f03 --- /dev/null +++ b/codecipher/caesar/config.py @@ -0,0 +1,73 @@ +# -*- coding: UTF-8 -*- + +''' +Module + config.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines configuration for cipher CAESAR logic. +''' + +from typing import Dict, List, Optional, Set +from string import ascii_lowercase, ascii_uppercase, digits, whitespace +from dataclasses import dataclass, field +from codecipher.abstracts.iconfig import IConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass(frozen=True) +class CaesarConfig(IConfig): + ''' + Defines class CaesarConfig with attribute(s). + + It defines: + + :attributes: + | key - Controls transformation during encoding and decoding (default None). + | shift - Controls transformation during encoding and decoding (default 3). + | upper_case_offset - Offset for uppercase letters (default 0). + | lower_case_offset - Offset for lowercase letters (default 0). + | lower_case_base - Base index for lowercase letters (default 0). + | numeric_base - Base index for numeric characters (default 0). + | alphabet_size - Size of alphabet (default 0). + | code_splitter - Code splitter (default None). + | altchars - Defines replacements for '+' and '/' (default None). + | padding - Adds to end '=' (default False). + | allowed_chars - Strict set of allowed characters (default ascii_lowercase + ascii_uppercase + digits + whitespace). + | lookup_table - Lookup table for cipher set (default None). + :methods: None + ''' + + key: Optional[str] = None + shift: int = 3 + upper_case_offset: int = 0 + lower_case_offset: int = 0 + lower_case_base: int = 0 + numeric_base: int = 0 + alphabet_size: int = 0 + code_splitter: Optional[str] = None + altchars: Optional[bytes] = None + padding: bool = False + allowed_chars: Optional[Set[str]] = field( + default_factory=lambda: set(ascii_lowercase + ascii_uppercase + digits + whitespace) + ) + lookup_table: Optional[Dict[str, str]] = None diff --git a/codecipher/caesar/decode.py b/codecipher/caesar/decode.py deleted file mode 100644 index 65bd07a..0000000 --- a/codecipher/caesar/decode.py +++ /dev/null @@ -1,110 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - decode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class CaesarDecode with attribute(s) and method(s). - Creates decode class with backend API. -''' - -from dataclasses import dataclass, field -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class CaesarDecode: - ''' - Defines class CaesarDecode with attribute(s) and method(s). - Creates decode class with backend API. - - It defines: - - :attributes: - | _decode_data - Data decode container. - :methods: - | decode_data - Property methods for decode data. - | decode - Decode data from Caesar format. - ''' - - _decode_data: Optional[str] = field(default=None) - - @property - def decode_data(self) -> Optional[str]: - ''' - Property method for getting decode data. - - :return: Decode data in str format | None - :rtype: - :exceptions: None - ''' - return self._decode_data - - @decode_data.setter - def decode_data(self, decode_data: Optional[str]) -> None: - ''' - Property method for setting decode data. - - :param decode_data: Decoded data | None - :type decode_data: - :return: None - :exceptions: None - ''' - if bool(decode_data): - self._decode_data = decode_data - - def decode( - self, data: Optional[str], shift_counter: Optional[int] - ) -> None: - ''' - Decoding data from Caesar format. - - :param data: Data which should be decoded | None - :type data: - :param shift_counter: Defining the shift count | None - :type shift_counter: - :return: None - :exceptions: None - ''' - if bool(data) and bool(shift_counter): - decode_list: List[str] = [] - for element in data: - if element.isspace() or element.isnumeric(): - decode_list.append(element) - continue - element_index: Optional[int] = None - new_index: Optional[int] = None - new_unicode: Optional[int] = None - new_character: Optional[str] = None - if element.isupper(): - element_index = ord(element) - ord('A') - new_index = (element_index - shift_counter) % 26 - new_unicode = new_index + ord('A') - else: - element_index = ord(element) - ord('a') - new_index = (element_index - shift_counter) % 26 - new_unicode = new_index + ord('a') - new_character = chr(new_unicode) - decode_list.append(new_character) - self._decode_data = ''.join(decode_list) diff --git a/codecipher/caesar/decode/.editorconfig b/codecipher/caesar/decode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/caesar/decode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/caesar/decode/__init__.py b/codecipher/caesar/decode/__init__.py new file mode 100644 index 0000000..ee659fa --- /dev/null +++ b/codecipher/caesar/decode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.caesar.decode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/caesar/decode/decode_algorithm.py b/codecipher/caesar/decode/decode_algorithm.py new file mode 100644 index 0000000..cdf144d --- /dev/null +++ b/codecipher/caesar/decode/decode_algorithm.py @@ -0,0 +1,105 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class DecodeAlgorithm with default cipher CAESAR implementation. +''' + +from typing import List, Optional +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.caesar.config import CaesarConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class DecodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class DecodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher CAESAR. + :methods: + | __init__ - Initializes DecodeAlgorithm constructor. + | encoded_data - Property method for getting decoded data. + | encode - Execute cipher CAESAR logic. + ''' + + def __init__(self) -> None: + ''' + Initializes DecodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher CAESAR logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or CaesarConfig() + + if not self.__config: + return None + + shift: int = getattr(self.__config, 'shift', 3) + decode_list: List[str] = [] + + for element in data: + + if not (('a' <= element <= 'z') or ('A' <= element <= 'Z')): + decode_list.append(element) + continue + + element_index: Optional[int] = None + new_index: Optional[int] = None + new_unicode: Optional[int] = None + new_character: Optional[str] = None + + if element.isupper(): + element_index = ord(element) - ord('A') + new_index = (element_index - shift) % 26 + new_unicode = new_index + ord('A') + else: + element_index = ord(element) - ord('a') + new_index = (element_index - shift) % 26 + new_unicode = new_index + ord('a') + + new_character = chr(new_unicode) + decode_list.append(new_character) + + return ''.join(decode_list) diff --git a/codecipher/caesar/decode/decoder.py b/codecipher/caesar/decode/decoder.py new file mode 100644 index 0000000..609dfcc --- /dev/null +++ b/codecipher/caesar/decode/decoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class decoder with cipher CAESAR logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.idecoder import IDecoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.caesar.config import CaesarConfig +from codecipher.caesar.decode.decode_algorithm import DecodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Decoder(IDecoder): + ''' + Defines class Decoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher CAESAR logic. + | _strategy - Strategy for cipher CAESAR logic. + | _decoded_data - Container for decoded data. + :methods: + | decoded_data - Property method for getting decoded data. + | decode - Decode data by cipher CAESAR logic. + ''' + + _config: IConfig = field(default_factory=CaesarConfig) + _strategy: IAlgorithm[IConfig] = field(default_factory=DecodeAlgorithm) + _decoded_data: Optional[str] = field(default=None, init=False) + + @property + def decoded_data(self) -> Optional[str]: + ''' + Property method for getting decoded data. + + :return: Decoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._decoded_data + + def decode(self, data: Optional[str] = None) -> bool: + ''' + Decode data by cipher CAESAR logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher CAESAR logic with configuration parameters + self._decoded_data = self._strategy.execute(data, self._config) + + if not self._decoded_data: + return False + + return True diff --git a/codecipher/caesar/encode.py b/codecipher/caesar/encode.py deleted file mode 100644 index ed6b2c5..0000000 --- a/codecipher/caesar/encode.py +++ /dev/null @@ -1,110 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - encode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class CaesarEncode with attribute(s) and method(s). - Creates encode class with backend API. -''' - -from dataclasses import dataclass, field -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class CaesarEncode: - ''' - Defines class CaesarEncode with attribute(s) and method(s). - Creates encode class with backend API. - - It defines: - - :attributes: - | _encode_data - Data encode container. - :methods: - | encode_data - Property methods for encode data. - | encode - Encode data to Caesar format. - ''' - - _encode_data: Optional[str] = field(default=None) - - @property - def encode_data(self) -> Optional[str]: - ''' - Property method for getting encode data. - - :return: Encoded data | None - :rtype: - :exceptions: None - ''' - return self._encode_data - - @encode_data.setter - def encode_data(self, encode_data: Optional[str]) -> None: - ''' - Property method for setting encode data. - - :param encode_data: Encode data | None - :type encode_data: - :return: None - :exceptions: None - ''' - if bool(encode_data): - self._encode_data = encode_data - - def encode( - self, data: Optional[str], shift_counter: Optional[int] - ) -> None: - ''' - Encoding data to Caesar format. - - :param data: Data which should be encoded | None - :type data: - :param shift_counter: Defining the shift count | None - :type shift_counter: - :return: None - :exceptions: None - ''' - if bool(data) and bool(shift_counter): - encode_list: List[str] = [] - for element in data: - if element.isspace() or element.isnumeric(): - encode_list.append(element) - continue - element_index: Optional[int] = None - new_index: Optional[int] = None - new_unicode: Optional[int] = None - new_character: Optional[str] = None - if element.isupper(): - element_index = ord(element) - ord('A') - new_index = (element_index + shift_counter) % 26 - new_unicode = new_index + ord('A') - else: - element_index = ord(element) - ord('a') - new_index = (element_index + shift_counter) % 26 - new_unicode = new_index + ord('a') - new_character = chr(new_unicode) - encode_list.append(new_character) - self._encode_data = ''.join(encode_list) diff --git a/codecipher/caesar/encode/.editorconfig b/codecipher/caesar/encode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/caesar/encode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/caesar/encode/__init__.py b/codecipher/caesar/encode/__init__.py new file mode 100644 index 0000000..e1af9bf --- /dev/null +++ b/codecipher/caesar/encode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.caesar.encode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/caesar/encode/encode_algorithm.py b/codecipher/caesar/encode/encode_algorithm.py new file mode 100644 index 0000000..81442d4 --- /dev/null +++ b/codecipher/caesar/encode/encode_algorithm.py @@ -0,0 +1,105 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class EncodeAlgorithm with default cipher CAESAR implementation. +''' + +from typing import List, Optional +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.caesar.config import CaesarConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class EncodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class EncodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher CAESAR. + :methods: + | __init__ - Initializes EncodeAlgorithm constructor. + | encoded_data - Property method for getting encoded data. + | encode - Execute cipher CAESAR logic. + ''' + + def __init__(self) -> None: + ''' + Initializes EncodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher CAESAR logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or CaesarConfig() + + if not self.__config: + return None + + shift: int = getattr(self.__config, 'shift', 3) + encode_list: List[str] = [] + + for element in data: + + if not (('a' <= element <= 'z') or ('A' <= element <= 'Z')): + encode_list.append(element) + continue + + element_index: Optional[int] = None + new_index: Optional[int] = None + new_unicode: Optional[int] = None + new_character: Optional[str] = None + + if element.isupper(): + element_index = ord(element) - ord('A') + new_index = (element_index + shift) % 26 + new_unicode = new_index + ord('A') + else: + element_index = ord(element) - ord('a') + new_index = (element_index + shift) % 26 + new_unicode = new_index + ord('a') + + new_character = chr(new_unicode) + encode_list.append(new_character) + + return ''.join(encode_list) diff --git a/codecipher/caesar/encode/encoder.py b/codecipher/caesar/encode/encoder.py new file mode 100644 index 0000000..b9498a8 --- /dev/null +++ b/codecipher/caesar/encode/encoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class encoder with cipher CAESAR logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.caesar.config import CaesarConfig +from codecipher.caesar.encode.encode_algorithm import EncodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Encoder(IEncoder): + ''' + Defines class Encoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher CAESAR logic. + | _strategy - Strategy for cipher CAESAR logic. + | _encoded_data - Container for encoded data. + :methods: + | encoded_data - Property method for getting encoded data. + | encode - Encode data by cipher CAESAR logic. + ''' + + _config: IConfig = field(default_factory=CaesarConfig) + _strategy: IAlgorithm[IConfig] = field(default_factory=EncodeAlgorithm) + _encoded_data: Optional[str] = field(default=None, init=False) + + @property + def encoded_data(self) -> Optional[str]: + ''' + Property method for getting encoded data. + + :return: Encoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._encoded_data + + def encode(self, data: Optional[str] = None) -> bool: + ''' + Encode data by cipher CAESAR logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher CAESAR logic with configuration parameters + self._encoded_data = self._strategy.execute(data, self._config) + + if not self._encoded_data: + return False + + return True diff --git a/codecipher/caesar/engine.py b/codecipher/caesar/engine.py new file mode 100644 index 0000000..1920184 --- /dev/null +++ b/codecipher/caesar/engine.py @@ -0,0 +1,126 @@ +# -*- coding: UTF-8 -*- + +''' +Module + caesar.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class Caesar with attribute(s) and method(s). +''' + +from typing import List, Optional +from codecipher.abstracts.icipher_engine import ICipherEngine +from codecipher.abstracts.iconfig import IConfig +from codecipher.abstracts.ivalidation_engine import IValidationEngine +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.idecoder import IDecoder +from codecipher.validation.validation_engine import ValidationEngine +from codecipher.caesar.encode.encoder import Encoder +from codecipher.caesar.decode.decoder import Decoder +from codecipher.caesar.config import CaesarConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class Caesar(ICipherEngine): + ''' + Defines class Caesar with attribute(s) and method(s). + + It defines: + + :attributes: + | __config - Configuration for cipher CAESAR. + | __validation_engine - Engine for data validation. + | __encoder - Encoder for cipher CAESAR. + | __decoder - Decoder for cipher CAESAR. + :methods: + | __init__ - Initializes Caesar constructor. + | encode - Encoding data to CAESAR format. + | decode - Decoding data from CAESAR format. + ''' + + def __init__( + self, + config: Optional[IConfig] = None, + validation_engine: Optional[IValidationEngine] = None, + encoder: Optional[IEncoder] = None, + decoder: Optional[IDecoder] = None, + ) -> None: + ''' + Initializes Caesar constructor. + + :param config: Configuration for cipher CAESAR | None + :type config: + :param validation_engine: Engine for data validation | None + :type validation_engine: + :param encoder: Encoder for cipher | None + :type encoder: + :param decoder: Decoder for cipher | None + :type decoder: + :exceptions: None + ''' + # Dependency injection or use default implementations + self.__config: IConfig = config or CaesarConfig() + self.__validation_engine: IValidationEngine = validation_engine or ValidationEngine( + allowed_chars=self.__config.allowed_chars + ) + self.__encoder: IEncoder = encoder or Encoder(_config=self.__config) + self.__decoder: IDecoder = decoder or Decoder(_config=self.__config) + + def encode(self, data: Optional[str]) -> Optional[str]: + ''' + Encoding data to CAESAR format. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking and validation data for process of encoding + if not data or not self.__validation_engine.is_valid(data): + return None + + # Checking process of encoding data + if not self.__encoder.encode(data): + return None + + return self.__encoder.encoded_data + + def decode(self, data: Optional[str]) -> Optional[str]: + ''' + Decoding data from CAESAR format. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking data and process of decoding data + if not data or not self.__decoder.decode(data): + return None + + # Checking and validation decoded data + if not self.__validation_engine.is_valid(self.__decoder.decoded_data): + return None + + return self.__decoder.decoded_data diff --git a/codecipher/validation/__init__.py b/codecipher/validation/__init__.py new file mode 100644 index 0000000..8b0312e --- /dev/null +++ b/codecipher/validation/__init__.py @@ -0,0 +1,32 @@ + +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.validation package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/validation/character_validator.py b/codecipher/validation/character_validator.py new file mode 100644 index 0000000..ab471b6 --- /dev/null +++ b/codecipher/validation/character_validator.py @@ -0,0 +1,74 @@ +# -*- coding: UTF-8 -*- + +''' +Module + character_validator.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class CharacterValidator for strict chipher character validation. +''' + +from typing import List, Optional, Set +from codecipher.abstracts.icharacter_validator import ICharacterValidator + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class CharacterValidator(ICharacterValidator): + ''' + Defines class CharacterValidator with attribute(s) and method(s). + Creates character validator with cipher character set. + + It defines: + + :attributes: + | __allowed_chars - Strict cipher character set. + :methods: + | __init__ - Initializes CharacterValidator constructor. + | is_valid_char - Validates if a single character belongs to cipher charcter set. + ''' + + def __init__(self, allowed_chars: Optional[Set[str]] = None) -> None: + ''' + Initializes CharacterValidator constructor. + + :param allowed_chars: Strict cipher character set. + :type allowed_chars: + :param allow_space: Whether to allow space character | False + :type allow_space: + :exceptions: None + ''' + self.__allowed_chars: Optional[Set[str]] = allowed_chars + + def is_valid_char(self, character: Optional[str]) -> bool: + ''' + Validates if a single character belongs to cipher charcter set. + + :param character: Single character in string format to be validated + :type character: + :return: True (valid) | False (invalid) + :rtype: + :exceptions: None + ''' + if not self.__allowed_chars or not character or len(character) != 1: + return False + + return character in self.__allowed_chars diff --git a/codecipher/validation/data_validator.py b/codecipher/validation/data_validator.py new file mode 100644 index 0000000..ec347e3 --- /dev/null +++ b/codecipher/validation/data_validator.py @@ -0,0 +1,82 @@ +# -*- coding: UTF-8 -*- + +''' +Module + data_validator.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class DataValidator for strict chipher data validation. +''' + +from typing import List, Optional, Set +from codecipher.abstracts.idata_validator import IDataValidator +from codecipher.abstracts.icharacter_validator import ICharacterValidator +from codecipher.validation.character_validator import CharacterValidator + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class DataValidator(IDataValidator): + ''' + Defines class DataValidator with attribute(s) and method(s). + Creates data validator with cipher character validator. + + It defines: + + :attributes: + | __char_validator - Validator for individual characters. + :methods: + | __init__ - Initializes DataValidator constructor. + | is_valid - Validates if data belongs to cipher data set. + ''' + + def __init__( + self, + char_validator: Optional[ICharacterValidator] = None, + allowed_chars: Optional[Set[str]] = None + ) -> None: + ''' + Initializes DataValidator constructor. + + :param char_validator: Character validator instance | None + :type char_validator: + :param allowed_chars: Strict cipher character set | None + :type allowed_chars: + :exceptions: None + ''' + self.__char_validator: ICharacterValidator = char_validator or CharacterValidator( + allowed_chars=allowed_chars + ) + + def is_valid(self, data: Optional[str]) -> bool: + ''' + Validates if data belongs to cipher data set. + + :param data: Data which should to be validated | None + :type data: + :return: True (valid) | False (invalid) + :rtype: + :exceptions: None + ''' + if not data: + return False + + return all(self.__char_validator.is_valid_char(element) for element in data) diff --git a/codecipher/validation/validation_engine.py b/codecipher/validation/validation_engine.py new file mode 100644 index 0000000..f0924a5 --- /dev/null +++ b/codecipher/validation/validation_engine.py @@ -0,0 +1,98 @@ +# -*- coding: UTF-8 -*- + +''' +Module + validation_engine.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class ValidationEngine for managing multiple cipher data validators. +''' + +from typing import List, Optional, Set +from codecipher.abstracts.ivalidation_engine import IValidationEngine +from codecipher.abstracts.idata_validator import IDataValidator +from codecipher.validation.data_validator import DataValidator + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class ValidationEngine(IValidationEngine): + ''' + Defines class ValidationEngine with attribute(s) and method(s). + Creates validation engine with options to add multiple data validators. + + It defines: + + :attributes: + | __validators - List of registered data validators. + :methods: + | __init__ - Initializes ValidationEngine constructor. + | add_validator - Adds a new data validator to the validation engine. + | is_valid - Validates data using all registered validators. + ''' + + def __init__( + self, + validators: Optional[List[IDataValidator]] = None, + allowed_chars: Optional[Set[str]] = None + ) -> None: + ''' + Initializes ValidationEngine constructor. + + :param validators: Initial list of validators | None + :type validators: + :param allowed_chars: Strict cipher character set | None + :type allowed_chars: + :exceptions: None + ''' + self.__validators: List[IDataValidator] = validators or [ + DataValidator(allowed_chars=allowed_chars) + ] + + def add_validator(self, validator: Optional[IDataValidator]) -> None: + ''' + Adds a new data validator to the validation engine. + + :param validator: Data validator instance to be added. + :type validator: + :return: None + :exceptions: None + ''' + if validator and validator not in self.__validators: + self.__validators.append(validator) + + def is_valid(self, data: Optional[str]) -> bool: + ''' + Validates data using all registered validators. + + :param data: Data which should to be validated | None + :type data: + :return: True (valid) | False (invalid) + :rtype: + :exceptions: None + ''' + if not data: + return False + + if not self.__validators: + return False + + return all(validator.is_valid(data) for validator in self.__validators) diff --git a/codecipher/vernam/__init__.py b/codecipher/vernam/__init__.py index da48a55..a1e1d92 100644 --- a/codecipher/vernam/__init__.py +++ b/codecipher/vernam/__init__.py @@ -16,47 +16,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . Info - Defines class Vernam with attribute(s) and method(s). - Creates container class with aggregate backend API. + Initialization for codecipher.vernam package. ''' -import sys from typing import List -try: - from codecipher.vernam.encode import VernamEncode - from codecipher.vernam.decode import VernamDecode -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' - - -class Vernam(VernamEncode, VernamDecode): - ''' - Defines class Vernam with attribute(s) and method(s). - Creates container class with aggregate backend API. - - It defines: - - :attributes: - | None. - :methods: - | __init__ - Initials Vernam constructor. - ''' - - def __init__(self) -> None: - ''' - Initials Vernam constructor. - - :exceptions: None - ''' - super().__init__() diff --git a/codecipher/vernam/config.py b/codecipher/vernam/config.py new file mode 100644 index 0000000..98c7bbe --- /dev/null +++ b/codecipher/vernam/config.py @@ -0,0 +1,73 @@ +# -*- coding: UTF-8 -*- + +''' +Module + config.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines configuration for cipher VERNAM logic. +''' + +from typing import Dict, List, Optional, Set +from string import ascii_lowercase, ascii_uppercase, digits, whitespace +from dataclasses import dataclass, field +from codecipher.abstracts.iconfig import IConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass(frozen=True) +class VernamConfig(IConfig): + ''' + Defines class VernamConfig with attribute(s). + + It defines: + + :attributes: + | key - Controls transformation during encoding and decoding (default "MyVerNamKey"). + | shift - Controls transformation during encoding and decoding (default 0). + | upper_case_offset - Offset for uppercase letters (default 0). + | lower_case_offset - Offset for lowercase letters (default 96). + | lower_case_base - Base index for lowercase letters (default 0). + | numeric_base - Base index for numeric characters (default 0). + | alphabet_size - Size of alphabet (default 26). + | code_splitter - Code splitter (default None). + | altchars - Defines replacements for '+' and '/' (default None). + | padding - Adds to end '=' (default False). + | allowed_chars - Strict set of allowed characters (default ascii_lowercase + ascii_uppercase + digits + whitespace). + | lookup_table - Lookup table for cipher set (default None). + :methods: None + ''' + + key: Optional[str] = "MyVerNamKey" + shift: int = 0 + upper_case_offset: int = 0 + lower_case_offset: int = 96 + lower_case_base: int = 0 + numeric_base: int = 0 + alphabet_size: int = 26 + code_splitter: Optional[str] = None + altchars: Optional[bytes] = None + padding: bool = False + allowed_chars: Optional[Set[str]] = field( + default_factory=lambda: set(ascii_lowercase + ascii_uppercase + digits + whitespace) + ) + lookup_table: Optional[Dict[str, str]] = None diff --git a/codecipher/vernam/decode.py b/codecipher/vernam/decode.py deleted file mode 100644 index a97eb1f..0000000 --- a/codecipher/vernam/decode.py +++ /dev/null @@ -1,104 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - decode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class VernamDecode with attribute(s) and method(s). - Creates decode class with backend API. -''' - -from dataclasses import dataclass, field -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class VernamDecode: - ''' - Defines class VernamDecode with attribute(s) and method(s). - Creates decode class with backend API. - - It defines: - - :attributes: - | _decode_data - Data decode container. - :methods: - | decode_data - Property methods for decode data. - | decode - Decode data from Vernam format. - ''' - - _decode_data: Optional[str] = field(default=None) - - @property - def decode_data(self) -> Optional[str]: - ''' - Property method for getting decode data. - - :return: Decode data in str format | None - :rtype: - :exceptions: None - ''' - return self._decode_data - - @decode_data.setter - def decode_data(self, decode_data: Optional[str]) -> None: - ''' - Property method for setting decode data. - - :param decode_data: Decoded data | None - :type decode_data: - :return: None - :exceptions: None - ''' - if bool(decode_data): - self._decode_data = decode_data - - def decode(self, data: Optional[str], key: Optional[str]) -> None: - ''' - Decoding data from Vernam format. - - :param data: Data which should be decoded | None - :type data: - :param key: Key for decoding | None - :type key: - :return: None - :exceptions: None - ''' - if bool(data) and bool(key): - decode_list: List[str] = [] - key = (key * (len(data) // len(key))) + key[:len(data) % len(key)] - for i, element in enumerate(data): - if element.isalpha() and key[i].isalpha(): - key_code: int = ord(key[i].lower()) - 96 - code: int = ord(element.lower()) - 96 - ans: int = code - key_code + 1 - if ans < 1: - ans += 26 - if element.isupper(): - decode_list.append(chr(ans + 96).upper()) - else: - decode_list.append(chr(ans + 96)) - else: - decode_list.append(element) - self._decode_data = ''.join(decode_list) diff --git a/codecipher/vernam/decode/.editorconfig b/codecipher/vernam/decode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/vernam/decode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/vernam/decode/__init__.py b/codecipher/vernam/decode/__init__.py new file mode 100644 index 0000000..6900e6f --- /dev/null +++ b/codecipher/vernam/decode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.vernam.decode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/vernam/decode/decode_algorithm.py b/codecipher/vernam/decode/decode_algorithm.py new file mode 100644 index 0000000..35cad54 --- /dev/null +++ b/codecipher/vernam/decode/decode_algorithm.py @@ -0,0 +1,113 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class DecodeAlgorithm with default cipher VERNAM implementation. +''' + +from typing import List, Optional +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.vernam.config import VernamConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class DecodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class DecodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher VERNAM. + :methods: + | __init__ - Initializes DecodeAlgorithm constructor. + | execute - Execute cipher VERNAM logic. + ''' + + def __init__(self) -> None: + ''' + Initializes DecodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher VERNAM logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or VernamConfig() + + if not self.__config: + return None + + key: str = getattr(self.__config, 'key', 'MyVerNamKey') + + if not key: + return None + + lower_case_offset: int = getattr(self.__config, 'lower_case_offset', 96) + + if not lower_case_offset: + return None + + alphabet_size: int = getattr(self.__config, 'alphabet_size', 26) + + if not alphabet_size: + return None + + decode_list: List[str] = [] + key = (key * (len(data) // len(key))) + key[:len(data) % len(key)] + + for i, element in enumerate(data): + + if element.isalpha() and key[i].isalpha(): + key_code: int = ord(key[i].lower()) - lower_case_offset + code: int = ord(element.lower()) - lower_case_offset + ans: int = code - key_code + 1 + + if ans < 1: + ans += alphabet_size + if element.isupper(): + decode_list.append(chr(ans + lower_case_offset).upper()) + else: + decode_list.append(chr(ans + lower_case_offset)) + + else: + decode_list.append(element) + + return ''.join(decode_list) diff --git a/codecipher/vernam/decode/decoder.py b/codecipher/vernam/decode/decoder.py new file mode 100644 index 0000000..8a5ecee --- /dev/null +++ b/codecipher/vernam/decode/decoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class decoder with cipher VERNAM logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.idecoder import IDecoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.vernam.config import VernamConfig +from codecipher.vernam.decode.decode_algorithm import DecodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Decoder(IDecoder): + ''' + Defines class Decoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher VERNAM logic. + | _strategy - Strategy for cipher VERNAM logic. + | _decoded_data - Container for decoded data. + :methods: + | decoded_data - Property method for getting decoded data. + | decode - Decode data by cipher VERNAM logic. + ''' + + _config: IConfig = field(default_factory=VernamConfig) + _strategy: IAlgorithm[IConfig] = field(default_factory=DecodeAlgorithm) + _decoded_data: Optional[str] = field(default=None, init=False) + + @property + def decoded_data(self) -> Optional[str]: + ''' + Property method for getting decoded data. + + :return: Decoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._decoded_data + + def decode(self, data: Optional[str] = None) -> bool: + ''' + Decode data by cipher VERNAM logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher VERNAM logic with configuration parameters + self._decoded_data = self._strategy.execute(data, self._config) + + if not self._decoded_data: + return False + + return True diff --git a/codecipher/vernam/encode.py b/codecipher/vernam/encode.py deleted file mode 100644 index f69b023..0000000 --- a/codecipher/vernam/encode.py +++ /dev/null @@ -1,104 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - encode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class VernamEncode with attribute(s) and method(s). - Creates encode class with backend API. -''' - -from dataclasses import dataclass, field -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class VernamEncode: - ''' - Defines class VernamEncode with attribute(s) and method(s). - Creates encode class with backend API. - - It defines: - - :attributes: - | _encode_data - Data encode container. - :methods: - | encode_data - Property methods for encode data. - | encode - Encode data to Vernam format. - ''' - - _encode_data: Optional[str] = field(default=None) - - @property - def encode_data(self) -> Optional[str]: - ''' - Property method for getting encode data. - - :return: Encoded data | None - :rtype: - :exceptions: None - ''' - return self._encode_data - - @encode_data.setter - def encode_data(self, encode_data: Optional[str]) -> None: - ''' - Property method for setting encode data. - - :param encode_data: Encode data | None - :type encode_data: - :return: None - :exceptions: None - ''' - if bool(encode_data): - self._encode_data = encode_data - - def encode(self, data: Optional[str], key: Optional[str]) -> None: - ''' - Encoding data to Vernam format. - - :param data: Data which should be encoded | None - :type data: - :param key: Key for encoding | None - :type key: - :return: None - :exceptions: None - ''' - if bool(data) and bool(key): - encode_list: List[str] = [] - key = (key * (len(data) // len(key))) + key[:len(data) % len(key)] - for i, element in enumerate(data): - if element.isalpha() and key[i].isalpha(): - key_code: int = ord(key[i].lower()) - 96 - text_code: int = ord(element.lower()) - 96 - ans: int = text_code + key_code - 1 - if ans > 26: - ans -= 26 - if element.isupper(): - encode_list.append(chr(ans + 96).upper()) - else: - encode_list.append(chr(ans + 96)) - else: - encode_list.append(element) - self._encode_data = ''.join(encode_list) diff --git a/codecipher/vernam/encode/.editorconfig b/codecipher/vernam/encode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/vernam/encode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/vernam/encode/__init__.py b/codecipher/vernam/encode/__init__.py new file mode 100644 index 0000000..b929541 --- /dev/null +++ b/codecipher/vernam/encode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.vernam.encode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/vernam/encode/encode_algorithm.py b/codecipher/vernam/encode/encode_algorithm.py new file mode 100644 index 0000000..dec7f8f --- /dev/null +++ b/codecipher/vernam/encode/encode_algorithm.py @@ -0,0 +1,113 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class EncodeAlgorithm with default cipher VERNAM implementation. +''' + +from typing import List, Optional +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.vernam.config import VernamConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class EncodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class EncodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher VERNAM. + :methods: + | __init__ - Initializes EncodeAlgorithm constructor. + | execute - Execute cipher VERNAM logic. + ''' + + def __init__(self) -> None: + ''' + Initializes EncodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher VERNAM logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or VernamConfig() + + if not self.__config: + return None + + key: str = getattr(self.__config, 'key', 'MyVerNamKey') + + if not key: + return None + + lower_case_offset: int = getattr(self.__config, 'lower_case_offset', 96) + + if not lower_case_offset: + return None + + alphabet_size: int = getattr(self.__config, 'alphabet_size', 26) + + if not alphabet_size: + return None + + encode_list: List[str] = [] + key = (key * (len(data) // len(key))) + key[:len(data) % len(key)] + + for i, element in enumerate(data): + + if element.isalpha() and key[i].isalpha(): + key_code: int = ord(key[i].lower()) - lower_case_offset + text_code: int = ord(element.lower()) - lower_case_offset + ans: int = text_code + key_code - 1 + + if ans > alphabet_size: + ans -= alphabet_size + if element.isupper(): + encode_list.append(chr(ans + lower_case_offset).upper()) + else: + encode_list.append(chr(ans + lower_case_offset)) + + else: + encode_list.append(element) + + return ''.join(encode_list) diff --git a/codecipher/vernam/encode/encoder.py b/codecipher/vernam/encode/encoder.py new file mode 100644 index 0000000..3e3aa23 --- /dev/null +++ b/codecipher/vernam/encode/encoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class encoder with cipher VERNAM logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.vernam.config import VernamConfig +from codecipher.vernam.encode.encode_algorithm import EncodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Encoder(IEncoder): + ''' + Defines class Encoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher VERNAM logic. + | _strategy - Strategy for cipher VERNAM logic. + | _encoded_data - Container for encoded data. + :methods: + | encoded_data - Property method for getting encoded data. + | encode - Encode data by cipher VERNAM logic. + ''' + + _config: IConfig = field(default_factory=VernamConfig) + _strategy: IAlgorithm[IConfig] = field(default_factory=EncodeAlgorithm) + _encoded_data: Optional[str] = field(default=None, init=False) + + @property + def encoded_data(self) -> Optional[str]: + ''' + Property method for getting encoded data. + + :return: Encoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._encoded_data + + def encode(self, data: Optional[str] = None) -> bool: + ''' + Encode data by cipher VERNAM logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher VERNAM logic with configuration parameters + self._encoded_data = self._strategy.execute(data, self._config) + + if not self._encoded_data: + return False + + return True diff --git a/codecipher/vernam/engine.py b/codecipher/vernam/engine.py new file mode 100644 index 0000000..55d3d5c --- /dev/null +++ b/codecipher/vernam/engine.py @@ -0,0 +1,126 @@ +# -*- coding: UTF-8 -*- + +''' +Module + vernam.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class Vernam with attribute(s) and method(s). +''' + +from typing import List, Optional +from codecipher.abstracts.icipher_engine import ICipherEngine +from codecipher.abstracts.iconfig import IConfig +from codecipher.abstracts.ivalidation_engine import IValidationEngine +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.idecoder import IDecoder +from codecipher.validation.validation_engine import ValidationEngine +from codecipher.vernam.encode.encoder import Encoder +from codecipher.vernam.decode.decoder import Decoder +from codecipher.vernam.config import VernamConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class Vernam(ICipherEngine): + ''' + Defines class Vernam with attribute(s) and method(s). + + It defines: + + :attributes: + | __config - Configuration for cipher VERNAM. + | __validation_engine - Engine for data validation. + | __encoder - Encoder for cipher VERNAM. + | __decoder - Decoder for cipher VERNAM. + :methods: + | __init__ - Initializes Vernam constructor. + | encode - Encoding data to VERNAM format. + | decode - Decoding data from VERNAM format. + ''' + + def __init__( + self, + config: Optional[IConfig] = None, + validation_engine: Optional[IValidationEngine] = None, + encoder: Optional[IEncoder] = None, + decoder: Optional[IDecoder] = None, + ) -> None: + ''' + Initializes Vernam constructor. + + :param config: Configuration for cipher VERNAM | None + :type config: + :param validation_engine: Engine for data validation | None + :type validation_engine: + :param encoder: Encoder for cipher | None + :type encoder: + :param decoder: Decoder for cipher | None + :type decoder: + :exceptions: None + ''' + # Dependency injection or use default implementations + self.__config: IConfig = config or VernamConfig() + self.__validation_engine: IValidationEngine = validation_engine or ValidationEngine( + allowed_chars=self.__config.allowed_chars + ) + self.__encoder: IEncoder = encoder or Encoder(_config=self.__config) + self.__decoder: IDecoder = decoder or Decoder(_config=self.__config) + + def encode(self, data: Optional[str]) -> Optional[str]: + ''' + Encoding data to VERNAM format. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking and validation data for process of encoding + if not data or not self.__validation_engine.is_valid(data): + return None + + # Checking process of encoding data + if not self.__encoder.encode(data): + return None + + return self.__encoder.encoded_data + + def decode(self, data: Optional[str]) -> Optional[str]: + ''' + Decoding data from VERNAM format. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking data and process of decoding data + if not data or not self.__decoder.decode(data): + return None + + # Checking and validation decoded data + if not self.__validation_engine.is_valid(self.__decoder.decoded_data): + return None + + return self.__decoder.decoded_data diff --git a/codecipher/vigenere/__init__.py b/codecipher/vigenere/__init__.py index 4081792..5f2b4a2 100644 --- a/codecipher/vigenere/__init__.py +++ b/codecipher/vigenere/__init__.py @@ -16,48 +16,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . Info - Defines class Vigenere with attribute(s) and method(s). - Creates container class with aggregate backend API. + Initialization for codecipher.vigenere package. ''' -import sys from typing import List -try: - from codecipher.vigenere.encode import VigenereEncode - from codecipher.vigenere.decode import VigenereDecode - from codecipher.vigenere.key_generator import KeyGenerator -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' - - -class Vigenere(VigenereEncode, VigenereDecode, KeyGenerator): - ''' - Defines class Vigenere with attribute(s) and method(s). - Creates container class with aggregate backend API. - - It defines: - - :attributes: - | None. - :methods: - | __init__ - Initials Vigenere constructor. - ''' - - def __init__(self) -> None: - ''' - Initials Vigenere constructor. - - :exceptions: None - ''' - super().__init__() diff --git a/codecipher/vigenere/config.py b/codecipher/vigenere/config.py new file mode 100644 index 0000000..7a8cace --- /dev/null +++ b/codecipher/vigenere/config.py @@ -0,0 +1,73 @@ +# -*- coding: UTF-8 -*- + +''' +Module + config.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines configuration for cipher VIGENERE logic. +''' + +from typing import Dict, List, Optional, Set +from string import ascii_lowercase, ascii_uppercase, digits, whitespace +from dataclasses import dataclass, field +from codecipher.abstracts.iconfig import IConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass(frozen=True) +class VigenereConfig(IConfig): + ''' + Defines class VigenereConfig with attribute(s). + + It defines: + + :attributes: + | key - Controls transformation during encoding and decoding (default 'MyVigenereKey'). + | shift - Controls transformation during encoding and decoding (default 0). + | upper_case_offset - Offset for uppercase letters (default 0). + | lower_case_offset - Offset for lowercase letters (default 0). + | lower_case_base - Base index for lowercase letters (default 0). + | numeric_base - Base index for numeric characters (default 0). + | alphabet_size - Size of alphabet (default 0). + | code_splitter - Code splitter (default None). + | altchars - Defines replacements for '+' and '/' (default None). + | padding - Adds to end '=' (default False). + | allowed_chars - Strict set of allowed characters (default ascii_lowercase + ascii_uppercase + digits + whitespace). + | lookup_table - Lookup table for cipher set (default None). + :methods: None + ''' + + key: Optional[str] = 'MyVigenereKey' + shift: int = 0 + upper_case_offset: int = 0 + lower_case_offset: int = 0 + lower_case_base: int = 0 + numeric_base: int = 0 + alphabet_size: int = 0 + code_splitter: Optional[str] = None + altchars: Optional[bytes] = None + padding: bool = False + allowed_chars: Optional[Set[str]] = field( + default_factory=lambda: set(ascii_lowercase + ascii_uppercase + digits + whitespace) + ) + lookup_table: Optional[Dict[str, str]] = None diff --git a/codecipher/vigenere/decode.py b/codecipher/vigenere/decode.py deleted file mode 100644 index d569da4..0000000 --- a/codecipher/vigenere/decode.py +++ /dev/null @@ -1,129 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - decode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class VigenereDecode with attribute(s) and method(s). - Creates decode class with backend API. -''' - -import sys -from dataclasses import dataclass, field -from typing import List, Optional - -try: - from codecipher.vigenere.lookup_table import LookUpTable -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class VigenereDecode: - ''' - Defines class VigenereDecode with attribute(s) and method(s). - Creates decode class with backend API. - - It defines: - - :attributes: - | _decode_data - Data decode container. - :methods: - | decode_data - Property methods for decode data. - | _split_data - Splitting data for decoding. - | decode - Decode data from Vigenere format. - ''' - - _decode_data: Optional[str] = field(default=None) - - @property - def decode_data(self) -> Optional[str]: - ''' - Property method for getting decode data. - - :return: Decode data in str format | None - :rtype: - :exceptions: None - ''' - return self._decode_data - - @decode_data.setter - def decode_data(self, decode_data_val: Optional[str]) -> None: - ''' - Property method for setting decode data. - - :param decode_data_val: Decoded data | None - :type decode_data_val: - :return: None - :exceptions: None - ''' - if bool(decode_data_val): - self._decode_data = decode_data_val - - def _split_data_decode( - self, data_to_decode: Optional[str], key: Optional[str] - ) -> List[str]: - ''' - Splitting data for decoding. - - :param data_to_decode: Data which should be decoded | None - :type data_to_decode: - :param key: Key for decoding | None - :type key: - :return: List with data for decoding - :rtype: - :exceptions: None - ''' - elements: List[str] = [] - if bool(data_to_decode) and bool(key): - for i in range(0, len(data_to_decode), len(key)): - elements.append(data_to_decode[i: i + len(key)]) - return elements - - def decode( - self, data_to_decode: Optional[str], key: Optional[str] - ) -> None: - ''' - Decoding data from Vigenere format. - - :param data_to_decode: Data which should be decoded - :type data_to_decode: - :param key: Key for decoding - :type key: - :return: None - :exceptions: None - ''' - if bool(data_to_decode) and bool(key): - decode_list: List[str] = [] - for element in self._split_data_decode(data_to_decode, key): - for index, letter in enumerate(element): - process_index: int = ( - LookUpTable.LETTER_TO_INDEX[letter] - - LookUpTable.LETTER_TO_INDEX[key[index]] - ) % len(LookUpTable.ALPHANUM) - decode_list.append( - LookUpTable.INDEX_TO_LETTER[process_index] - ) - self._decode_data = ''.join(decode_list) diff --git a/codecipher/vigenere/decode/.editorconfig b/codecipher/vigenere/decode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/vigenere/decode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/vigenere/decode/__init__.py b/codecipher/vigenere/decode/__init__.py new file mode 100644 index 0000000..5e9bb4c --- /dev/null +++ b/codecipher/vigenere/decode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.vigenere.decode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/vigenere/decode/decode_algorithm.py b/codecipher/vigenere/decode/decode_algorithm.py new file mode 100644 index 0000000..751e9ac --- /dev/null +++ b/codecipher/vigenere/decode/decode_algorithm.py @@ -0,0 +1,115 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class DecodeAlgorithm with default cipher VIGENERE implementation. +''' + +from typing import Dict, List, Optional, Set +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.vigenere.config import VigenereConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class DecodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class DecodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher VIGENERE. + :methods: + | __init__ - Initializes DecodeAlgorithm constructor. + | _split_data_decode - Splitting data for process of decoding. + | execute - Execute cipher VIGENERE logic. + ''' + + def __init__(self) -> None: + ''' + Initializes DecodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def _split_data_decode(self, data_to_decode: Optional[str], key: Optional[str]) -> List[str]: + ''' + Splitting data for process of decoding. + + :param data_to_decode: Data which should to be decoded | None + :type data_to_decode: + :param key: Key for process of decoding | None + :type key: + :return: List with data for process of decoding + :rtype: + :exceptions: None + ''' + elements: List[str] = [] + + if data_to_decode and key: + for i in range(0, len(data_to_decode), len(key)): + elements.append(data_to_decode[i: i + len(key)]) + + return elements + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher VIGENERE logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or VigenereConfig() + + if not self.__config: + return None + + key: str = getattr(self.__config, 'key', 'MyVigenereKey') + allowed_chars: Optional[Set[str]] = getattr(self.__config, 'allowed_chars') + + if not allowed_chars: + return None + + alphanum: str = ''.join(sorted(allowed_chars)) + letter_to_index: Dict[str, int] = dict(zip(alphanum, range(len(alphanum)))) + index_to_letter: Dict[int, str] = dict(zip(range(len(alphanum)), alphanum)) + decode_list: List[str] = [] + + for element in self._split_data_decode(data, key): + for index, letter in enumerate(element): + process_index: int = (letter_to_index[letter] - letter_to_index[key[index]]) % len(alphanum) + decode_list.append(index_to_letter[process_index]) + + return ''.join(decode_list) diff --git a/codecipher/vigenere/decode/decoder.py b/codecipher/vigenere/decode/decoder.py new file mode 100644 index 0000000..f0efaf1 --- /dev/null +++ b/codecipher/vigenere/decode/decoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + decoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class decoder with cipher VIGENERE logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.idecoder import IDecoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.vigenere.config import VigenereConfig +from codecipher.vigenere.decode.decode_algorithm import DecodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Decoder(IDecoder): + ''' + Defines class Decoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher VIGENERE logic. + | _strategy - Strategy for cipher VIGENERE logic. + | _decoded_data - Container for decoded data. + :methods: + | decoded_data - Property method for getting decoded data. + | decode - Decode data by cipher VIGENERE logic. + ''' + + _config: IConfig = field(default_factory=VigenereConfig) + _strategy: IAlgorithm[IConfig] = field(default_factory=DecodeAlgorithm) + _decoded_data: Optional[str] = field(default=None, init=False) + + @property + def decoded_data(self) -> Optional[str]: + ''' + Property method for getting decoded data. + + :return: Decoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._decoded_data + + def decode(self, data: Optional[str] = None) -> bool: + ''' + Decode data by cipher VIGENERE logic. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher VIGENERE logic with configuration parameters + self._decoded_data = self._strategy.execute(data, self._config) + + if not self._decoded_data: + return False + + return True diff --git a/codecipher/vigenere/encode.py b/codecipher/vigenere/encode.py deleted file mode 100644 index e5c96dd..0000000 --- a/codecipher/vigenere/encode.py +++ /dev/null @@ -1,129 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - encode.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class VigenereEncode with attribute(s) and method(s). - Creates encode class with backend API. -''' - -import sys -from dataclasses import dataclass, field -from typing import List, Optional - -try: - from codecipher.vigenere.lookup_table import LookUpTable -except ImportError as ats_error_message: # pragma: no cover - # Force exit python ####################################################### - sys.exit(f'\n{__file__}\n{ats_error_message}\n') # pragma: no cover - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class VigenereEncode: - ''' - Defines class VigenereEncode with attribute(s) and method(s). - Creates encode class with backend API. - - It defines: - - :attributes: - | _encode_data - Data encode container. - :methods: - | encode_data - Property methods for encode data. - | _split_data - Splitting data for encoding. - | encode - Encode data to Vigenere format. - ''' - - _encode_data: Optional[str] = field(default=None) - - @property - def encode_data(self) -> Optional[str]: - ''' - Property method for getting encode data. - - :return: Encoded data | None - :rtype: - :exceptions: None - ''' - return self._encode_data - - @encode_data.setter - def encode_data(self, encode_data_val: Optional[str]) -> None: - ''' - Property method for setting encode data. - - :param encode_data_val: Encode data | None - :type encode_data_val: - :return: None - :exceptions: None - ''' - if bool(encode_data_val): - self._encode_data = encode_data_val - - def _split_data_encode( - self, data_to_encode: Optional[str], key: Optional[str] - ) -> List[str]: - ''' - Splitting data for encoding. - - :param data_to_encode: Data which should be encoded | None - :type data_to_encode: - :param key: Key for encoding | None - :type key: - :return: List with data for encoding - :rtype: - :exceptions: None - ''' - elements: List[str] = [] - if bool(data_to_encode) and bool(key): - for i in range(0, len(data_to_encode), len(key)): - elements.append(data_to_encode[i: i + len(key)]) - return elements - - def encode( - self, data_to_encode: Optional[str], key: Optional[str] - ) -> None: - ''' - Encoding data to Vigenere format. - - :param data_to_encode: Data which should be encoded | None - :type data_to_encode: - :param key: Key for encoding | None - :type key: - :return: None - :exceptions: None - ''' - if bool(data_to_encode) and bool(key): - encode_list: List[str] = [] - for element in self._split_data_encode(data_to_encode, key): - for index, letter in enumerate(element): - process_index: int = ( - LookUpTable.LETTER_TO_INDEX[letter] + - LookUpTable.LETTER_TO_INDEX[key[index]] - ) % len(LookUpTable.ALPHANUM) - encode_list.append( - LookUpTable.INDEX_TO_LETTER[process_index] - ) - self._encode_data = ''.join(encode_list) diff --git a/codecipher/vigenere/encode/.editorconfig b/codecipher/vigenere/encode/.editorconfig new file mode 100755 index 0000000..f228d58 --- /dev/null +++ b/codecipher/vigenere/encode/.editorconfig @@ -0,0 +1,3 @@ +[**.py] +indent_style = tab +tab_width = 4 \ No newline at end of file diff --git a/codecipher/vigenere/encode/__init__.py b/codecipher/vigenere/encode/__init__.py new file mode 100644 index 0000000..bd1e0cc --- /dev/null +++ b/codecipher/vigenere/encode/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: UTF-8 -*- + +''' +Module + __init__.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Initialization for codecipher.vigenere.encode package. +''' + +from typing import List + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' diff --git a/codecipher/vigenere/encode/encode_algorithm.py b/codecipher/vigenere/encode/encode_algorithm.py new file mode 100644 index 0000000..19437ac --- /dev/null +++ b/codecipher/vigenere/encode/encode_algorithm.py @@ -0,0 +1,115 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encode_algorithm.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class EncodeAlgorithm with default cipher VIGENERE implementation. +''' + +from typing import Dict, List, Optional, Set +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.vigenere.config import VigenereConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class EncodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class EncodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher VIGENERE. + :methods: + | __init__ - Initializes EncodeAlgorithm constructor. + | _split_data_encode - Splitting data for process of encoding. + | execute - Execute cipher VIGENERE logic. + ''' + + def __init__(self) -> None: + ''' + Initializes EncodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + + def _split_data_encode(self, data_to_encode: Optional[str], key: Optional[str]) -> List[str]: + ''' + Splitting data for process of encoding. + + :param data_to_encode: Data which should to be encoded | None + :type data_to_encode: + :param key: Key for process of encoding | None + :type key: + :return: List with data for process of encoding + :rtype: + :exceptions: None + ''' + elements: List[str] = [] + + if data_to_encode and key: + for i in range(0, len(data_to_encode), len(key)): + elements.append(data_to_encode[i: i + len(key)]) + + return elements + + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher VIGENERE logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :param config: Configuration for cipher | None + :type config: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + if not data: + return None + + self.__config = config or VigenereConfig() + + if not self.__config: + return None + + key: str = getattr(self.__config, 'key', 'MyVigenereKey') + allowed_chars: Optional[Set[str]] = getattr(self.__config, 'allowed_chars') + + if not allowed_chars: + return None + + alphanum: str = ''.join(sorted(allowed_chars)) + letter_to_index: Dict[str, int] = dict(zip(alphanum, range(len(alphanum)))) + index_to_letter: Dict[int, str] = dict(zip(range(len(alphanum)), alphanum)) + encode_list: List[str] = [] + + for element in self._split_data_encode(data, key): + for index, letter in enumerate(element): + process_index: int = (letter_to_index[letter] + letter_to_index[key[index]]) % len(alphanum) + encode_list.append(index_to_letter[process_index]) + + return ''.join(encode_list) diff --git a/codecipher/vigenere/encode/encoder.py b/codecipher/vigenere/encode/encoder.py new file mode 100644 index 0000000..5bb80bd --- /dev/null +++ b/codecipher/vigenere/encode/encoder.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- + +''' +Module + encoder.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Creates class encoder with cipher VIGENERE logic. +''' + +from dataclasses import dataclass, field +from typing import List, Optional +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.ialgorithm import IAlgorithm +from codecipher.abstracts.iconfig import IConfig +from codecipher.vigenere.config import VigenereConfig +from codecipher.vigenere.encode.encode_algorithm import EncodeAlgorithm + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +@dataclass +class Encoder(IEncoder): + ''' + Defines class Encoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher VIGENERE logic. + | _strategy - Strategy for cipher VIGENERE logic. + | _encoded_data - Container for encoded data. + :methods: + | encoded_data - Property method for getting encoded data. + | encode - Encode data by cipher VIGENERE logic. + ''' + + _config: IConfig = field(default_factory=VigenereConfig) + _strategy: IAlgorithm[IConfig] = field(default_factory=EncodeAlgorithm) + _encoded_data: Optional[str] = field(default=None, init=False) + + @property + def encoded_data(self) -> Optional[str]: + ''' + Property method for getting encoded data. + + :return: Encoded data in string format | None + :rtype: + :exceptions: None + ''' + return self._encoded_data + + def encode(self, data: Optional[str] = None) -> bool: + ''' + Encode data by cipher VIGENERE logic. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: True (success) | False (fail) + :rtype: + :exceptions: None + ''' + if not data: + return False + + # Execute cipher VIGENERE logic with configuration parameters + self._encoded_data = self._strategy.execute(data, self._config) + + if not self._encoded_data: + return False + + return True diff --git a/codecipher/vigenere/engine.py b/codecipher/vigenere/engine.py new file mode 100644 index 0000000..a887de2 --- /dev/null +++ b/codecipher/vigenere/engine.py @@ -0,0 +1,126 @@ +# -*- coding: UTF-8 -*- + +''' +Module + vigenere.py +Copyright + Copyright (C) 2021 - 2026 Vladimir Roncevic + codecipher is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + codecipher is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program. If not, see . +Info + Defines class Vigenere with attribute(s) and method(s). +''' + +from typing import List, Optional +from codecipher.abstracts.icipher_engine import ICipherEngine +from codecipher.abstracts.iconfig import IConfig +from codecipher.abstracts.ivalidation_engine import IValidationEngine +from codecipher.abstracts.iencoder import IEncoder +from codecipher.abstracts.idecoder import IDecoder +from codecipher.validation.validation_engine import ValidationEngine +from codecipher.vigenere.encode.encoder import Encoder +from codecipher.vigenere.decode.decoder import Decoder +from codecipher.vigenere.config import VigenereConfig + +__author__: str = 'Vladimir Roncevic' +__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' +__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] +__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' +__version__: str = '1.5.1' +__maintainer__: str = 'Vladimir Roncevic' +__email__: str = 'elektron.ronca@gmail.com' +__status__: str = 'Updated' + + +class Vigenere(ICipherEngine): + ''' + Defines class Vigenere with attribute(s) and method(s). + + It defines: + + :attributes: + | __config - Configuration for cipher VIGENERE. + | __validation_engine - Engine for data validation. + | __encoder - Encoder for cipher VIGENERE. + | __decoder - Decoder for cipher VIGENERE. + :methods: + | __init__ - Initializes Vigenere constructor. + | encode - Encoding data to VIGENERE format. + | decode - Decoding data from VIGENERE format. + ''' + + def __init__( + self, + config: Optional[IConfig] = None, + validation_engine: Optional[IValidationEngine] = None, + encoder: Optional[IEncoder] = None, + decoder: Optional[IDecoder] = None, + ) -> None: + ''' + Initializes Vigenere constructor. + + :param config: Configuration for cipher VIGENERE | None + :type config: + :param validation_engine: Engine for data validation | None + :type validation_engine: + :param encoder: Encoder for cipher | None + :type encoder: + :param decoder: Decoder for cipher | None + :type decoder: + :exceptions: None + ''' + # Dependency injection or use default implementations + self.__config: IConfig = config or VigenereConfig() + self.__validation_engine: IValidationEngine = validation_engine or ValidationEngine( + allowed_chars=self.__config.allowed_chars + ) + self.__encoder: IEncoder = encoder or Encoder(_config=self.__config) + self.__decoder: IDecoder = decoder or Decoder(_config=self.__config) + + def encode(self, data: Optional[str]) -> Optional[str]: + ''' + Encoding data to VIGENERE format. + + :param data: Data in string format which should to be encoded | None + :type data: + :return: Encoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking and validation data for process of encoding + if not data or not self.__validation_engine.is_valid(data): + return None + + # Checking process of encoding data + if not self.__encoder.encode(data): + return None + + return self.__encoder.encoded_data + + def decode(self, data: Optional[str]) -> Optional[str]: + ''' + Decoding data from VIGENERE format. + + :param data: Data in string format which should to be decoded | None + :type data: + :return: Decoded data in string format (success) | None (fail) + :rtype: + :exceptions: None + ''' + # Checking data and process of decoding data + if not data or not self.__decoder.decode(data): + return None + + # Checking and validation decoded data + if not self.__validation_engine.is_valid(self.__decoder.decoded_data): + return None + + return self.__decoder.decoded_data diff --git a/codecipher/vigenere/key_generator.py b/codecipher/vigenere/key_generator.py deleted file mode 100644 index 2f7aae7..0000000 --- a/codecipher/vigenere/key_generator.py +++ /dev/null @@ -1,119 +0,0 @@ -# -*- coding: UTF-8 -*- - -''' -Module - key_generator.py -Copyright - Copyright (C) 2021 - 2026 Vladimir Roncevic - codecipher is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - codecipher is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program. If not, see . -Info - Defines class KeyGenerator with attribute(s) and method(s). - Creates key generator class for Vigener encoding/decoding. -''' - -from dataclasses import dataclass, field -from typing import List, Optional - -__author__: str = 'Vladimir Roncevic' -__copyright__: str = '(C) 2026, https://electux.github.io/codecipher' -__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] -__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' -__maintainer__: str = 'Vladimir Roncevic' -__email__: str = 'elektron.ronca@gmail.com' -__status__: str = 'Updated' - - -@dataclass -class KeyGenerator: - ''' - Defines class KeyGenerator with attribute(s) and method(s). - Creates key generator class for Vigener encoding/decoding. - - It defines: - - :attributes: - | _data_len - Data length. - | _key - Key for encoding/decoding. - :methods: - | data - Property methods for data length. - | key - Property methods for key. - | generate_key - Generates key for encoding/decoding. - ''' - - _data_len: Optional[int] = field(default=None) - _key: Optional[str] = field(default=None) - - @property - def data_len(self) -> Optional[int]: - ''' - Property method for getting data length. - - :return: Data length | None - :rtype: - :exceptions: None - ''' - return self._data_len - - @data_len.setter - def data_len(self, data_length: Optional[int]) -> None: - ''' - Property method for setting data length. - - :param data: Data length | None - :type data: - :return: None - :exceptions: None - ''' - if bool(data_length): - self._data_len = data_length - - @property - def key(self) -> Optional[str]: - ''' - Property method for getting key. - - :return: Key for encoding/decoding | None - :rtype: - :exceptions: None - ''' - return self._key - - @key.setter - def key(self, key: Optional[str]) -> None: - ''' - Property method for setting key. - - :param key: Key for encoding/decoding | None - :type key: - :return: None - :exceptions: None - ''' - if bool(key): - self._key = key - - def generate_key(self) -> None: - ''' - Generates key for encoding/decoding. - - :return: None - :exceptions: None - ''' - if bool(self._key): - key_list: List[str] = list(self._key) - if bool(key_list) and bool(self._data_len): - if self._data_len == len(key_list): - pass - else: - for i in range(self._data_len - len(key_list)): - key_list.append(key_list[i % len(key_list)]) - self._key = ''. join(key_list) diff --git a/docs/build/doctrees/codecipher.a1z52n62.config.doctree b/docs/build/doctrees/codecipher.a1z52n62.config.doctree new file mode 100644 index 0000000..2ffeb7d Binary files /dev/null and b/docs/build/doctrees/codecipher.a1z52n62.config.doctree differ diff --git a/docs/build/doctrees/codecipher.a1z52n62.decode.decode_algorithm.doctree b/docs/build/doctrees/codecipher.a1z52n62.decode.decode_algorithm.doctree new file mode 100644 index 0000000..ded919b Binary files /dev/null and b/docs/build/doctrees/codecipher.a1z52n62.decode.decode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.a1z52n62.decode.decoder.doctree b/docs/build/doctrees/codecipher.a1z52n62.decode.decoder.doctree new file mode 100644 index 0000000..c7c6c4c Binary files /dev/null and b/docs/build/doctrees/codecipher.a1z52n62.decode.decoder.doctree differ diff --git a/docs/build/doctrees/codecipher.a1z52n62.decode.doctree b/docs/build/doctrees/codecipher.a1z52n62.decode.doctree index 1ac8d9c..24990f8 100644 Binary files a/docs/build/doctrees/codecipher.a1z52n62.decode.doctree and b/docs/build/doctrees/codecipher.a1z52n62.decode.doctree differ diff --git a/docs/build/doctrees/codecipher.a1z52n62.doctree b/docs/build/doctrees/codecipher.a1z52n62.doctree index a651403..f0af869 100644 Binary files a/docs/build/doctrees/codecipher.a1z52n62.doctree and b/docs/build/doctrees/codecipher.a1z52n62.doctree differ diff --git a/docs/build/doctrees/codecipher.a1z52n62.encode.doctree b/docs/build/doctrees/codecipher.a1z52n62.encode.doctree index d7e4b70..845add4 100644 Binary files a/docs/build/doctrees/codecipher.a1z52n62.encode.doctree and b/docs/build/doctrees/codecipher.a1z52n62.encode.doctree differ diff --git a/docs/build/doctrees/codecipher.a1z52n62.encode.encode_algorithm.doctree b/docs/build/doctrees/codecipher.a1z52n62.encode.encode_algorithm.doctree new file mode 100644 index 0000000..c0f1eb6 Binary files /dev/null and b/docs/build/doctrees/codecipher.a1z52n62.encode.encode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.a1z52n62.encode.encoder.doctree b/docs/build/doctrees/codecipher.a1z52n62.encode.encoder.doctree new file mode 100644 index 0000000..d8185d8 Binary files /dev/null and b/docs/build/doctrees/codecipher.a1z52n62.encode.encoder.doctree differ diff --git a/docs/build/doctrees/codecipher.a1z52n62.engine.doctree b/docs/build/doctrees/codecipher.a1z52n62.engine.doctree new file mode 100644 index 0000000..42099dc Binary files /dev/null and b/docs/build/doctrees/codecipher.a1z52n62.engine.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.doctree b/docs/build/doctrees/codecipher.abstracts.doctree new file mode 100644 index 0000000..37cebc5 Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.ialgorithm.doctree b/docs/build/doctrees/codecipher.abstracts.ialgorithm.doctree new file mode 100644 index 0000000..38ecdd3 Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.ialgorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.icharacter_validator.doctree b/docs/build/doctrees/codecipher.abstracts.icharacter_validator.doctree new file mode 100644 index 0000000..bc8552d Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.icharacter_validator.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.icipher_engine.doctree b/docs/build/doctrees/codecipher.abstracts.icipher_engine.doctree new file mode 100644 index 0000000..15604e4 Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.icipher_engine.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.iconfig.doctree b/docs/build/doctrees/codecipher.abstracts.iconfig.doctree new file mode 100644 index 0000000..b439d0a Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.iconfig.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.idata_validator.doctree b/docs/build/doctrees/codecipher.abstracts.idata_validator.doctree new file mode 100644 index 0000000..67f9ec5 Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.idata_validator.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.idecoder.doctree b/docs/build/doctrees/codecipher.abstracts.idecoder.doctree new file mode 100644 index 0000000..3bb6738 Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.idecoder.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.iencoder.doctree b/docs/build/doctrees/codecipher.abstracts.iencoder.doctree new file mode 100644 index 0000000..50c2d18 Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.iencoder.doctree differ diff --git a/docs/build/doctrees/codecipher.abstracts.ivalidation_engine.doctree b/docs/build/doctrees/codecipher.abstracts.ivalidation_engine.doctree new file mode 100644 index 0000000..c6c9a91 Binary files /dev/null and b/docs/build/doctrees/codecipher.abstracts.ivalidation_engine.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.config.doctree b/docs/build/doctrees/codecipher.atbs.config.doctree new file mode 100644 index 0000000..37f21b3 Binary files /dev/null and b/docs/build/doctrees/codecipher.atbs.config.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.decode.decode_algorithm.doctree b/docs/build/doctrees/codecipher.atbs.decode.decode_algorithm.doctree new file mode 100644 index 0000000..2013dd9 Binary files /dev/null and b/docs/build/doctrees/codecipher.atbs.decode.decode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.decode.decoder.doctree b/docs/build/doctrees/codecipher.atbs.decode.decoder.doctree new file mode 100644 index 0000000..db8dda4 Binary files /dev/null and b/docs/build/doctrees/codecipher.atbs.decode.decoder.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.decode.doctree b/docs/build/doctrees/codecipher.atbs.decode.doctree index ef53c30..f6355ca 100644 Binary files a/docs/build/doctrees/codecipher.atbs.decode.doctree and b/docs/build/doctrees/codecipher.atbs.decode.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.doctree b/docs/build/doctrees/codecipher.atbs.doctree index d07a390..908d7e4 100644 Binary files a/docs/build/doctrees/codecipher.atbs.doctree and b/docs/build/doctrees/codecipher.atbs.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.encode.doctree b/docs/build/doctrees/codecipher.atbs.encode.doctree index 382eb44..df12718 100644 Binary files a/docs/build/doctrees/codecipher.atbs.encode.doctree and b/docs/build/doctrees/codecipher.atbs.encode.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.encode.encode_algorithm.doctree b/docs/build/doctrees/codecipher.atbs.encode.encode_algorithm.doctree new file mode 100644 index 0000000..61acc62 Binary files /dev/null and b/docs/build/doctrees/codecipher.atbs.encode.encode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.encode.encoder.doctree b/docs/build/doctrees/codecipher.atbs.encode.encoder.doctree new file mode 100644 index 0000000..a4508e8 Binary files /dev/null and b/docs/build/doctrees/codecipher.atbs.encode.encoder.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.engine.doctree b/docs/build/doctrees/codecipher.atbs.engine.doctree new file mode 100644 index 0000000..8e51519 Binary files /dev/null and b/docs/build/doctrees/codecipher.atbs.engine.doctree differ diff --git a/docs/build/doctrees/codecipher.atbs.lookup_table.doctree b/docs/build/doctrees/codecipher.atbs.lookup_table.doctree deleted file mode 100644 index c432cf5..0000000 Binary files a/docs/build/doctrees/codecipher.atbs.lookup_table.doctree and /dev/null differ diff --git a/docs/build/doctrees/codecipher.b64.config.doctree b/docs/build/doctrees/codecipher.b64.config.doctree new file mode 100644 index 0000000..0810e98 Binary files /dev/null and b/docs/build/doctrees/codecipher.b64.config.doctree differ diff --git a/docs/build/doctrees/codecipher.b64.decode.decode_algorithm.doctree b/docs/build/doctrees/codecipher.b64.decode.decode_algorithm.doctree new file mode 100644 index 0000000..435de31 Binary files /dev/null and b/docs/build/doctrees/codecipher.b64.decode.decode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.b64.decode.decoder.doctree b/docs/build/doctrees/codecipher.b64.decode.decoder.doctree new file mode 100644 index 0000000..7b17f92 Binary files /dev/null and b/docs/build/doctrees/codecipher.b64.decode.decoder.doctree differ diff --git a/docs/build/doctrees/codecipher.b64.decode.doctree b/docs/build/doctrees/codecipher.b64.decode.doctree index 5d08a43..683109a 100644 Binary files a/docs/build/doctrees/codecipher.b64.decode.doctree and b/docs/build/doctrees/codecipher.b64.decode.doctree differ diff --git a/docs/build/doctrees/codecipher.b64.doctree b/docs/build/doctrees/codecipher.b64.doctree index 4b370c0..0645e56 100644 Binary files a/docs/build/doctrees/codecipher.b64.doctree and b/docs/build/doctrees/codecipher.b64.doctree differ diff --git a/docs/build/doctrees/codecipher.b64.encode.doctree b/docs/build/doctrees/codecipher.b64.encode.doctree index dff75df..880c09e 100644 Binary files a/docs/build/doctrees/codecipher.b64.encode.doctree and b/docs/build/doctrees/codecipher.b64.encode.doctree differ diff --git a/docs/build/doctrees/codecipher.b64.encode.encode_algorithm.doctree b/docs/build/doctrees/codecipher.b64.encode.encode_algorithm.doctree new file mode 100644 index 0000000..9cebe6b Binary files /dev/null and b/docs/build/doctrees/codecipher.b64.encode.encode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.b64.encode.encoder.doctree b/docs/build/doctrees/codecipher.b64.encode.encoder.doctree new file mode 100644 index 0000000..6dcfaac Binary files /dev/null and b/docs/build/doctrees/codecipher.b64.encode.encoder.doctree differ diff --git a/docs/build/doctrees/codecipher.b64.engine.doctree b/docs/build/doctrees/codecipher.b64.engine.doctree new file mode 100644 index 0000000..4a6c8ca Binary files /dev/null and b/docs/build/doctrees/codecipher.b64.engine.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.config.doctree b/docs/build/doctrees/codecipher.caesar.config.doctree new file mode 100644 index 0000000..2e4650b Binary files /dev/null and b/docs/build/doctrees/codecipher.caesar.config.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.decode.decode_algorithm.doctree b/docs/build/doctrees/codecipher.caesar.decode.decode_algorithm.doctree new file mode 100644 index 0000000..56abc8f Binary files /dev/null and b/docs/build/doctrees/codecipher.caesar.decode.decode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.decode.decoder.doctree b/docs/build/doctrees/codecipher.caesar.decode.decoder.doctree new file mode 100644 index 0000000..92280d0 Binary files /dev/null and b/docs/build/doctrees/codecipher.caesar.decode.decoder.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.decode.doctree b/docs/build/doctrees/codecipher.caesar.decode.doctree index 003657e..0cab967 100644 Binary files a/docs/build/doctrees/codecipher.caesar.decode.doctree and b/docs/build/doctrees/codecipher.caesar.decode.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.doctree b/docs/build/doctrees/codecipher.caesar.doctree index ece88da..e504e35 100644 Binary files a/docs/build/doctrees/codecipher.caesar.doctree and b/docs/build/doctrees/codecipher.caesar.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.encode.doctree b/docs/build/doctrees/codecipher.caesar.encode.doctree index 4f905fb..5bb6457 100644 Binary files a/docs/build/doctrees/codecipher.caesar.encode.doctree and b/docs/build/doctrees/codecipher.caesar.encode.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.encode.encode_algorithm.doctree b/docs/build/doctrees/codecipher.caesar.encode.encode_algorithm.doctree new file mode 100644 index 0000000..09be76d Binary files /dev/null and b/docs/build/doctrees/codecipher.caesar.encode.encode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.encode.encoder.doctree b/docs/build/doctrees/codecipher.caesar.encode.encoder.doctree new file mode 100644 index 0000000..59e2703 Binary files /dev/null and b/docs/build/doctrees/codecipher.caesar.encode.encoder.doctree differ diff --git a/docs/build/doctrees/codecipher.caesar.engine.doctree b/docs/build/doctrees/codecipher.caesar.engine.doctree new file mode 100644 index 0000000..bb5aabd Binary files /dev/null and b/docs/build/doctrees/codecipher.caesar.engine.doctree differ diff --git a/docs/build/doctrees/codecipher.doctree b/docs/build/doctrees/codecipher.doctree index d5afa07..fe9a4f8 100644 Binary files a/docs/build/doctrees/codecipher.doctree and b/docs/build/doctrees/codecipher.doctree differ diff --git a/docs/build/doctrees/codecipher.validation.character_validator.doctree b/docs/build/doctrees/codecipher.validation.character_validator.doctree new file mode 100644 index 0000000..8767c32 Binary files /dev/null and b/docs/build/doctrees/codecipher.validation.character_validator.doctree differ diff --git a/docs/build/doctrees/codecipher.validation.data_validator.doctree b/docs/build/doctrees/codecipher.validation.data_validator.doctree new file mode 100644 index 0000000..1cea831 Binary files /dev/null and b/docs/build/doctrees/codecipher.validation.data_validator.doctree differ diff --git a/docs/build/doctrees/codecipher.validation.doctree b/docs/build/doctrees/codecipher.validation.doctree new file mode 100644 index 0000000..2c565fb Binary files /dev/null and b/docs/build/doctrees/codecipher.validation.doctree differ diff --git a/docs/build/doctrees/codecipher.validation.validation_engine.doctree b/docs/build/doctrees/codecipher.validation.validation_engine.doctree new file mode 100644 index 0000000..0120baa Binary files /dev/null and b/docs/build/doctrees/codecipher.validation.validation_engine.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.config.doctree b/docs/build/doctrees/codecipher.vernam.config.doctree new file mode 100644 index 0000000..d6859e7 Binary files /dev/null and b/docs/build/doctrees/codecipher.vernam.config.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.decode.decode_algorithm.doctree b/docs/build/doctrees/codecipher.vernam.decode.decode_algorithm.doctree new file mode 100644 index 0000000..f89feb7 Binary files /dev/null and b/docs/build/doctrees/codecipher.vernam.decode.decode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.decode.decoder.doctree b/docs/build/doctrees/codecipher.vernam.decode.decoder.doctree new file mode 100644 index 0000000..e1607d4 Binary files /dev/null and b/docs/build/doctrees/codecipher.vernam.decode.decoder.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.decode.doctree b/docs/build/doctrees/codecipher.vernam.decode.doctree index 0b3d501..75cf75a 100644 Binary files a/docs/build/doctrees/codecipher.vernam.decode.doctree and b/docs/build/doctrees/codecipher.vernam.decode.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.doctree b/docs/build/doctrees/codecipher.vernam.doctree index 73f07ea..82d3fd3 100644 Binary files a/docs/build/doctrees/codecipher.vernam.doctree and b/docs/build/doctrees/codecipher.vernam.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.encode.doctree b/docs/build/doctrees/codecipher.vernam.encode.doctree index 8c79a9c..5ff8f68 100644 Binary files a/docs/build/doctrees/codecipher.vernam.encode.doctree and b/docs/build/doctrees/codecipher.vernam.encode.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.encode.encode_algorithm.doctree b/docs/build/doctrees/codecipher.vernam.encode.encode_algorithm.doctree new file mode 100644 index 0000000..034247b Binary files /dev/null and b/docs/build/doctrees/codecipher.vernam.encode.encode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.encode.encoder.doctree b/docs/build/doctrees/codecipher.vernam.encode.encoder.doctree new file mode 100644 index 0000000..3c429f2 Binary files /dev/null and b/docs/build/doctrees/codecipher.vernam.encode.encoder.doctree differ diff --git a/docs/build/doctrees/codecipher.vernam.engine.doctree b/docs/build/doctrees/codecipher.vernam.engine.doctree new file mode 100644 index 0000000..eea0a45 Binary files /dev/null and b/docs/build/doctrees/codecipher.vernam.engine.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.config.doctree b/docs/build/doctrees/codecipher.vigenere.config.doctree new file mode 100644 index 0000000..99d702d Binary files /dev/null and b/docs/build/doctrees/codecipher.vigenere.config.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.decode.decode_algorithm.doctree b/docs/build/doctrees/codecipher.vigenere.decode.decode_algorithm.doctree new file mode 100644 index 0000000..2ba9c92 Binary files /dev/null and b/docs/build/doctrees/codecipher.vigenere.decode.decode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.decode.decoder.doctree b/docs/build/doctrees/codecipher.vigenere.decode.decoder.doctree new file mode 100644 index 0000000..846a7a8 Binary files /dev/null and b/docs/build/doctrees/codecipher.vigenere.decode.decoder.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.decode.doctree b/docs/build/doctrees/codecipher.vigenere.decode.doctree index 1f64ba2..dd1a882 100644 Binary files a/docs/build/doctrees/codecipher.vigenere.decode.doctree and b/docs/build/doctrees/codecipher.vigenere.decode.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.doctree b/docs/build/doctrees/codecipher.vigenere.doctree index 569c88d..52a4db5 100644 Binary files a/docs/build/doctrees/codecipher.vigenere.doctree and b/docs/build/doctrees/codecipher.vigenere.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.encode.doctree b/docs/build/doctrees/codecipher.vigenere.encode.doctree index c231d7e..e990bb6 100644 Binary files a/docs/build/doctrees/codecipher.vigenere.encode.doctree and b/docs/build/doctrees/codecipher.vigenere.encode.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.encode.encode_algorithm.doctree b/docs/build/doctrees/codecipher.vigenere.encode.encode_algorithm.doctree new file mode 100644 index 0000000..fad679c Binary files /dev/null and b/docs/build/doctrees/codecipher.vigenere.encode.encode_algorithm.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.encode.encoder.doctree b/docs/build/doctrees/codecipher.vigenere.encode.encoder.doctree new file mode 100644 index 0000000..3f462dd Binary files /dev/null and b/docs/build/doctrees/codecipher.vigenere.encode.encoder.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.engine.doctree b/docs/build/doctrees/codecipher.vigenere.engine.doctree new file mode 100644 index 0000000..e0c186d Binary files /dev/null and b/docs/build/doctrees/codecipher.vigenere.engine.doctree differ diff --git a/docs/build/doctrees/codecipher.vigenere.key_generator.doctree b/docs/build/doctrees/codecipher.vigenere.key_generator.doctree deleted file mode 100644 index 60df58a..0000000 Binary files a/docs/build/doctrees/codecipher.vigenere.key_generator.doctree and /dev/null differ diff --git a/docs/build/doctrees/codecipher.vigenere.lookup_table.doctree b/docs/build/doctrees/codecipher.vigenere.lookup_table.doctree deleted file mode 100644 index 6700044..0000000 Binary files a/docs/build/doctrees/codecipher.vigenere.lookup_table.doctree and /dev/null differ diff --git a/docs/build/doctrees/environment.pickle b/docs/build/doctrees/environment.pickle index 213c2d0..0828f6d 100644 Binary files a/docs/build/doctrees/environment.pickle and b/docs/build/doctrees/environment.pickle differ diff --git a/docs/build/doctrees/index.doctree b/docs/build/doctrees/index.doctree index 9d8d107..a460355 100644 Binary files a/docs/build/doctrees/index.doctree and b/docs/build/doctrees/index.doctree differ diff --git a/docs/build/html/_modules/codecipher/a1z52n62.html b/docs/build/html/_modules/codecipher/a1z52n62.html deleted file mode 100644 index b411ab6..0000000 --- a/docs/build/html/_modules/codecipher/a1z52n62.html +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - codecipher.a1z52n62 — codecipher https://github.com/electux/codecipher/releases documentation - - - - - - - - - - - - -
-
-
-
- -

Source code for codecipher.a1z52n62

-# -*- coding: UTF-8 -*-
-
-'''
-Module
-    __init__.py
-Copyright
-    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
-    codecipher is free software: you can redistribute it and/or modify it
-    under the terms of the GNU General Public License as published by the
-    Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-    codecipher is distributed in the hope that it will be useful, but
-    WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-    See the GNU General Public License for more details.
-    You should have received a copy of the GNU General Public License along
-    with this program. If not, see <http://www.gnu.org/licenses/>.
-Info
-    Defines class A1z52N62 with attribute(s) and method(s).
-    Creates container class with aggregate backend API.
-'''
-
-import sys
-from typing import List
-
-try:
-    from codecipher.a1z52n62.encode import A1z52N62Encode
-    from codecipher.a1z52n62.decode import A1z52N62Decode
-except ImportError as ats_error_message:  # pragma: no cover
-    # Force exit python #######################################################
-    sys.exit(f'\n{__file__}\n{ats_error_message}\n')  # pragma: no cover
-
-__author__: str = 'Vladimir Roncevic'
-__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
-__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
-__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
-__version__: str = '1.5.0'
-__maintainer__: str = 'Vladimir Roncevic'
-__email__: str = 'elektron.ronca@gmail.com'
-__status__: str = 'Updated'
-
-
-
-[docs] -class A1z52N62(A1z52N62Encode, A1z52N62Decode): - ''' - Defines class A1z52N62 with attribute(s) and method(s). - Creates container class with aggregate backend API. - - It defines: - - :attributes: - | None. - :methods: - | __init__ - Initials A1z52N62 constructor. - ''' - - def __init__(self) -> None: - ''' - Initials A1z52N62 constructor. - - :exceptions: None - ''' - super().__init__()
- -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/a1z52n62/config.html b/docs/build/html/_modules/codecipher/a1z52n62/config.html new file mode 100644 index 0000000..9d585e8 --- /dev/null +++ b/docs/build/html/_modules/codecipher/a1z52n62/config.html @@ -0,0 +1,156 @@ + + + + + + + codecipher.a1z52n62.config — codecipher https://github.com/electux/codecipher/releases documentation + + + + + + + + + + + + +
+
+
+
+ +

Source code for codecipher.a1z52n62.config

+# -*- coding: UTF-8 -*-
+
+'''
+Module
+    config.py
+Copyright
+    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
+    codecipher is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    codecipher is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    See the GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License along
+    with this program. If not, see <http://www.gnu.org/licenses/>.
+Info
+    Defines configuration for cipher A1z52N62 logic.
+'''
+
+from typing import Dict, List, Optional, Set
+from string import ascii_lowercase, ascii_uppercase, digits, whitespace
+from dataclasses import dataclass, field
+from codecipher.abstracts.iconfig import IConfig
+
+__author__: str = 'Vladimir Roncevic'
+__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
+__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
+__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
+__version__: str = '1.5.1'
+__maintainer__: str = 'Vladimir Roncevic'
+__email__: str = 'elektron.ronca@gmail.com'
+__status__: str = 'Updated'
+
+
+
+[docs] +@dataclass(frozen=True) +class A1z52N62Config(IConfig): + ''' + Defines class A1z52N62Config with attribute(s). + + It defines: + + :attributes: + | key - Controls transformation during encoding and decoding (default None). + | shift - Controls transformation during encoding and decoding (default 0). + | upper_case_offset - Offset for uppercase letters (default 64). + | lower_case_offset - Offset for lowercase letters (default 96). + | lower_case_base - Base index for lowercase letters (default 27). + | numeric_base - Base index for numeric characters (default 53). + | alphabet_size - Size of alphabet (default 26). + | code_splitter - Code splitter (default ' - '). + | altchars - Defines replacements for '+' and '/' (default None). + | padding - Adds to end '=' (default False). + | allowed_chars - Strict set of allowed characters (default ascii_lowercase + ascii_uppercase + digits + whitespace). + | lookup_table - Lookup table for cipher set (default None). + :methods: None + ''' + + key: Optional[str] = None + shift: int = 0 + upper_case_offset: int = 64 + lower_case_offset: int = 96 + lower_case_base: int = 27 + numeric_base: int = 53 + alphabet_size: int = 26 + code_splitter: Optional[str] = ' - ' + altchars: Optional[bytes] = None + padding: bool = False + allowed_chars: Optional[Set[str]] = field( + default_factory=lambda: set(ascii_lowercase + ascii_uppercase + digits + whitespace) + ) + lookup_table: Optional[Dict[str, str]] = None
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/a1z52n62/decode.html b/docs/build/html/_modules/codecipher/a1z52n62/decode.html deleted file mode 100644 index 68fa9f8..0000000 --- a/docs/build/html/_modules/codecipher/a1z52n62/decode.html +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - codecipher.a1z52n62.decode — codecipher https://github.com/electux/codecipher/releases documentation - - - - - - - - - - - - -
-
-
-
- -

Source code for codecipher.a1z52n62.decode

-# -*- coding: UTF-8 -*-
-
-'''
-Module
-    decode.py
-Copyright
-    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
-    codecipher is free software: you can redistribute it and/or modify it
-    under the terms of the GNU General Public License as published by the
-    Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-    codecipher is distributed in the hope that it will be useful, but
-    WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-    See the GNU General Public License for more details.
-    You should have received a copy of the GNU General Public License along
-    with this program. If not, see <http://www.gnu.org/licenses/>.
-Info
-    Defines class A1z52N62Decode with attribute(s) and method(s).
-    Creates decode class with backend API.
-'''
-
-from dataclasses import dataclass, field
-from typing import List, Optional
-
-__author__: str = 'Vladimir Roncevic'
-__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
-__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
-__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
-__version__: str = '1.5.0'
-__maintainer__: str = 'Vladimir Roncevic'
-__email__: str = 'elektron.ronca@gmail.com'
-__status__: str = 'Updated'
-
-
-
-[docs] -@dataclass -class A1z52N62Decode: - ''' - Defines class A1z52N62Decode with attribute(s) and method(s). - Creates decode class with backend API. - - It defines: - - :attributes: - | _decode_data - Data decode container. - :methods: - | decode_data - Property methods for decode data. - | decode - Decode data from A1z52N62 format. - ''' - - _decode_data: Optional[str] = field(default=None) - - @property - def decode_data(self) -> Optional[str]: - ''' - Property method for getting decode data. - - :return: Decode data in str format | None - :rtype: <Optional[str]> - :exceptions: None - ''' - return self._decode_data - - @decode_data.setter - def decode_data(self, decode_data: Optional[str]) -> None: - ''' - Property method for setting decode data. - - :param decode_data: Decoded data | None - :type decode_data: <Optional[str]> - :return: None - :exceptions: None - ''' - if bool(decode_data): - self._decode_data = decode_data - -
-[docs] - def decode(self, data: Optional[str]) -> None: - ''' - Decoding data from A1z52N62 format. - - :param data: Data which should be decoded | None - :type data: <Optional[str]> - :return: None - :exceptions: None - ''' - if bool(data): - decode_list: List[str] = [] - for element in data.split(' - '): - if element.isnumeric(): - if int(element) <= 52: - if int(element) <= 26: - decode_list.append(chr(int(element) + 64)) - else: - decode_list.append(chr(int(element) + 96 - 27)) - else: - decode_list.append(str(int(element) - 53)) - else: - decode_list.append(element) - self._decode_data = ''.join(decode_list)
-
- -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/a1z52n62/decode/decode_algorithm.html b/docs/build/html/_modules/codecipher/a1z52n62/decode/decode_algorithm.html new file mode 100644 index 0000000..5012496 --- /dev/null +++ b/docs/build/html/_modules/codecipher/a1z52n62/decode/decode_algorithm.html @@ -0,0 +1,201 @@ + + + + + + + codecipher.a1z52n62.decode.decode_algorithm — codecipher https://github.com/electux/codecipher/releases documentation + + + + + + + + + + + + +
+
+
+
+ +

Source code for codecipher.a1z52n62.decode.decode_algorithm

+# -*- coding: UTF-8 -*-
+
+'''
+Module
+    decode_algorithm.py
+Copyright
+    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
+    codecipher is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    codecipher is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    See the GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License along
+    with this program. If not, see <http://www.gnu.org/licenses/>.
+Info
+    Defines class DecodeAlgorithm with default cipher A1z52N62 implementation.
+'''
+
+from typing import List, Optional
+from codecipher.abstracts.ialgorithm import IAlgorithm
+from codecipher.abstracts.iconfig import IConfig
+from codecipher.a1z52n62.config import A1z52N62Config
+
+__author__: str = 'Vladimir Roncevic'
+__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
+__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
+__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
+__version__: str = '1.5.1'
+__maintainer__: str = 'Vladimir Roncevic'
+__email__: str = 'elektron.ronca@gmail.com'
+__status__: str = 'Updated'
+
+
+
+[docs] +class DecodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class DecodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher A1z52N62. + :methods: + | __init__ - Initializes DecodeAlgorithm constructor. + | encoded_data - Property method for getting decoded data. + | encode - Execute cipher A1z52N62 logic. + ''' + + def __init__(self) -> None: + ''' + Initializes DecodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + +
+[docs] + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher A1z52N62 logic. + + :param data: Data in string format which should to be decoded | None + :type data: <Optional[str]> + :param config: Configuration for cipher | None + :type config: <Optional[IConfig]> + :return: Decoded data in string format (success) | None (fail) + :rtype: <Optional[str]> + :exceptions: None + ''' + if not data: + return None + + self.__config = config or A1z52N62Config() + + if not self.__config: + return None + + splitter: str = getattr(self.__config, 'code_splitter', ' - ') or ' - ' + + try: + tokens: List[str] = data.split(splitter) + decode_list: List[str] = [] + + for token in tokens: + + if not token: + continue + + if token.isdigit(): + val = int(token) + + # Range 1 to 26: big letters (A-Z) + if 1 <= val <= self.__config.alphabet_size: + decode_list.append(chr(val + self.__config.upper_case_offset)) + + # Range 27 to 52: small letters (a-z) + elif self.__config.lower_case_base <= val <= (self.__config.lower_case_base + self.__config.alphabet_size - 1): + decode_list.append(chr(val - (self.__config.lower_case_base - 1) + self.__config.lower_case_offset)) + + # Range 53 to 62: digits (0-9) + elif val >= self.__config.numeric_base: + decode_list.append(str(val - self.__config.numeric_base)) + + # Defanse step: any token out of range, append as string + else: + decode_list.append(token) + else: + # All others (ex. space ' ', dot '.'), append without changes to decode list + decode_list.append(token) + + # Join decoded list without splitters and spaces + return "".join(decode_list) + except (AttributeError, ValueError, TypeError): + return None
+
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/a1z52n62/decode/decoder.html b/docs/build/html/_modules/codecipher/a1z52n62/decode/decoder.html new file mode 100644 index 0000000..48b4c7a --- /dev/null +++ b/docs/build/html/_modules/codecipher/a1z52n62/decode/decoder.html @@ -0,0 +1,176 @@ + + + + + + + codecipher.a1z52n62.decode.decoder — codecipher https://github.com/electux/codecipher/releases documentation + + + + + + + + + + + + +
+
+
+
+ +

Source code for codecipher.a1z52n62.decode.decoder

+# -*- coding: UTF-8 -*-
+
+'''
+Module
+    decoder.py
+Copyright
+    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
+    codecipher is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    codecipher is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    See the GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License along
+    with this program. If not, see <http://www.gnu.org/licenses/>.
+Info
+    Creates class decoder with cipher A1z52N62 logic.
+'''
+
+from dataclasses import dataclass, field
+from typing import List, Optional
+from codecipher.abstracts.idecoder import IDecoder
+from codecipher.abstracts.ialgorithm import IAlgorithm
+from codecipher.abstracts.iconfig import IConfig
+from codecipher.a1z52n62.config import A1z52N62Config
+from codecipher.a1z52n62.decode.decode_algorithm import DecodeAlgorithm
+
+__author__: str = 'Vladimir Roncevic'
+__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
+__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
+__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
+__version__: str = '1.5.1'
+__maintainer__: str = 'Vladimir Roncevic'
+__email__: str = 'elektron.ronca@gmail.com'
+__status__: str = 'Updated'
+
+
+
+[docs] +@dataclass +class Decoder(IDecoder): + ''' + Defines class Decoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher A1z52N62 logic. + | _strategy - Strategy for cipher A1z52N62 logic. + | _decoded_data - Container for decoded data. + :methods: + | decoded_data - Property method for getting decoded data. + | decode - Decode data by cipher A1z52N62 logic. + ''' + + _config: IConfig = field(default_factory=A1z52N62Config) + _strategy: IAlgorithm[IConfig] = field(default_factory=DecodeAlgorithm) + _decoded_data: Optional[str] = field(default=None, init=False) + + @property + def decoded_data(self) -> Optional[str]: + ''' + Property method for getting decoded data. + + :return: Decoded data in string format | None + :rtype: <Optional[str]> + :exceptions: None + ''' + return self._decoded_data + +
+[docs] + def decode(self, data: Optional[str] = None) -> bool: + ''' + Decode data by cipher A1z52N62 logic. + + :param data: Data in string format which should to be decoded | None + :type data: <Optional[str]> + :return: True (success) | False (fail) + :rtype: <bool> + :exceptions: None + ''' + if not data: + return False + + # Execute cipher A1z52N62 logic with configuration parameters + self._decoded_data = self._strategy.execute(data, self._config) + + if not self._decoded_data: + return False + + return True
+
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/a1z52n62/encode.html b/docs/build/html/_modules/codecipher/a1z52n62/encode.html deleted file mode 100644 index 7819f18..0000000 --- a/docs/build/html/_modules/codecipher/a1z52n62/encode.html +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - codecipher.a1z52n62.encode — codecipher https://github.com/electux/codecipher/releases documentation - - - - - - - - - - - - -
-
-
-
- -

Source code for codecipher.a1z52n62.encode

-# -*- coding: UTF-8 -*-
-
-'''
-Module
-    encode.py
-Copyright
-    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
-    codecipher is free software: you can redistribute it and/or modify it
-    under the terms of the GNU General Public License as published by the
-    Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-    codecipher is distributed in the hope that it will be useful, but
-    WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-    See the GNU General Public License for more details.
-    You should have received a copy of the GNU General Public License along
-    with this program. If not, see <http://www.gnu.org/licenses/>.
-Info
-    Defines class A1z52N62Encode with attribute(s) and method(s).
-    Creates encode class with backend API.
-'''
-
-from dataclasses import dataclass, field
-from typing import List, Optional
-
-__author__: str = 'Vladimir Roncevic'
-__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
-__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
-__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
-__version__: str = '1.5.0'
-__maintainer__: str = 'Vladimir Roncevic'
-__email__: str = 'elektron.ronca@gmail.com'
-__status__: str = 'Updated'
-
-
-
-[docs] -@dataclass -class A1z52N62Encode: - ''' - Defines class A1z52N62Encode with attribute(s) and method(s). - Creates encode class with backend API. - - It defines: - - :attributes: - | _encode_data - Data encode container. - :methods: - | encode_data - Property methods for encode data. - | encode - Encode data to A1z52N62 format. - ''' - - _encode_data: Optional[str] = field(default=None) - - @property - def encode_data(self) -> Optional[str]: - ''' - Property method for getting encode data. - - :return: Encoded data - :rtype: <Optional[str]> - :exceptions: None - ''' - return self._encode_data - - @encode_data.setter - def encode_data(self, encode_data: Optional[str]) -> None: - ''' - Property method for setting encode data. - - :param encode_data: Encode data | None - :type encode_data: <Optional[str]> - :return: None - :exceptions: None - ''' - if bool(encode_data): - self._encode_data = encode_data - -
-[docs] - def encode(self, data: Optional[str]) -> None: - ''' - Encoding data to A1z52N62 format. - - :param data: Data which should be encoded | None - :type data: <Optional[str]> - :return: None - :exceptions: None - ''' - if bool(data): - encode_list: List[str] = [] - for element in data: - if element.isalpha(): - if element.isupper(): - encode_list.append(str(ord(element) - 64)) - else: - encode_list.append(str(ord(element) - 96 + 27)) - else: - if element.isnumeric(): - encode_list.append(str(int(element) + 53)) - else: - encode_list.append(element) - self._encode_data = ' - '.join(encode_list)
-
- -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/a1z52n62/encode/encode_algorithm.html b/docs/build/html/_modules/codecipher/a1z52n62/encode/encode_algorithm.html new file mode 100644 index 0000000..5aec551 --- /dev/null +++ b/docs/build/html/_modules/codecipher/a1z52n62/encode/encode_algorithm.html @@ -0,0 +1,187 @@ + + + + + + + codecipher.a1z52n62.encode.encode_algorithm — codecipher https://github.com/electux/codecipher/releases documentation + + + + + + + + + + + + +
+
+
+
+ +

Source code for codecipher.a1z52n62.encode.encode_algorithm

+# -*- coding: UTF-8 -*-
+
+'''
+Module
+    encode_algorithm.py
+Copyright
+    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
+    codecipher is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    codecipher is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    See the GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License along
+    with this program. If not, see <http://www.gnu.org/licenses/>.
+Info
+    Defines class EncodeAlgorithm with default cipher A1z52N62 implementation.
+'''
+
+from typing import List, Optional
+from codecipher.abstracts.ialgorithm import IAlgorithm
+from codecipher.abstracts.iconfig import IConfig
+from codecipher.a1z52n62.config import A1z52N62Config
+
+__author__: str = 'Vladimir Roncevic'
+__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
+__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
+__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
+__version__: str = '1.5.1'
+__maintainer__: str = 'Vladimir Roncevic'
+__email__: str = 'elektron.ronca@gmail.com'
+__status__: str = 'Updated'
+
+
+
+[docs] +class EncodeAlgorithm(IAlgorithm[IConfig]): + ''' + Defines class EncodeAlgorithm with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher A1z52N62. + :methods: + | __init__ - Initializes EncodeAlgorithm constructor. + | encoded_data - Property method for getting encoded data. + | encode - Execute cipher A1z52N62 logic. + ''' + + def __init__(self) -> None: + ''' + Initializes EncodeAlgorithm constructor. + + :exceptions: None + ''' + self.__config: Optional[IConfig] = None + +
+[docs] + def execute(self, data: Optional[str] = None, config: Optional[IConfig] = None) -> Optional[str]: + ''' + Execute cipher A1z52N62 logic. + + :param data: Data in string format which should to be encoded | None + :type data: <Optional[str]> + :param config: Configuration for cipher | None + :type config: <Optional[IConfig]> + :return: Encoded data in string format (success) | None (fail) + :rtype: <Optional[str]> + :exceptions: None + ''' + if not data: + return None + + self.__config = config or A1z52N62Config() + + if not self.__config: + return None + + splitter = getattr(self.__config, 'code_splitter', ' - ') or ' - ' + + encode_list: List[str] = [] + + for element in data: + if element.isalpha(): + if element.isupper(): + # 'A' -> 65 - 64 = 1. + encode_list.append(str(ord(element) - self.__config.upper_case_offset)) + else: + # lower_case_base = 27, a ord('a') - 96 = 1, 'a' -> (1 + 26 = 27). + encode_list.append( + str(ord(element) - self.__config.lower_case_offset + (self.__config.lower_case_base - 1)) + ) + elif element.isnumeric(): + # '0' -> 0 + 53 = 53, '9' -> 9 + 53 = 62. + encode_list.append(str(int(element) + self.__config.numeric_base)) + else: + # All other characters (spaces, punctuation) remain unchanged. + encode_list.append(element) + + # Join encoded list with splitters + return splitter.join(encode_list)
+
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/a1z52n62/encode/encoder.html b/docs/build/html/_modules/codecipher/a1z52n62/encode/encoder.html new file mode 100644 index 0000000..bce4e5e --- /dev/null +++ b/docs/build/html/_modules/codecipher/a1z52n62/encode/encoder.html @@ -0,0 +1,176 @@ + + + + + + + codecipher.a1z52n62.encode.encoder — codecipher https://github.com/electux/codecipher/releases documentation + + + + + + + + + + + + +
+
+
+
+ +

Source code for codecipher.a1z52n62.encode.encoder

+# -*- coding: UTF-8 -*-
+
+'''
+Module
+    encoder.py
+Copyright
+    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
+    codecipher is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    codecipher is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    See the GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License along
+    with this program. If not, see <http://www.gnu.org/licenses/>.
+Info
+    Creates class encoder with cipher A1z52N62 logic.
+'''
+
+from typing import List, Optional
+from dataclasses import dataclass, field
+from codecipher.abstracts.iencoder import IEncoder
+from codecipher.abstracts.ialgorithm import IAlgorithm
+from codecipher.abstracts.iconfig import IConfig
+from codecipher.a1z52n62.config import A1z52N62Config
+from codecipher.a1z52n62.encode.encode_algorithm import EncodeAlgorithm
+
+__author__: str = 'Vladimir Roncevic'
+__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
+__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
+__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
+__version__: str = '1.5.1'
+__maintainer__: str = 'Vladimir Roncevic'
+__email__: str = 'elektron.ronca@gmail.com'
+__status__: str = 'Updated'
+
+
+
+[docs] +@dataclass +class Encoder(IEncoder): + ''' + Defines class Encoder with attribute(s) and method(s). + + It defines: + + :attributes: + | _config - Configuration parameters for cipher A1z52N62 logic. + | _strategy - Strategy for cipher A1z52N62 logic. + | _encoded_data - Container for encoded data. + :methods: + | encoded_data - Property method for getting encoded data. + | encode - Encode data by cipher A1z52N62 logic. + ''' + + _config: IConfig = field(default_factory=A1z52N62Config) + _strategy: IAlgorithm[IConfig] = field(default_factory=EncodeAlgorithm) + _encoded_data: Optional[str] = field(default=None, init=False) + + @property + def encoded_data(self) -> Optional[str]: + ''' + Property method for getting encoded data. + + :return: Encoded data in string format | None + :rtype: <Optional[str]> + :exceptions: None + ''' + return self._encoded_data + +
+[docs] + def encode(self, data: Optional[str] = None) -> bool: + ''' + Encode data by cipher A1z52N62 logic. + + :param data: Data in string format which should to be encoded | None + :type data: <Optional[str]> + :return: True (success) | False (fail) + :rtype: <bool> + :exceptions: None + ''' + if not data: + return False + + # Execute cipher A1z52N62 logic with configuration parameters + self._encoded_data = self._strategy.execute(data, self._config) + + if not self._encoded_data: + return False + + return True
+
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/a1z52n62/engine.html b/docs/build/html/_modules/codecipher/a1z52n62/engine.html new file mode 100644 index 0000000..96e00a9 --- /dev/null +++ b/docs/build/html/_modules/codecipher/a1z52n62/engine.html @@ -0,0 +1,215 @@ + + + + + + + codecipher.a1z52n62.engine — codecipher https://github.com/electux/codecipher/releases documentation + + + + + + + + + + + + +
+
+
+
+ +

Source code for codecipher.a1z52n62.engine

+# -*- coding: UTF-8 -*-
+
+'''
+Module
+    a1z52n62.py
+Copyright
+    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
+    codecipher is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    codecipher is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    See the GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License along
+    with this program. If not, see <http://www.gnu.org/licenses/>.
+Info
+    Defines class A1Z52N62 with attribute(s) and method(s).
+'''
+
+from typing import List, Optional
+from codecipher.abstracts.icipher_engine import ICipherEngine
+from codecipher.abstracts.iconfig import IConfig
+from codecipher.abstracts.ivalidation_engine import IValidationEngine
+from codecipher.abstracts.iencoder import IEncoder
+from codecipher.abstracts.idecoder import IDecoder
+from codecipher.validation.validation_engine import ValidationEngine
+from codecipher.a1z52n62.encode.encoder import Encoder
+from codecipher.a1z52n62.decode.decoder import Decoder
+from codecipher.a1z52n62.config import A1z52N62Config
+
+__author__: str = 'Vladimir Roncevic'
+__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
+__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
+__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
+__version__: str = '1.5.1'
+__maintainer__: str = 'Vladimir Roncevic'
+__email__: str = 'elektron.ronca@gmail.com'
+__status__: str = 'Updated'
+
+
+
+[docs] +class A1Z52N62(ICipherEngine): + ''' + Defines class A1Z52N62 with attribute(s) and method(s). + + It defines: + + :attributes: + | __config - Configuration for cipher A1Z52N62. + | __validation_engine - Engine for data validation. + | __encoder - Encoder for cipher A1Z52N62. + | __decoder - Decoder for cipher A1Z52N62. + :methods: + | __init__ - Initializes A1Z52N62 constructor. + | encode - Encoding data to A1Z52N62 format. + | decode - Decoding data from A1Z52N62 format. + ''' + + def __init__( + self, + config: Optional[IConfig] = None, + validation_engine: Optional[IValidationEngine] = None, + encoder: Optional[IEncoder] = None, + decoder: Optional[IDecoder] = None, + ) -> None: + ''' + Initializes A1Z52N62 constructor. + + :param config: Configuration for cipher A1Z52N62 | None + :type config: <Optional[IConfig]> + :param validation_engine: Engine for data validation | None + :type validation_engine: <Optional[IValidationEngine]> + :param encoder: Encoder for cipher | None + :type encoder: <Optional[IEncoder]> + :param decoder: Decoder for cipher | None + :type decoder: <Optional[IDecoder]> + :exceptions: None + ''' + # Dependency injection or use default implementations + self.__config: IConfig = config or A1z52N62Config() + self.__validation_engine: IValidationEngine = validation_engine or ValidationEngine( + allowed_chars=self.__config.allowed_chars + ) + self.__encoder: IEncoder = encoder or Encoder(_config=self.__config) + self.__decoder: IDecoder = decoder or Decoder(_config=self.__config) + +
+[docs] + def encode(self, data: Optional[str]) -> Optional[str]: + ''' + Encoding data to A1Z52N62 format. + + :param data: Data in string format which should to be encoded | None + :type data: <Optional[str]> + :return: Encoded data in string format (success) | None (fail) + :rtype: <Optional[str]> + :exceptions: None + ''' + # Checking and validation data for process of encoding + if not data or not self.__validation_engine.is_valid(data): + return None + + # Checking process of encoding data + if not self.__encoder.encode(data): + return None + + return self.__encoder.encoded_data
+ + +
+[docs] + def decode(self, data: Optional[str]) -> Optional[str]: + ''' + Decoding data from A1Z52N62 format. + + :param data: Data in string format which should to be decoded | None + :type data: <Optional[str]> + :return: Decoded data in string format (success) | None (fail) + :rtype: <Optional[str]> + :exceptions: None + ''' + # Checking data and process of decoding data + if not data or not self.__decoder.decode(data): + return None + + # Checking and validation decoded data + if not self.__validation_engine.is_valid(self.__decoder.decoded_data): + return None + + return self.__decoder.decoded_data
+
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/abstracts/ialgorithm.html b/docs/build/html/_modules/codecipher/abstracts/ialgorithm.html new file mode 100644 index 0000000..6e91c39 --- /dev/null +++ b/docs/build/html/_modules/codecipher/abstracts/ialgorithm.html @@ -0,0 +1,149 @@ + + + + + + + codecipher.abstracts.ialgorithm — codecipher https://github.com/electux/codecipher/releases documentation + + + + + + + + + + + + +
+
+
+
+ +

Source code for codecipher.abstracts.ialgorithm

+# -*- coding: UTF-8 -*-
+
+'''
+Module
+    ialgorithm.py
+Copyright
+    Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
+    codecipher is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    codecipher is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    See the GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License along
+    with this program. If not, see <http://www.gnu.org/licenses/>.
+Info
+    Defines class IAlgorithm for cipher algorithms.
+'''
+
+from typing import List, Optional, TypeVar, Generic
+from abc import ABC, abstractmethod
+from codecipher.abstracts.iconfig import IConfig
+
+__author__: str = 'Vladimir Roncevic'
+__copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
+__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
+__license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
+__version__: str = '1.5.1'
+__maintainer__: str = 'Vladimir Roncevic'
+__email__: str = 'elektron.ronca@gmail.com'
+__status__: str = 'Updated'
+
+# Generic type for algorithm configuration
+ConfigT = TypeVar('ConfigT', bound=IConfig)
+
+
+
+[docs] +class IAlgorithm(ABC, Generic[ConfigT]): + ''' + Defines interface IAlgorithm with abstract method. + + It defines: + + :attributes: None + :methods: + | execute - Execute chipher logic for processing data. + ''' + +
+[docs] + @abstractmethod + def execute(self, data: Optional[str] = None, config: Optional[ConfigT] = None) -> Optional[str]: + ''' + Execute cipher logic for processing data. + + :param data: Data in string format which should to be processed | None + :type data: <Optional[str]> + :param config: Configuration parameters for cipher | None + :type config: <Optional[IConfig]> + :return: Processed data in string format (success) | None (fail) + :rtype: <Optional[str]> + :exceptions: None + ''' + raise NotImplementedError('Method execute() must be implemented.')
+
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/docs/build/html/_modules/codecipher/vigenere/lookup_table.html b/docs/build/html/_modules/codecipher/abstracts/icharacter_validator.html similarity index 62% rename from docs/build/html/_modules/codecipher/vigenere/lookup_table.html rename to docs/build/html/_modules/codecipher/abstracts/icharacter_validator.html index 4599cc8..e9f6c05 100644 --- a/docs/build/html/_modules/codecipher/vigenere/lookup_table.html +++ b/docs/build/html/_modules/codecipher/abstracts/icharacter_validator.html @@ -4,7 +4,7 @@ - codecipher.vigenere.lookup_table — codecipher https://github.com/electux/codecipher/releases documentation + codecipher.abstracts.icharacter_validator — codecipher https://github.com/electux/codecipher/releases documentation @@ -25,9 +25,8 @@

Navigation

modules | - - - + + @@ -36,12 +35,12 @@

Navigation

-

Source code for codecipher.vigenere.lookup_table

+  

Source code for codecipher.abstracts.icharacter_validator

 # -*- coding: UTF-8 -*-
 
 '''
 Module
-    lookup_table.py
+    icharacter_validator.py
 Copyright
     Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
     codecipher is free software: you can redistribute it and/or modify it
@@ -55,48 +54,50 @@ 

Source code for codecipher.vigenere.lookup_table

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Info - Defines class LookUpTable with attribute(s). - Creates lookup table class with support for encoding/decoding. + Defines interface ICharacterValidator for character validators. ''' -from typing import List, Dict +from typing import List, Optional +from abc import ABC, abstractmethod __author__: str = 'Vladimir Roncevic' __copyright__: str = '(C) 2026, https://electux.github.io/codecipher' __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation'] __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE' -__version__: str = '1.5.0' +__version__: str = '1.5.1' __maintainer__: str = 'Vladimir Roncevic' __email__: str = 'elektron.ronca@gmail.com' __status__: str = 'Updated' -
-[docs] -class LookUpTable: +
+[docs] +class ICharacterValidator(ABC): ''' - Defines class LookUpTable with attribute(s) and method(s). - Creates lookup table class with support for encoding/decoding. + Defines interface ICharacterValidator with abstract method. It defines: - :attributes: - | ALPHA - Define alphabet for encoding/decoding. - | NUM - Defines numeric for encoding/decoding. - | WHITE_SPACE - Defines white space for encoding/decoding. - | ALPHANUM - Aggregated chars for encoding/decoding. - | LETTER_TO_INDEX - Indexed letters for encoding/decoding. - | INDEX_TO_LETTER - Indexed letters for encoding/decoding. + :attributes: None :methods: - | None + | is_valid_char - Validates if a single character belongs to cipher charcter set. ''' - ALPHA: str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' - NUM: str = '0123456789' - WHITE_SPACE: str = ' ' - ALPHANUM: str = ''.join([ALPHA, NUM, WHITE_SPACE]) - LETTER_TO_INDEX: Dict[str, int] = dict(zip(ALPHANUM, range(len(ALPHANUM)))) - INDEX_TO_LETTER: Dict[int, str] = dict(zip(range(len(ALPHANUM)), ALPHANUM))
+
+[docs] + @abstractmethod + def is_valid_char(self, character: Optional[str]) -> bool: + ''' + Validates if a single character belongs to cipher charcter set. + + :param character: Single character in string format to be validated | None + :type character: <Optional[str]> + :return: True (valid) | False (invalid) + :rtype: <bool> + :exceptions: NotImplementedError + ''' + raise NotImplementedError("Method is_valid_char() must be implemented.")
+
@@ -131,8 +132,7 @@

Navigation

>modules | - - +
@@ -36,12 +35,12 @@

Navigation

-

Source code for codecipher.b64.decode

+  

Source code for codecipher.abstracts.icipher_engine

 # -*- coding: UTF-8 -*-
 
 '''
 Module
-    decode.py
+    icipher_engine.py
 Copyright
     Copyright (C) 2021 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
     codecipher is free software: you can redistribute it and/or modify it
@@ -55,80 +54,66 @@ 

Source code for codecipher.b64.decode

     You should have received a copy of the GNU General Public License along
     with this program. If not, see <http://www.gnu.org/licenses/>.
 Info
-    Defines class AlephTawBetShinDecode with attribute(s) and method(s).
-    Creates decode class with backend API.
+    Defines interface ICipherEngine for cipher class with encoders and decoders.
 '''
 
-from dataclasses import dataclass, field
-from base64 import b64decode
+from abc import ABC, abstractmethod
 from typing import List, Optional
 
 __author__: str = 'Vladimir Roncevic'
 __copyright__: str = '(C) 2026, https://electux.github.io/codecipher'
 __credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
 __license__: str = 'https://github.com/electux/codecipher/blob/main/LICENSE'
-__version__: str = '1.5.0'
+__version__: str = '1.5.1'
 __maintainer__: str = 'Vladimir Roncevic'
 __email__: str = 'elektron.ronca@gmail.com'
 __status__: str = 'Updated'
 
 
-
-[docs] -@dataclass -class B64Decode: +
+[docs] +class ICipherEngine(ABC): ''' - Defines class AlephTawBetShinDecode with attribute(s) and method(s). - Creates decode class with backend API. + Defines interface ICipherEngine with method(s). It defines: - :attributes: - | _decode_data - Data decode container. + :attributes: None :methods: - | decode_data - Property methods for decode data. - | decode - Decode data from AlephTawBetShin format. + | encode - Encoding data in string format to CIPHER format. + | decode - Decoding data in string format from CIPHER format. ''' - _decode_data: Optional[str] = field(default=None) - - @property - def decode_data(self) -> Optional[str]: +
+[docs] + @abstractmethod + def encode(self, data: Optional[str]) -> Optional[str]: ''' - Property method for getting decode data. + Encoding data in string format to CIPHER format. - :return: Decode data in str format | None + :param data: Data in string format which should to be encoded | None + :type data: <Optional[str]> + :return: Encoded data in string format (success) | None (fail) :rtype: <Optional[str]> - :exceptions: None + :exceptions: NotImplementedError ''' - return self._decode_data + raise NotImplementedError('Method encode() must be implemented.')
- @decode_data.setter - def decode_data(self, decode_data: Optional[str]) -> None: - ''' - Property method for setting decode data. - :param decode_data: Decoded data - :type decode_data: <Optional[str]> - :return: None - :exceptions: None - ''' - if bool(decode_data): - self._decode_data = decode_data - -
-[docs] - def decode(self, data: Optional[str]) -> None: +
+[docs] + @abstractmethod + def decode(self, data: Optional[str]) -> Optional[str]: ''' - Decoding data from AlephTawBetShin format. + Decoding data in string format from CIPHER format. - :param data: Data which should be decoded | None + :param data: Data in string format which should to be decoded | None :type data: <Optional[str]> - :return: None - :exceptions: None + :return: Decoded data in string format (success) | None (fail) + :rtype: <Optional[str]> + :exceptions: NotImplementedError ''' - if bool(data): - self._decode_data = b64decode(data).decode()
+ raise NotImplementedError('Method decode() must be implemented.')
@@ -164,8 +149,7 @@

Navigation

>modules | - - +