Example #1
0
def test_compare_ignores_random_letters():
    cipher = Fleissner(
        key="XooXooooooXoXoooXoooXXoXoooooooooXoXoooXooooXoooXoXoooXXoooooooo")

    ciphertext = cipher.encrypt("WELCOME TO VILLIERS PARK")
    assert cipher.compare_ciphertext(
        ciphertext,
        "WEHERRXSJQL C  POPVBMEA XTZRJRCKMTXOR Q NMMYVXGJIELAIOLIUB Q J Z")
Example #2
0
def cryptanalysis_fleissner():
    ciphertexts = request.form.get("ciphertexts", "").strip().splitlines()
    plaintexts = request.form.get("plaintexts", "").strip().splitlines()
    key = request.form.get(
        "key",
        "XooXooooooXoXoooXoooXXoXoooooooooXoXoooXooooXoooXoXoooXXoooooooo")
    if request.method == "POST":
        cipher = Fleissner(key=key)
        plaintexts = [cipher.decrypt(c) for c in ciphertexts]
    return render_template(
        "cryptanalysis/fleissner.html",
        ciphertexts=ciphertexts,
        plaintexts=plaintexts,
        key=key,
    )
Example #3
0
def test_from_worksheet():
    cipher = Fleissner(
        key="XooXooooooXoXoooXoooXXoXoooooooooXoXoooXooooXoooXoXoooXXoooooooo")

    ciphertext = cipher.encrypt("WELCOME TO VILLIERS PARK")
    assert cipher.compare(
        "WEXEXRXSXXL CXXXOPXXMEA XXXRXXXKXTXOXXX XXXXVXXXIXLXXXLIXXXXXXXX",
        ciphertext), ciphertext
    plaintext = cipher.decrypt(
        "WEXEXRXSXXL CXXXOPXXMEA XXXRXXXKXTXOXXX XXXXVXXXIXLXXXLIXXXXXXXX")
    assert cipher.compare("WELCOME TO VILLIERS PARK", plaintext), plaintext

    ciphertext = cipher.encrypt("FLEISSNER IS A FUNNY NAME")
    assert cipher.compare_ciphertext(
        "FUHLINDNVXEYIRACS RNSNNEKEXAZZQMKRE BDGIENXPSZMN GAJKX FRTBUDSKC",
        ciphertext), ciphertext
    plaintext = cipher.decrypt(
        "FUHLINDNVXEYIRACS RNSNNEKEXAZZQMKRE BDGIENXPSZMN GAJKX FRTBUDSKC")
    assert cipher.compare_plaintext("FLEISSNER IS A FUNNY NAME",
                                    plaintext), plaintext
Example #4
0
def create_diffie_messages(group):
    playfair = Playfair(key='LSCZGADKUORFXTHQNBEPYMWIV')
    myszkowski = Myszkowski(key='HELLMAN')
    fleissner = Fleissner(
        key='ooooooooooooXoooXoooXoXXXoooXXXoooooooooooXooooooXXooooXooooXoXX')
    trifid = Trifid(key='CSQY_UBNVDWKPGERLTZJOHFAXMI')

    messages = [
        'BAILEY WHITFIELD DIFFIE WAS BORN IN NINETEEN FOURTY FOUR',
        'WHIT WAS THE COCREATOR OF DIFFIE HELLMAN KEY EXCHANGE',
        'DIFFIE GRADUATED FROM MIT IN NINETEEN SIXTY FIVE',
        'WITHOUT BAILEYS WORK THE INTERNET WOULD NOT BE POSSIBLE',
        'NEW DIRECTIONS IN CRYPTOGRAPHY',
        'HE HELPED DEVELOP THE FUNDAMENTAL IDEAS BEHIND PUBLIC KEY CIPHERS'
    ]
    yield from create_activity_messages(group,
                                        [fleissner, myszkowski, playfair],
                                        trifid, messages)
