Python/ciphers/rot13.py

25 lines
468 B
Python
Raw Normal View History

2017-10-29 17:44:54 +00:00
def dencrypt(s, n):
2019-10-05 05:14:13 +00:00
out = ""
2017-10-29 17:44:54 +00:00
for c in s:
2019-10-05 05:14:13 +00:00
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)
2017-10-29 17:44:54 +00:00
else:
out += c
return out
def main():
2019-10-05 05:14:13 +00:00
s0 = "HELLO"
2017-10-29 17:44:54 +00:00
s1 = dencrypt(s0, 13)
print(s1) # URYYB
s2 = dencrypt(s1, 13)
print(s2) # HELLO
2019-10-05 05:14:13 +00:00
if __name__ == "__main__":
2017-10-29 17:44:54 +00:00
main()