Skip to content

Instantly share code, notes, and snippets.

@sanzaru
Last active May 13, 2020 07:56
Show Gist options
  • Save sanzaru/9035e0dd25bef72faa9a to your computer and use it in GitHub Desktop.
Save sanzaru/9035e0dd25bef72faa9a to your computer and use it in GitHub Desktop.
Simple python script to byte encode a string
import array, sys
ARGV = sys.argv
if len(ARGV) <= 1 or not ARGV[1]:
print 'usage: ' + ARGV[0] + ' <string to encode>'
sys.exit(1)
inp = str(ARGV[1])
bc = ''
for item in [elem.encode("hex") for elem in inp]:
bc = bc + '\\x' + item
print bc
# Decode, just for a prove
print bc.replace('\\x', '').decode("hex")
@sanzaru
Copy link
Author

sanzaru commented Jan 31, 2016

That's easy. Taken the string bc from above it would be:

print bc.replace('\\x', '').decode("hex")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment