Lesson 26: Riddle
Post date: May 18, 2018 2:58:32 PM
riddle = "hVObYomcioTcfoZSOfbWbUodfcUfOaaWbU"
abc = "abcdefghijklmnopqrstuvwxyz !@#$%^&*()_+:?><ABCDEFGHIJKLMNOPQRSTUVWXYZ"
length = len(abc)
def position(c):
return abc.find(c)
def getkey(password):
key = 0
for c in password: key += position(c)
return key
def shift(c,x):
x = x % length
y = x + abc.find(c)
if y > length - 1: y = y % length
return abc[y]
def crypt(text, password, x):
key = getkey(password)
encryptedtext = ""
for c in text:
encryptedtext += shift(c, x * key)
return encryptedtext
text = input("Give me a text:")
password = input("Give me a password:")
secretmsg = crypt(text,password, 1)
print(secretmsg)
print(crypt(secretmsg, password, -1))
message = input("Give me encoded msg:")
for x in range(1, len(abc)):
msg = ""
for c in message:
msg += shift(c,x)
print(str(x) + ":" + msg)
input()