Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using regex, ord(), chr() solution in Clear category for Caesar Cipher (decryptor) by H0r4c3
import re
def to_decrypt(cryptotext, delta):
result = list()
regex = re.compile('[\s?\w+\s?]')
cryptotext_ok = regex.findall(cryptotext)
for item in cryptotext_ok:
if item == ' ':
result.append(item)
elif item == '_':
pass
else:
new_ord = 97 + ((ord(item) - 97 + delta) % 26)
result.append(chr(new_ord))
return ''.join(result)
if __name__ == '__main__':
print("Example:")
print(to_decrypt('abc', 10))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert to_decrypt("!d! [e] &f*", -3) == "a b c"
assert to_decrypt("x^$# y&*( (z):-)", 3) == "a b c"
assert to_decrypt("iycfbu!@# junj%&", -16) == "simple text"
assert to_decrypt("*$#%swzybdkxd !)(^#%dohd", -10) == "important text"
assert to_decrypt("fgngr **&&frperg^__^", 13) == "state secret"
print("Coding complete? Click 'Check' to earn cool rewards!")
Dec. 10, 2021
Comments: