From 75af340aff08b0b1b20775b447fc6a0766f79518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20T=C3=B4rres?= Date: Sun, 29 Oct 2017 14:44:54 -0300 Subject: [PATCH] ROT13 --- ciphers/rot13.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ciphers/rot13.py diff --git a/ciphers/rot13.py b/ciphers/rot13.py new file mode 100644 index 000000000..208de4890 --- /dev/null +++ b/ciphers/rot13.py @@ -0,0 +1,24 @@ +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()