File tree 1 file changed +27
-7
lines changed
1 file changed +27
-7
lines changed Original file line number Diff line number Diff line change 1
1
import base64
2
2
3
3
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" )
10
28
11
29
12
30
if __name__ == "__main__" :
13
- main ()
31
+ import doctest
32
+
33
+ doctest .testmod ()
You can’t perform that action at this time.
0 commit comments