Guest User

Untitled

a guest
Nov 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import subprocess
  2.  
  3.  
  4. def to_hex(byte_string):
  5. return " ".join("{:02x}".format(b) for b in byte_string)
  6.  
  7.  
  8. def to_bin(byte_string):
  9. return " ".join("{:08b}".format(b) for b in byte_string)
  10.  
  11.  
  12. def test(input_string, bin_output=False):
  13. fmt = to_bin if bin_output else to_hex
  14. if isinstance(input_string, list):
  15. input_string = bytes(input_string)
  16. out = subprocess.check_output(("./orakel", input_string))[:-1]
  17. print("[{}] (len={}) -> [{}] (len={})".format(
  18. fmt(input_string),
  19. len(input_string),
  20. fmt(out),
  21. len(out)))
  22.  
  23. #################################################################
  24. # Write tests below:
  25. #################################################################
  26.  
  27.  
  28. if __name__ == '__main__':
  29.  
  30. # string as input
  31. test(b"abc")
  32.  
  33. # integer ascii codes as input
  34. test([97, 98, 99])
  35. # ...or as hex
  36. test([0x61, 0x62, 0x63])
  37. # ...or as binary
  38. test([0b01100001, 0b01100010, 0b01100011])
  39.  
  40. # display as binary instead of hex
  41. test(b"abc", bin_output=True)
Add Comment
Please, Sign In to add comment