我整天都在做简单的编程挑战,努力学习和实践。然而,我似乎总是在效率上失败。如果不使用内置代码(例如 encode 方法),我是否可以提高程序的效率(我的一般效率)?
import string
alph = string.ascii_lowercase
def encrypt(text):
encryption = ""
for character in text:
index = 0
shift = 0
for letter in alph:
if letter == character:
if index > 23:
shift = abs(26 - (index+3))
encryption += alph[shift]
break
shift = index + 3
encryption += alph[shift]
index += 1
return encryption
def decrypt(text):
decryption = ""
for character in text:
index = 0
shift = 0
for letter in alph:
if letter == character:
if index < 3:
shift = abs(26 - (index+3))
decryption += alph[shift]
break
shift = index - 3
decryption += alph[shift]
index += 1
return decryption