diff --git a/api/app.py b/api/app.py index e24647a..937db44 100644 --- a/api/app.py +++ b/api/app.py @@ -1,28 +1,28 @@ import traceback -from flask_openapi3 import Info -from flask_openapi3 import OpenAPI, APIBlueprint +from cipher_algorithms.ciphers.polygram_substitution_cipher.algo import ( + UnsupportedCharacterError, +) +from cipher_algorithms.helpers.char_conversion_27 import InvalidCharacterException from flask import redirect +from flask_openapi3 import APIBlueprint, Info, OpenAPI +from .ciphers.base64 import base64_blueprint from .ciphers.bifid import bifid_blueprint from .ciphers.caesar import caesar_blueprint from .ciphers.columnar_transposition import columnar_transposition_blueprint from .ciphers.fractioned_morse import fractioned_morse_blueprint +from .ciphers.hill import hill_blueprint from .ciphers.homophonic_substitution import homophonic_substitution_blueprint from .ciphers.mono_alphabetic_substitution import mono_alphabetic_substitution_blueprint from .ciphers.one_time_pad import one_time_pad_blueprint +from .ciphers.playfair import playfair_blueprint from .ciphers.polyalphabetic_substitution import polyalphabetic_substitution_blueprint from .ciphers.polybius import polybius_blueprint from .ciphers.polygram_substitution import polygram_substitution_cipher_blueprint from .ciphers.rail_fence import rail_fence_cipher_blueprint from .ciphers.vigenere import vigenere_blueprint - from .common.schemas import ExceptionSchema -from cipher_algorithms.helpers.char_conversion_27 import InvalidCharacterException -from cipher_algorithms.ciphers.polygram_substitution_cipher.algo import ( - UnsupportedCharacterError, -) - info = Info(title="Cipher Algorithm API", version="0.0.1") app = OpenAPI(__name__, info=info, doc_prefix="/docs", swagger_url="/") @@ -68,13 +68,16 @@ def homepage(): return redirect("docs") +ciphers.register_api(base64_blueprint) ciphers.register_api(bifid_blueprint) ciphers.register_api(caesar_blueprint) ciphers.register_api(columnar_transposition_blueprint) ciphers.register_api(fractioned_morse_blueprint) +ciphers.register_api(hill_blueprint) ciphers.register_api(homophonic_substitution_blueprint) ciphers.register_api(mono_alphabetic_substitution_blueprint) ciphers.register_api(one_time_pad_blueprint) +ciphers.register_api(playfair_blueprint) ciphers.register_api(polyalphabetic_substitution_blueprint) ciphers.register_api(polybius_blueprint) ciphers.register_api(polygram_substitution_cipher_blueprint) diff --git a/tests/base64/test_base64.py b/tests/base64/test_base64.py new file mode 100644 index 0000000..7d54d10 --- /dev/null +++ b/tests/base64/test_base64.py @@ -0,0 +1,18 @@ +from cipher_algorithms.ciphers.base64.algo import ( + encrypt, + decrypt, +) + + +def test_base64_encrypt(): + plaintext = "testingabc" + cipher = encrypt(plaintext) + + assert cipher == "dGVzdGluZ2FiYw==" + + +def test_base64_decrypt(): + cipher = "dGVzdGluZ2FiYw==" + plaintext = decrypt(cipher) + + assert plaintext == "testingabc" diff --git a/tests/hill/test_hill.py b/tests/hill/test_hill.py new file mode 100644 index 0000000..248d984 --- /dev/null +++ b/tests/hill/test_hill.py @@ -0,0 +1,20 @@ +from cipher_algorithms.ciphers.hill.algo import ( + encrypt, + decrypt, +) + + +def test_hill_encrypt(): + plaintext = "TESTINGABC" + key = "HELLO" + cipher = encrypt(plaintext, key) + + assert cipher == "VQXVRTQYDA" + + +def test_hill_decrypt(): + plaintext = "VQXVRTQYDA" + key = "HELLO" + cipher = decrypt(plaintext, key) + + assert cipher == "TESTINGABC" diff --git a/tests/playfair/test_playfair.py b/tests/playfair/test_playfair.py new file mode 100644 index 0000000..70974f4 --- /dev/null +++ b/tests/playfair/test_playfair.py @@ -0,0 +1,20 @@ +from cipher_algorithms.ciphers.playfair.algo import ( + encrypt, + decrypt, +) + + +def test_playfair_encrypt(): + plaintext = "TESTINGABC" + key = "HELLO" + cipher = encrypt(plaintext, key) + + assert cipher == "ROTUKPPGCD" + + +def test_playfair_decrypt(): + plaintext = "ROTUKPPGCD" + key = "HELLO" + cipher = decrypt(plaintext, key) + + assert cipher == "TESTINGABC"