Example #5
0
def create_tutte_messages(group):
    playfair = Playfair(key='KQSGLRYTWEUXBFPVDHMNZOCAI')
    myszkowski = Myszkowski(key='TUNNY')
    fleissner = Fleissner(
        key='oXXXooXXooXoXXooooooXooooooXoooooXooooooooooXXoXoXoooooooooXoooo')
    trifid = Trifid(key='_AWCDPYSEKQORNHBTLGJMVFIZXU')

    messages = [
        'WILLIAM THOMAS TUTTE WORKED AT BLETCHLEY PARK CRACKING GERMAN CIPHERS',
        'BILL WAS BORN IN SUFFOLK IN NINETEEN SEVENTEEN',
        'TUTTE WAS INSTRUMENTAL IN BREAKING THE GERMAN LORENZ CIPHER',
        'AN ALGEBRAIC THEORY OF GRAPHS',
        'TUTTE PERFORMED ONE OF THE GREATEST INTELLECTUAL FEATS OF WORLD WAR TWO',
        'UNLIKE IN THE MOVIE TUTTE DID NOT WORK DIRECTLY WITH TURING'
    ]
    yield from create_activity_messages(group,
                                        [myszkowski, fleissner, playfair],
                                        trifid, messages)
Example #6
0
def create_rivest_messages(group):
    playfair = Playfair(key='PCGDAVESFOHMUWZLYNBRXKIQT')
    myszkowski = Myszkowski(key='CLIFFORD')
    fleissner = Fleissner(
        key='oXXXooXoooXoXoooXooooXooXooooXXooooXoooooooXooXoooooooXooooooooX')
    trifid = Trifid(key='AOGMPWEDZRCIBH_XTLVUQSNKYJF')

    messages = [
        'RONALD LINN RIVEST WAS BORN IN NINETEEN FOURTY SEVEN',
        'RIVEST IS ONE OF THE INVENTORS OF THE RSA ALGORITHM',
        'RON ALSO AUTHORED MANY OTHER ENCRYPTION ALGORITMS',
        'RONALD WORKS AS A CRYPTOGRAPHER AND INSTITUTE PROFESSOR AT MIT',
        'RIVEST WAS GIVEN A TURING AWARD IN TWO THOUSAND AND TWO',
        'RSA IS ONE OF THE FIRST PRACTICAL PUBLIC KEY CIPHERS IT IS USED EVERYWHERE'
    ]
    yield from create_activity_messages(group,
                                        [playfair, myszkowski, fleissner],
                                        trifid, messages)
Example #7
0
def create_friedman_messages(group):
    playfair = Playfair(key='ADUQYKOMRETGVFHNWLXZCIPBS')
    myszkowski = Myszkowski(key='INDIANA')
    fleissner = Fleissner(
        key='oooXooooXXoXXooXXXooooXooooooooooooXoXoXXoXoXooooooooooooooooooX')
    trifid = Trifid(key='V_WLNJDOGRMHIPXKYQSETBZUAFC')

    messages = [
        'AMERICAS FIRST FEMALE CRYPTANALYST',
        'FRIEDMAN WAS BORN IN EIGHTEEN NINETY TWO',
        'CRACKED CODES AT RIVERBANK DURING WORLD WAR ONE',
        'USED CRYPTANALYSIS TO STOP SMUGGLING AND BOOTLEGGING',
        'SHE WORKED FOR THE US NAVY THE TREASURY DEPARTMENT AND THE COAST GUARD',
        'THE SHAKESPEAREAN CIPHERS EXAMINED'
    ]
    yield from create_activity_messages(group,
                                        [myszkowski, fleissner, playfair],
                                        trifid, messages)
