-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrot13.py
More file actions
executable file
·36 lines (27 loc) · 1.02 KB
/
rot13.py
File metadata and controls
executable file
·36 lines (27 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""rot13.py
At https://github.com/wilsonmar/python-samples/blob/main/rot13.py
git commit -m "v004 + unittest :rot13.py"
STATUS: Working
This program provides a utility to encode text using "ROT13"
(Rotation 13 characters out).
based on: https://en.wikipedia.org/wiki/ROT13
"""
import unittest
# TODO: Make the string a parameter argument:
def encode_rot13(string):
# FIXME: Handle special characters
for abcd in ["abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]:
string = ''.join([abcd[(abcd.index(char) + 13) % 26] if char in abcd else char for char in string])
return string
if __name__ == "__main__":
# unittest.main()
# TODO: Obtain from CLI attribute
# TODO: Add unit test assertion
string = "The quick brown fox jumps over the lazy dog"
# Gur dhvpx oebja sbk whzcf bire gur ynml qbt
print(f"Encode string : {string}")
encoded = encode_rot13(string)
print(f"Encoded string: {encoded}")
# TODO: Send out log.