1

I'm trying to generate all possible hex bytes and set them to a byte string. This is,

I have this:

iv = b"\x14\x42\x31\xB5\xFE\x52\xA3\x32\x3E\xEA\xA4\x30\x00\x11\x23\xFE"

And for instance, I want to try all possible values for byte 7:

b"\x14\x42\x31\xB5\xFE\x52\xA3\ + x00\ + x3E\xEA\xA4\x30\x00\x11\x23\xFE"

b"\x14\x42\x31\xB5\xFE\x52\xA3\ + x01\ + x3E\xEA\xA4\x30\x00\x11\x23\xFE" 

b"\x14\x42\x31\xB5\xFE\x52\xA3\ + x02\ + x3E\xEA\xA4\x30\x00\x11\x23\xFE"

(...)

b"\x14\x42\x31\xB5\xFE\x52\xA3\ + xFF\ + x3E\xEA\xA4\x30\x00\x11\x23\xFE"

How can I iterate and manipulate these structures in python?

Thank you for your time

1 Answer 1

2

You can use for loop

all_combination = []
for i in range(256):  
    all_combination.append(iv[:7] + bytes([i]) + iv[8:])
[b'\x14B1\xb5\xfe\x00\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x01\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x02\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x03\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x04\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x05\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x06\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x07\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x08\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\t\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\n\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x0b\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x0c\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\r\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x0e\xa32>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfe\x0f\xa32>\xea\xa40\x00\x11#\xfe'
.
.
.
 b'\x14B1\xb5\xfeR\xa3\xfd>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfeR\xa3\xfe>\xea\xa40\x00\x11#\xfe',
 b'\x14B1\xb5\xfeR\xa3\xff>\xea\xa40\x00\x11#\xfe']
Sign up to request clarification or add additional context in comments.

2 Comments

I thought that was not working because of the print results. Now I see they are formatted to be output but the inner data is still correct. Fantastic!
yes, you are correct. the bytes are represented in character

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.