Merge pull request #201 from t0rr3sp3dr0/master

ROT13
This commit is contained in:
Harshil 2017-10-31 10:44:14 +05:30 committed by GitHub
commit 991d09af9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

24
ciphers/rot13.py Normal file
View File

@ -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()