Example #8
0
def create_driscoll_messages(group):
    playfair = Playfair(key='CTOEFMUHYISAWNGQRZXLDKBVP')
    myszkowski = Myszkowski(key='ILLINOIS')
    fleissner = Fleissner(
        key='oooooooXXoooXoooXoXooooXXooooXoXooooXXooooooooXoXXooXXoooooooooo')
    trifid = Trifid(key='VAMZWXKSYONFTDUCHIBERGPJL_Q')

    messages = [
        'AGNES MEYER DRISCOLL WAS BORN IN EIGHTEEN EIGHTY NINE',
        'SHE WAS ALSO KNOWN AS MADAME X',
        'SHE WAS WITHOUT PEER AS A CRYPTANALYST',
        'DRISCOLL WORKED FOR THE US NAVY IN WORLD WAR ONE AND TWO',
        'SHE IS IN THE NATIONAL SECURITY AGENCYS HALL OF HONOR',
        'AGNES CRACKED JAPANESE NAVAL CODES INCLUDING THE RED AND BLUE BOOK CODES'
    ]
    yield from create_activity_messages(group,
                                        [fleissner, playfair, myszkowski],
                                        trifid, messages)
Example #9
0
def create_babbage_messages(group):
    playfair = Playfair(key='SCQOGUERPBKVWYZFDAHIMTLNX')
    myszkowski = Myszkowski(key='ENGINE')
    fleissner = Fleissner(
        key='ooooooXoooooXooXooooooooXoXoXoXoooooooooXXXoXooXooXoooXoXoooXooo')
    trifid = Trifid(key='HFERKDGNOQVJTMYP_AXSUBZWLIC')

    messages = [
        'CHARLES BABBAGE WAS BORN IN THE YEAR SEVENTEEN HUNDRED AND NINETY ONE',
        'BABBAGE INVENTED THE IDEA OF A DIGITAL PROGRAMMABLE COMPUTER',
        'CB IS CONSIDERED TO BE ONE OF THE FATHERS OF THE COMPUTER',
        'HIS MOST FAMOUS INVENTION IS THE DIFFERENCE ENGINE',
        'ON THE ECONOMY OF MACHINERY AND MANUFACTURES',
        'BABBAGE CRACKED THE UNCRACKABLE VIGENERE CIPHER',
    ]
    yield from create_activity_messages(group,
                                        [playfair, myszkowski, fleissner],
                                        trifid, messages)
Example #10
0
def test_very_large_plaintext():
    cipher = Fleissner(key="XooooXoXoooooXoo")
    ciphertext = cipher.encrypt("A" * 32)
    assert len(ciphertext) == 32
Example #11
0
def test_key_contains_something_else():
    with pytest.raises(ScytaleError):
        Fleissner(key="ABC")
Example #12
0
def test_key_not_square():
    with pytest.raises(ScytaleError):
        Fleissner(key="Xoo")
Example #13
0
def test_hello():
    cipher = Fleissner(key="XooooXoXoooooXoo")
    assert "HXXOXEXLXXXXXLXX" == cipher.encrypt("HELLO")
    assert "HELLO" == cipher.decrypt("HXXOXEXLXXXXXLXX")
Example #14
0
def test_rotate_back_again():
    cipher = Fleissner(key="XooooXoXoooooXoo")
    rotated = cipher.rotate(cipher.grille)
    assert [("X", "o", "o", "o"), ("o", "X", "o", "X"), ("o", "o", "o", "o"),
            ("o", "X", "o", "o")] == cipher.rotate(rotated, clockwise=False)
Example #15
0
def test_key_has_overlapping_cuts():
    with pytest.raises(ScytaleError):
        Fleissner(key="XXoo")
Example #16
0
def test_rotate():
    cipher = Fleissner(key="XooooXoXoooooXoo")
    assert [("o", "o", "o", "X"), ("X", "o", "X", "o"), ("o", "o", "o", "o"),
            ("o", "o", "X", "o")] == cipher.rotate(cipher.grille)
Example #17
0
def test_grille():
    cipher = Fleissner(key="XooooXoXoooooXoo")
    assert [["X", "o", "o", "o"], ["o", "X", "o", "X"], ["o", "o", "o", "o"],
            ["o", "X", "o", "o"]] == cipher.grille
Example #18
0
def test_key_does_not_complete_grid():
    with pytest.raises(ScytaleError):
        Fleissner(
            key=
            "oXooooXoooXooooooooXoXooXoooooXoooooXoooXooooooXooXoooooooooXooX")