Skip to content

Commit 991d09a

Browse files
authored
Merge pull request TheAlgorithms#201 from t0rr3sp3dr0/master
ROT13
2 parents 9dfd0a6 + 75af340 commit 991d09a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

ciphers/rot13.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def dencrypt(s, n):
2+
out = ''
3+
for c in s:
4+
if c >= 'A' and c <= 'Z':
5+
out += chr(ord('A') + (ord(c) - ord('A') + n) % 26)
6+
elif c >= 'a' and c <= 'z':
7+
out += chr(ord('a') + (ord(c) - ord('a') + n) % 26)
8+
else:
9+
out += c
10+
return out
11+
12+
13+
def main():
14+
s0 = 'HELLO'
15+
16+
s1 = dencrypt(s0, 13)
17+
print(s1) # URYYB
18+
19+
s2 = dencrypt(s1, 13)
20+
print(s2) # HELLO
21+
22+
23+
if __name__ == '__main__':
24+
main()

0 commit comments

Comments
 (0)