Created
December 11, 2018 02:10
-
-
Save samredai/9ee1ce5c0ca81f6f3659ada12636a9ee to your computer and use it in GitHub Desktop.
Python: Encode a string into bytes using base64, then decode it and convert it back to a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
base64.b64encode(b'Encode this string.') | |
#b'RW5jb2RlIHRoaXMgc3RyaW5nLg==' | |
decodedBytes = base64.b64decode(b'RW5jb2RlIHRoaXMgc3RyaW5nLg==') | |
print(decodedBytes) | |
#b'Encode this string.' | |
decodedString = decodedBytes.decode('utf-8') | |
print(decodedString) | |
#Encode this string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment