Created
March 27, 2016 17:11
-
-
Save 0xquad/b56ba52f40803be77440 to your computer and use it in GitHub Desktop.
Generate an array of bytes based on different strategies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def dump(stream): | |
for i in range(len(stream)): | |
print('{:02x}'.format(stream[i]), end='') | |
print() | |
strategies = ( | |
lambda i: i, | |
lambda i: i * 0x11, | |
lambda i: i * 0x10, | |
lambda i: 16 - i, | |
lambda i: 0x11 * (16 - i), | |
lambda i: 0x10 * (15 - i), | |
lambda i: 0, | |
lambda i: 0xff, | |
lambda i: 1 << i, | |
lambda i: (0x0123456789abcdef0123456789abcdef).to_bytes(16, 'big')[i], | |
lambda i: -i, | |
lambda i: ~i, | |
lambda i: 0x40 + i, | |
lambda i: 0xa0 + i, | |
lambda i: 0xb0 + i, | |
) | |
def gen_bytes(strategy, length=16): | |
return list(strategy(i) % 256 for i in range(length)) | |
for strategy in strategies: | |
dump(gen_bytes(strategy)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment