Created
November 17, 2017 13:28
-
-
Save fkohlgrueber/52c7cd821ada5979f82a44c77742c07a to your computer and use it in GitHub Desktop.
This file contains 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment