import string key = 3 def decode(text): print "key:", key enc = "" columnlen = len(text) // key if len(text) % key != 0: columnlen += 1 print "Textlänge:", len(text) print "Zeilen:", columnlen for k in range (columnlen): for n in range(1+ (len(text) // columnlen)): i = k + (columnlen * n) if i < len(text): ch = text[i] else: ch = "" enc += ch return enc fInp = open("secret.txt") text = fInp.read() fInp.close() print "Krypto:\n", text krypto = decode(text) print "Message:\n", krypto fOut = open("message.txt", "w") for ch in krypto: fOut.write(ch) fOut.close()