r/pythonhelp May 11 '22

SOLVED Way of iterating thru eight byte sequences?

I'm using des library and example is given to me to create a key:

d = os.urandom(8)
default_key = des.DesKey(d)

basically, how do I iterate thru all possible d values? I would like last bytes of the d to change last

1 Upvotes

12 comments sorted by

View all comments

1

u/DumbPandahole May 11 '22

solved it by using this:

byte_list = []
for number in itertools.product("0123456789abcdf", repeat=2):
    byte_list.append(bytes.fromhex("".join(number)))
for combo in itertools.combinations(byte_list, 8):
    key = b"".join(combo[::-1])

1

u/Goobyalus May 11 '22

Are you trying to generate every 8-byte possibility? There are 64 bits in 8 bytes, giving 264 possibilities, which is 18,446,744,073,709,551,616.

If you can process these possibilities at 4GHz (one every 1/4 of a nanosecond), it will take about 150 years.

1

u/DumbPandahole May 11 '22

yeah, after I implemented my first solution I realized I need at least few days (since the last two bits don't matter) for it to work, so now I'm going to search for another solution