Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- def to_hex(byte_string):
- return " ".join("{:02x}".format(b) for b in byte_string)
- def to_bin(byte_string):
- return " ".join("{:08b}".format(b) for b in byte_string)
- def test(input_string, bin_output=False):
- fmt = to_bin if bin_output else to_hex
- if isinstance(input_string, list):
- input_string = bytes(input_string)
- out = subprocess.check_output(("./orakel", input_string))[:-1]
- print("[{}] (len={}) -> [{}] (len={})".format(
- fmt(input_string),
- len(input_string),
- fmt(out),
- len(out)))
- #################################################################
- # Write tests below:
- #################################################################
- if __name__ == '__main__':
- # string as input
- test(b"abc")
- # integer ascii codes as input
- test([97, 98, 99])
- # ...or as hex
- test([0x61, 0x62, 0x63])
- # ...or as binary
- test([0b01100001, 0b01100010, 0b01100011])
- # display as binary instead of hex
- test(b"abc", bin_output=True)
Add Comment
Please, Sign In to add comment