From b47b1e7bfca01108e7329bf6ddf723f858bcca51 Mon Sep 17 00:00:00 2001 From: godfreyduke Date: Fri, 11 Oct 2019 22:03:46 -0700 Subject: [PATCH] Add a rot13 cipher in response to Issue #7 --- Ciphers/rot13.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Ciphers/rot13.py diff --git a/Ciphers/rot13.py b/Ciphers/rot13.py new file mode 100644 index 0000000..966603d --- /dev/null +++ b/Ciphers/rot13.py @@ -0,0 +1,21 @@ +#rot13 +OFFSET_LOWER = ord('a') +OFFSET_UPPER = ord('A') + +def rot13(text): + rot13_text = '' + for i in range(len(text)): + ch = text[i] + if ch.isalpha(): + if(ch.islower()): + offset = OFFSET_LOWER + else: + offset = OFFSET_UPPER + rot13_text += chr(((ord(ch)-offset+13)%26+offset)) + else: + rot13_text += ch + return rot13_text + +plain_text = input("Enter the string: ") +print(rot13(plain_text)) +print(rot13(rot13(plain_text)))