FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TheAlgorithms-Python/ciphers/base16.py at master · windNight/TheAlgorithms-Python · GitHub
windNight
/
TheAlgorithms-Python
Public
forked from
TheAlgorithms/Python
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TheAlgorithms-Python
/
ciphers
/
base16.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
22 lines (17 loc) · 545 Bytes
Breadcrumbs
TheAlgorithms-Python
/
ciphers
/
base16.py
Copy path
File metadata and controls
22 lines (17 loc) · 545 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import
base64
def
encode_to_b16
(
inp
:
str
)
->
bytes
:
"""
Encodes a given utf-8 string into base-16.
>>> encode_to_b16('Hello World!')
b'48656C6C6F20576F726C6421'
>>> encode_to_b16('HELLO WORLD!')
b'48454C4C4F20574F524C4421'
>>> encode_to_b16('')
b''
"""
encoded
=
inp
.
encode
(
"utf-8"
)
# encoded the input (we need a bytes like object)
b16encoded
=
base64
.
b16encode
(
encoded
)
# b16encoded the encoded string
return
b16encoded
if
__name__
==
"__main__"
:
import
doctest
doctest
.
testmod
()
Back
|
FazBrowse Home
|
New Git URL