coding.py
Code: Alles auswählen
# -*- coding: cp1252 -*-
letters = [' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~']
def encode(pw,code):
#pw = passwort
code2 = []
for i in code:
code2.append(letters.index(i))
code3 = ""
ap = 0
apo = 0
px = 0
for i in code2:
ap = i+int(str(pw)[px])+apo
while ap<0:
ap += 95
while ap > 94:
ap -= 95
px += 1
if px == len(str(pw)):
px = 0
code3+=str(ap)
print int(i), apo, int(str(pw)[px]), ap
apo = i
print " "
return code3
def decode(pw,code):
code2 = []
for i in range(0, int(len(code)/2)):
j = 2*i
code2.append(code[j]+code[j+1])
ap = 0
apo = 0
px = 0
code3 = ""
for k in code2:
ap = int(k)-apo-int(str(pw)[px])
while ap<0:
ap += 95
while ap > 94:
ap -= 95
px += 1
if px == len(str(pw)):
px = 0
print ap, apo, int(str(pw)[px]), int(k)
apo=ap
code3+=letters[ap]
return code3
start.py
Code: Alles auswählen
import coding
# -*- coding: cp1252 -*-
variable = raw_input()
print coding.decode(123,coding.encode(123,variable))
(die Printbefehle sind zur übersicht, sie sollten Identisch sein vor und hinter dem Leerzeichen, sind sie aber nur bis zu einer bestimmten Stelle)