Skip to content

Instantly share code, notes, and snippets.

@nick3499
Created July 14, 2023 00:04
Show Gist options
  • Save nick3499/b881d7d6983d8374f2cdb1bd8ab53e87 to your computer and use it in GitHub Desktop.
Save nick3499/b881d7d6983d8374f2cdb1bd8ab53e87 to your computer and use it in GitHub Desktop.
Generate Hexadecimal Pattern: random.randrange()
#!/bin/python3
'''
generate password based on hex pattern
93b44021-a479-5fc2-4037-08b690031c73
xxxx-xx-xx-xx-xxxxxx
'''
from random import randrange
patt = [4, 2, 2, 2, 6]
hex_sets = []
for p in patt:
hex_sets.append(''.join([hex(randrange(0, 255))[2:] for a in range(p)]))
print('-'.join(hex_sets))
@nick3499
Copy link
Author

The purpose for this script was to generate any pattern of hexdecimal octets for specific random passwords

93b44021-a479-5fc2-4037-08b690031c73 becomes an example of a pseudo-randomly generated hex pattern for password creation but values in patt can be changed in order to suit any particular pattern—also add to the list; increase the number of values.

xxxx-xx-xx-xx-xxxxxx notice how this pattern example represents the actual values in patt, which are based on the number of octets needed, instead of the total value of hexits. In other words, the hexadecimal octet a4 contains the hexits a and 4.

Even though patt contains [4, 2, 2, 2, 6] for my original purpose, it could be changed to [4, 3, 4, 3, 6, 5] for your purpose, for example.

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