Python/ciphers/rot13.py
Christian Clauss 47a9ea2b0b
Simplify code by dropping support for legacy Python (#1143)
* Simplify code by dropping support for legacy Python

* sort() --> sorted()
2019-08-19 15:37:49 +02:00

25 lines
468 B
Python

def dencrypt(s, n):
out = ''
for c in s:
if c >= 'A' and c <= 'Z':
out += chr(ord('A') + (ord(c) - ord('A') + n) % 26)
elif c >= 'a' and c <= 'z':
out += chr(ord('a') + (ord(c) - ord('a') + n) % 26)
else:
out += c
return out
def main():
s0 = 'HELLO'
s1 = dencrypt(s0, 13)
print(s1) # URYYB
s2 = dencrypt(s1, 13)
print(s2) # HELLO
if __name__ == '__main__':
main()