Skip to content

Commit 01b5b55

Browse files
Split into functions, Add doctests
1 parent 1a7745a commit 01b5b55

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

ciphers/base85.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
import base64
22

33

4-
def main() -> None:
5-
inp = input("->")
6-
encoded = inp.encode("utf-8") # encoded the input (we need a bytes like object)
7-
a85encoded = base64.a85encode(encoded) # a85encoded the encoded string
8-
print(a85encoded)
9-
print(base64.a85decode(a85encoded).decode("utf-8")) # decoded it
4+
def base85_encode(string: str) -> bytes:
5+
"""
6+
>>> base85_encode("")
7+
b''
8+
>>> base85_encode("12345")
9+
b'0etOA2#'
10+
>>> base85_encode("base 85")
11+
b'@UX=h+?24'
12+
"""
13+
# encoded the input to a bytes-like object and then a85encode that
14+
return base64.a85encode(string.encode("utf-8"))
15+
16+
17+
def base85_decode(a85encoded: bytes) -> str:
18+
"""
19+
>>> base85_decode(b"")
20+
''
21+
>>> base85_decode(b"0etOA2#")
22+
'12345'
23+
>>> base85_decode(b"@UX=h+?24")
24+
'base 85'
25+
"""
26+
# a85decode the input into bytes and decode that into a human readable string
27+
return base64.a85decode(a85encoded).decode("utf-8")
1028

1129

1230
if __name__ == "__main__":
13-
main()
31+
import doctest
32+
33+
doctest.testmod()

0 commit comments

Comments
 (0)