Skip to content

Instantly share code, notes, and snippets.

@sourceperl
Last active October 30, 2018 10:49
Show Gist options
  • Save sourceperl/dfc8d9f94dc44489a630f46b14f48e6c to your computer and use it in GitHub Desktop.
Save sourceperl/dfc8d9f94dc44489a630f46b14f48e6c to your computer and use it in GitHub Desktop.
TTN utils
#!/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)
#!/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