Generate 9-digit keys with Python

Asked

Viewed 391 times

1

I would like to generate several values following the pattern XXX-XXX-XXX where all possibilities will be generated for example:

1 - 000-000-000
2 - 000-000-001
3 - 000-000-002
.
.
.
x - 999-999-999
.
.
.
x - 000-000-00A
x - 000-000-00B
.
.
.
x - A8S-71J-8SH
.
.
.
x - ZZZ-ZZZ-ZZZ

How best to make this code to follow the proposed standard?

  • Only valid letters and numbers? No lower case letters, no scores?

  • Yes @Andersoncarloswoss only numbers and uppercase letters without score even if filling the values of X in XXX-XXX-XXX

  • 2

    you have a right answer, for a task that with almost every chance is completely useless. You’re talking about over 5 trillion combinations - no ordinary device can even hack them all (although it’s possible nowadays with a dedicated data center, I believe). Even if you don’t want to store, Python will be able to generate a few million of these per second - it would take you about 10 days to generate them all on a common PC - unless you’re making a Joy-Force to try to find the static data key you have at hand, are doing wrong.

1 answer

7


You can use the method combinations module itertools


import itertools
import string

for row in itertools.combinations(string.digits + string.ascii_uppercase, 9):
  s = ''.join(row)
  print('{}-{}-{}'.format(s[:3], s[3:6], s[6:9]))
  • Well scored... Thanks ! Edit: If you do not concatenate the string, the output will be 3 tuples.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.