def decode(ww,key_open): rev="" for w1 in ww: sx=dic.index(w1) sx=sx+key_open if sx>25:sx=sx-25 if sx<0:sx=sx+25 rev=rev+dic[sx] return rev def code(ww,key): rev="" for w1 in ww: sx=dic.index(w1) sx=sx+key if sx>25:sx=sx-25 if sx<0:sx=sx+25 rev=rev+dic[sx] return rev dx="abcdefghijklmnopqrstuvwxyz" dic=[] for d1 in dx: dic.append(d1) word="thank" key=2 key_open=-2 ch=code(word,key) rev=decode(ch,key_open) de=0 if rev==word:de=100 if de>50:print(rev) if de<50:print("失敗")