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)
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)
def decrypt(ctx): text = readf(ENCRYPTED) key = readf(KEY) decrypted = ctx.obj['CIPHER'].decrypt(text, key) writef(decrypted, DECRYPTED)
def cracking(ctx): encrypted = readf(ENCRYPTED) decryptions = ctx.obj['CIPHER'].crack(encrypted) writef(decryptions, DECRYPTED)
def normalized(ctx): orig = readf(ORIGINALTEXT) normalized = normalize_text(orig) writef(normalized, PLAINTEXT)
def test_bitwisexor_decryption(): text = readf(XOR_ENCRYPTED) testf = readf(PLAINTEXT) keyf = readf(XOR_KEY) decrypted = BitwiseXOR.decrypt(text, keyf) assert decrypted == testf
def test_bitwisexor_cryptanalysis(): text = readf(XOR_ENCRYPTED) testf = readf(XOR_KEY) kw = BitwiseXOR.cryptanalysis(text) assert kw == testf
def test_vigenere_decryption(): testf = readf(PLAINTEXT) crypto = readf(VIGENERE_ENCRYPTED) keyf = readf(VIGENERE_KEY) decrypted = Vigenere.decrypt(crypto, keyf) assert decrypted == testf
def test_vigenere_cryptoanalysis(): testf = readf(VIGENERE_KEY) crypto = readf(VIGENERE_ENCRYPTED) keyword = Vigenere.cryptanalysis(crypto) assert keyword == testf
def test_vigenere_encryption(): testf = readf(VIGENERE_ENCRYPTED) plainf = readf(PLAINTEXT) keyf = readf(VIGENERE_KEY) encrypted = Vigenere.encrypt(plainf, keyf) assert encrypted == testf
def test_affine_decryption(): testf = readf(PLAINTEXT) crypto = readf(AFFINE_ENCRYPTED) keyf = readf(AFFINE_KEYS) decrypted = Affine.decrypt(crypto, keyf) assert decrypted == testf
def test_affine_encryption(): testf = readf(AFFINE_ENCRYPTED) plainf = readf(PLAINTEXT) keyf = readf(AFFINE_KEYS) encrypted = Affine.encrypt(plainf, keyf) assert encrypted == testf
def test_ceasars_decryption(): testf = readf(PLAINTEXT) crypto = readf(CAESARS_ENCRYPTED) keyf = readf(CAESARS_KEY) decrypted = Caesar.decrypt(crypto, keyf) assert decrypted == testf
def test_ceasars_encryption(): testf = readf(CAESARS_ENCRYPTED) plainf = readf(PLAINTEXT) keyf = readf(CAESARS_KEY) encrypted = Caesar.encrypt(plainf, keyf) assert encrypted == testf