Skip to content

Commit

Permalink
Adding tests cases for the 3 new ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Swartsenburg committed Dec 11, 2023
1 parent 0fbf793 commit dae69d7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
19 changes: 11 additions & 8 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -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="/")
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tests/base64/test_base64.py
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 20 additions & 0 deletions tests/hill/test_hill.py
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 20 additions & 0 deletions tests/playfair/test_playfair.py
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit dae69d7

Please sign in to comment.