Created
October 3, 2019 01:04
-
-
Save rmrfslashbin/8f1c65c4090cc1fd116561d39417aa98 to your computer and use it in GitHub Desktop.
Convert a string to hex
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
#!/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