Ich habe einen Text, der verschlüsselt, komprimiert und in einem bestimmten Format werden soll.
Dies geschieht durch:
Code: Alles auswählen
contents = zlib.compress(contents)
contents = tollekryptographischefunktion(password, contents.strip())
contents = zlib.compress(contents)
Code: Alles auswählen
for i in range(0, len(infilecontents)):
print ord(infilecontents[i]),
Code: Alles auswählen
120 156 1 32 0 223 255 199 49 14 225 96 246 70 122 214 237 227 30 75 127 173 56 155 245 122 199 206 203 16 65 78 155 243 133 175 50 245 45 34 146 17 144
So weit so gut - jetzt der Rückweg:
Ich parse das Format, bis ich bei diesen Zahlen bin. Auch hier bekomme ich als Debug-Ausgabe:
Code: Alles auswählen
120 156 1 32 0 223 255 199 49 14 225 96 246 70 122 214 237 227 30 75 127 173 56 155 245 122 199 206 203 16 65 78 155 243 133 175 50 245 45 34 146 17 144
Code: Alles auswählen
contents = ""
for byte in bytes:
byte = chr(byte)
contents += byte
Mein Versuch, das ganze zu decodieren, sieht so aus:
Code: Alles auswählen
contents = zlib.decompress(contents)
contents = tollekryptographischefunktionDecrypt(password, contents)
contents = zlib.decompress(contents)
Code: Alles auswählen
Traceback (most recent call last):
[..]
contents = zlib.decompress(contents)
zlib.error: Error -3 while decompressing data: incorrect header check
Es kommt noch interessanter:
Wenn ich mein Programm in einer interaktiven python-Session als Modul lade und manuell ausführe und contents vor dem decompress in eine Variable schreibe und diese auf der Konsole ausgebe, scheint alles zu funktionieren:
Code: Alles auswählen
>>> g.debug
'x\x9c\x01 \x00\xdf\xff\xc71\x0e\xe1`\xf6Fz\xd6\xed\xe3\x1eK\x7f\xad8\x9b\xf5z\xc7\xce\xcb\x10AN\x9b\xf3\x85\xaf2\xf5-"\x92\x11\x90'
>>> zlib.decompress('x\x9c\x01 \x00\xdf\xff\xc71\x0e\xe1`\xf6Fz\xd6\xed\xe3\x1eK\x7f\xad8\x9b\xf5z\xc7\xce\xcb\x10AN\x9b\xf3\x85\xaf2\xf5-"\x92\x11\x90')
'\xc71\x0e\xe1`\xf6Fz\xd6\xed\xe3\x1eK\x7f\xad8\x9b\xf5z\xc7\xce\xcb\x10AN\x9b\xf3\x85\xaf2\xf5-'
>>> zlib.decompress(g.debug)
'\xc71\x0e\xe1`\xf6Fz\xd6\xed\xe3\x1eK\x7f\xad8\x9b\xf5z\xc7\xce\xcb\x10AN\x9b\xf3\x85\xaf2\xf5-'
Weitere Infos:
Die Datei enthält zwar ein,
Code: Alles auswählen
# -*- coding: utf-8 -*-
Kann mir irgendjemand weiterhelfen?