Created
August 19, 2016 17:59
-
-
Save mlshv/c6327226567cc915dd8f03722e9f8a4b to your computer and use it in GitHub Desktop.
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
| # simple hexdump function | |
| # it's very similar to hexdump from Black Hat Python, but it runs on Python 3 | |
| def hexdump(src, length=16): | |
| result = [] | |
| digits = 2 | |
| for i in range(0, len(src), length): | |
| s = src[i:i+length] | |
| hexa = ' '.join(["%0*X" % (digits, ord(x)) for x in s]) | |
| text = ''.join([x if 0x20 <= ord(x) < 0x7F else '.' for x in s]) | |
| result.append("%04X %-*s %s" % (i, length*(digits+1), hexa, text)) | |
| print('\n'.join(result)) | |
| hexdump("No matter which way you go\n" + | |
| "No matter which way you stay\n" + | |
| "You're out of my mind, out of my mind\n" + | |
| "Out of my mind, out of my mind") | |
| """ Output: | |
| 0000 4E 6F 20 6D 61 74 74 65 72 20 77 68 69 63 68 20 No matter which | |
| 0010 77 61 79 20 79 6F 75 20 67 6F 0A 4E 6F 20 6D 61 way you go.No ma | |
| 0020 74 74 65 72 20 77 68 69 63 68 20 77 61 79 20 79 tter which way y | |
| 0030 6F 75 20 73 74 61 79 0A 59 6F 75 27 72 65 20 6F ou stay.You're o | |
| 0040 75 74 20 6F 66 20 6D 79 20 6D 69 6E 64 2C 20 6F ut of my mind, o | |
| 0050 75 74 20 6F 66 20 6D 79 20 6D 69 6E 64 0A 4F 75 ut of my mind.Ou | |
| 0060 74 20 6F 66 20 6D 79 20 6D 69 6E 64 2C 20 6F 75 t of my mind, ou | |
| 0070 74 20 6F 66 20 6D 79 20 6D 69 6E 64 t of my mind | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment