Пример #1
0
#ignore invalid constant names
# pylint: disable=C0103
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)
Пример #2
0
 def test_to_text(self):
     assert vigenere.to_text(self.b16) == self.eng, \
                                     "hex to text conversion mistakes"
     assert vigenere.to_text(self.b64) == self.eng, \
                                     "b64 to text conversion mistakes"