coder

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
while True:
string = input("Enter command and string:\n")
en = True
for i in string:
if ord(i) > 127:
en = False
break
if en:
if string[0:6] == "encode":
decoded = string[7:]
encoded = ""
prev = len(decoded)
for i in decoded:
now = ord(i)
encoded += chr((now + prev) % 128)
#print(str(now) + " + " + str(prev) + " = " + str((now + prev) % 128) + "( " + chr((now + prev) % 128) + " )")
prev = now
print(encoded)
#print(len(encoded), "==", len(decoded))
elif string[0:6] == "decode":
encoded = string[7:]
decoded = ""
prev = len(encoded)
for i in encoded:
now = ord(i)
decoded += chr(((now - prev)) % 128)
#print(str(now) + " - " + str(prev) + " = " + str(((now - prev)) % 128) + " (" + chr(((now - prev)) % 128) + ")")
prev = ((now - prev)) % 128
print(decoded)
#print(len(decoded), "==", len(encoded))
else:
print("Command uncorrect!")
else:
print("Only english, please!")