Skip to content

Instantly share code, notes, and snippets.

@birchmd

birchmd/hex2b58 Secret

Created February 28, 2022 20:17
Show Gist options
  • Save birchmd/a336269596651992ed9b742c843b9b0f to your computer and use it in GitHub Desktop.
Save birchmd/a336269596651992ed9b742c843b9b0f to your computer and use it in GitHub Desktop.
Converts hex input on stdin to base58
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import base58, sys
hex_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
if __name__ == '__main__':
for line in sys.stdin:
input = line.strip().replace('0x', '').lower()
hex_only = ''.join(c for c in input if c in hex_chars)
print(base58.b58encode(bytes.fromhex(hex_only)).decode('utf8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment