Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import string
  2.  
  3. def hexdump(src, length=16, sep='.'):
  4. DISPLAY = string.digits + string.letters + string.punctuation
  5. FILTER = ''.join(((x if x in DISPLAY else '.') for x in map(chr, range(256))))
  6. lines = []
  7. for c in xrange(0, len(src), length):
  8. chars = src[c:c+length]
  9. hex = ' '.join(["%02x" % ord(x) for x in chars])
  10. if len(hex) > 24:
  11. hex = "%s %s" % (hex[:24], hex[24:])
  12. printable = ''.join(["%s" % FILTER[ord(x)] for x in chars])
  13. lines.append("%08x: %-*s |%s|\n" % (c, length*3, hex, printable))
  14. print ''.join(lines)
  15.  
  16. if __name__ == '__main__':
  17. data = ''.join(chr(x) for x in range(256))
  18. hexdump(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement