Last active
May 22, 2023 06:46
-
-
Save ochaloup/b3c2c2410f63782b75abcda96d261fea to your computer and use it in GitHub Desktop.
Python script to convert base64 formatted string to uint8 binary data array
This file contains 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
#!~/.pyenv/shims/python3 | |
# Usage: | |
# frombase64.py o9lBUTXmHRwGAAAAaGVsbG8z | |
# Output: | |
# [163,217,65,81,53,230,29,28,6,0,0,0,104,101,108,108,111,51] | |
import base64 | |
import sys | |
if len(sys.argv) != 2: | |
print(f"Expecting argument of base64 string, not provided. Arguments: {sys.argv}") | |
exit(1) | |
string_key = sys.argv[1] | |
byte_array = base64.b64decode(string_key) | |
json_string = "[" + ",".join(map(lambda b: str(b), byte_array)) + "]" | |
print(json_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment