Skip to content

Instantly share code, notes, and snippets.

@rmrfslashbin
Created October 3, 2019 01:04
Show Gist options
  • Save rmrfslashbin/8f1c65c4090cc1fd116561d39417aa98 to your computer and use it in GitHub Desktop.
Save rmrfslashbin/8f1c65c4090cc1fd116561d39417aa98 to your computer and use it in GitHub Desktop.
Convert a string to hex
#!/usr/bin/env python
import binascii
def getHex(string):
x = binascii.hexlify(string.encode())
y = str(x,'ascii')
print("hex ", y)
x_unhexed = binascii.unhexlify(x)
x_ascii = str(x_unhexed,'ascii')
print("string", x_ascii)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Convert a string to hex")
parser.add_argument("string", type=str, nargs=1, help="String to convert")
args = parser.parse_args()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment