Beispiel #1
0
import sys
import os
from tools import vigenere

cipherAddr = sys.argv[1]

#get the cipher
cipherFile = open(os.getcwd() + "/" + cipherAddr, "r")
b64_cipher = cipherFile.read()
cipherFile.close()
#clean whitespace
cipher = ''.join(b64_cipher.split())
#pitch b64 encoding
cipher = vigenere.to_text(cipher)
#find keysize - probablistic, can misfire
keysize = vigenere.find_keysize(cipher)
#divide cipher into blocks that were xored with the same character
cipher_blocks = vigenere.keysize_striping(cipher, keysize)
#brute force each block
key = ''
text_transpose = []
largest_block = max(len(blocks) for blocks in cipher_blocks)
for block_cipher in cipher_blocks:
    block_key, block_text = vigenere.brute_xor(block_cipher)
    #square each block
    if len(block_text) < largest_block:
        block_text += 'X'
    key += block_key
    text_transpose.append(block_text)

#transpose and reassemble the plaintext
Beispiel #2
0
 def test_find_keysize(self):
     assert vigenere.find_keysize(self.cipher) == len(self.key), \
                                             "finds incorrect keysize"