Last active
October 30, 2018 10:49
-
-
Save sourceperl/dfc8d9f94dc44489a630f46b14f48e6c to your computer and use it in GitHub Desktop.
TTN utils
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 python3 | |
import random | |
key8 = ''.join(random.choice('0123456789ABCDEF') for n in range(16)) | |
key16 = ''.join(random.choice('0123456789ABCDEF') for n in range(32)) | |
print("generate 8 bytes key: %s" % key8) | |
print("generate 16 bytes key: %s" % key16) |
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 python3 | |
import argparse | |
import binascii | |
# parse args | |
parser = argparse.ArgumentParser() | |
parser.add_argument("key", type=str) | |
parser.add_argument("-r", "--reverse", action="store_true", default=False) | |
args = parser.parse_args() | |
s = "" | |
bytes_l = list(binascii.a2b_hex(args.key)) | |
if args.reverse: | |
bytes_l.reverse() | |
for b in bytes_l: | |
if s: | |
s += ", " | |
s += "0x%02x" % b | |
print(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment