예제 #1
0
파일: unvign.py 프로젝트: ggadal/matasano
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
plaintext = ''.join([''.join(block_rows)
                     for block_rows in zip(*text_transpose)])

#create new file w/ plaintext, cipher, and key
secretFile = open(os.getcwd() + "/" + cipherAddr + ".decript", "w")
secretFile.write(''.join(("key:\n", key, "\n\nplaintext:\n", plaintext,
                          "\n\nciphertext:\n", b64_cipher)))
secretFile.close()
예제 #2
0
파일: vigenere.py 프로젝트: ggadal/matasano
 def test_brute_xor(self):
     assert vigenere.brute_xor('\x11>x,01+x1+x:*73=6tx,0=*=\x7f+x9x?77<x;'+ \
         '096;=x1,\x7f+x:=;9-+=x7>x,0=x\x1d6?41+0u<=,=;,7*v') == \
         ('X', "If this is broken, there's a good chance it's because " + \
          "of the English-detector."), \
         "brute xor returns a wrong solution"