Ejemplo n.º 1
0
def cryptanalysis(ctx):
    text = readf(ENCRYPTED)
    if (ctx.obj['CIPHER'] == Affine or
            ctx.obj['CIPHER'] == Caesar):
        sample = readf(EXTRATEXT)
        decrypted, key = ctx.obj['CIPHER'].cryptanalysis(text, sample)
    else:
        key = ctx.obj['CIPHER'].cryptanalysis(text)
        decrypted = ctx.obj['CIPHER'].decrypt(text, key)
    writef(decrypted, DECRYPTED)
    writef(key, NEWKEY)
Ejemplo n.º 2
0
def encrypt(ctx):

    if (ctx.obj['CIPHER'] == ECB or
            ctx.obj['CIPHER'] == CBC):
        img = readf(ORIGINALIMG, binary=True)
        encrypted = ctx.obj['CIPHER'].encrypt(img)
        writef(encrypted, ENCRYPTEDIMG, binary=True)
    else:
        key = readf(KEY)
        text = readf(PLAINTEXT)
        encrypted = ctx.obj['CIPHER'].encrypt(text, key)
        writef(encrypted, ENCRYPTED)
Ejemplo n.º 3
0
def decrypt(ctx):
    text = readf(ENCRYPTED)
    key = readf(KEY)
    decrypted = ctx.obj['CIPHER'].decrypt(text, key)
    writef(decrypted, DECRYPTED)
Ejemplo n.º 4
0
def cracking(ctx):
    encrypted = readf(ENCRYPTED)
    decryptions = ctx.obj['CIPHER'].crack(encrypted)
    writef(decryptions, DECRYPTED)
Ejemplo n.º 5
0
def normalized(ctx):
    orig = readf(ORIGINALTEXT)
    normalized = normalize_text(orig)
    writef(normalized, PLAINTEXT)
Ejemplo n.º 6
0
def test_bitwisexor_decryption():
    text = readf(XOR_ENCRYPTED)
    testf = readf(PLAINTEXT)
    keyf = readf(XOR_KEY)
    decrypted = BitwiseXOR.decrypt(text, keyf)
    assert decrypted == testf
Ejemplo n.º 7
0
def test_bitwisexor_cryptanalysis():
    text = readf(XOR_ENCRYPTED)
    testf = readf(XOR_KEY)
    kw = BitwiseXOR.cryptanalysis(text)
    assert kw == testf
Ejemplo n.º 8
0
def test_vigenere_decryption():
    testf = readf(PLAINTEXT)
    crypto = readf(VIGENERE_ENCRYPTED)
    keyf = readf(VIGENERE_KEY)
    decrypted = Vigenere.decrypt(crypto, keyf)
    assert decrypted == testf
Ejemplo n.º 9
0
def test_vigenere_cryptoanalysis():
    testf = readf(VIGENERE_KEY)
    crypto = readf(VIGENERE_ENCRYPTED)
    keyword = Vigenere.cryptanalysis(crypto)
    assert keyword == testf
Ejemplo n.º 10
0
def test_vigenere_encryption():
    testf = readf(VIGENERE_ENCRYPTED)
    plainf = readf(PLAINTEXT)
    keyf = readf(VIGENERE_KEY)
    encrypted = Vigenere.encrypt(plainf, keyf)
    assert encrypted == testf
Ejemplo n.º 11
0
def test_affine_decryption():
    testf = readf(PLAINTEXT)
    crypto = readf(AFFINE_ENCRYPTED)
    keyf = readf(AFFINE_KEYS)
    decrypted = Affine.decrypt(crypto, keyf)
    assert decrypted == testf
Ejemplo n.º 12
0
def test_affine_encryption():
    testf = readf(AFFINE_ENCRYPTED)
    plainf = readf(PLAINTEXT)
    keyf = readf(AFFINE_KEYS)
    encrypted = Affine.encrypt(plainf, keyf)
    assert encrypted == testf
Ejemplo n.º 13
0
def test_ceasars_decryption():
    testf = readf(PLAINTEXT)
    crypto = readf(CAESARS_ENCRYPTED)
    keyf = readf(CAESARS_KEY)
    decrypted = Caesar.decrypt(crypto, keyf)
    assert decrypted == testf
Ejemplo n.º 14
0
def test_ceasars_encryption():
    testf = readf(CAESARS_ENCRYPTED)
    plainf = readf(PLAINTEXT)
    keyf = readf(CAESARS_KEY)
    encrypted = Caesar.encrypt(plainf, keyf)
    assert encrypted == testf