We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 87a954a commit 8bc4603Copy full SHA for 8bc4603
ciphers/base16.py
@@ -1,13 +1,22 @@
1
import base64
2
3
4
-def main():
5
- inp = input("->")
+def encode_to_b16(inp: str) -> bytes:
+ """
6
+ Encodes a given utf-8 string into base-16.
7
+ >>> encode_to_b16('Hello World!')
8
+ b'48656C6C6F20576F726C6421'
9
+ >>> encode_to_b16('HELLO WORLD!')
10
+ b'48454C4C4F20574F524C4421'
11
+ >>> encode_to_b16('')
12
+ b''
13
14
encoded = inp.encode("utf-8") # encoded the input (we need a bytes like object)
15
b16encoded = base64.b16encode(encoded) # b16encoded the encoded string
- print(b16encoded)
- print(base64.b16decode(b16encoded).decode("utf-8")) # decoded it
16
+ return b16encoded
17
18
19
if __name__ == "__main__":
- main()
20
+ import doctest
21
+
22
+ doctest.testmod()
0 commit comments