def test_decode(): assert bytearray(leviathan_plain, 'utf-8') == ascii85.decode(leviathan_encoded) for (plain, encoded) in tuples: assert bytearray(plain, 'utf-8') == ascii85.decode('<~' + encoded + '~>') assert False == ascii85.decode(encoded) assert False == ascii85.decode('<~' + encoded) assert False == ascii85.decode(encoded + '~>')
def test_decode(self): for phrase in self.phrases_to_decode: phrase = phrase.encode("utf-8") actual = ascii85.decode(phrase) expected = base64.a85decode(phrase, adobe=True) self.assertEqual(actual, expected)
xor.append(x) # a) 15 * '=' must be in the encrypted text, because the line "==[ Payload ]==" contains 47 * '='. # b) Multiple occurences are possible, but hopefully in at least one case 17 more '=' will follow. # c) The last occurence is tried first, because that should be the "Payload"-line. tattletale = bytearray() for x in xor: tattletale.append(x ^ ord('=')) xorfullstart = decoded.rfind(tattletale) # assumption/hope: the next 32 bytes are all encoded '=' xorfull = bytearray() for d in decoded[xorfullstart:xorfullstart + 32]: xorfull.append(d ^ ord('=')) # decrypt the bytes with the assumed key decrypted = bytearray() for i in range(len(decoded)): decrypted.append(decoded[i] ^ xorfull[i % 32]) return decrypted if __name__ == '__main__': import ascii85 payload = ascii85.loadpayload('layers/layer3.txt') decoded = ascii85.decode(payload) decoded = decrypt(decoded) print(decoded.decode()[0:500])