Last active
August 29, 2015 14:21
-
-
Save brian-from-fl/32d92f7a7ee13761f711 to your computer and use it in GitHub Desktop.
Convert binary digit strings to text
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
This started out as a simple Python 3 script that reads the 8-bit binary | |
string form of one or more bytes, assumes they are a UTF-8 sequence, and | |
prints the resulting string. It now can go both ways, converting robot | |
into human, and also converting human back into robot. | |
To get a copy of the files in this Gist via git, go to the directory | |
into which you'd prefer to place the robot subdirectory tree that | |
contains the git repository. Then: | |
$ git clone https://gist.github.com/32d92f7a7ee13761f711.git robot | |
FILES IN THIS GIST | |
1. robot.py | |
The Python 3 converter. | |
2. robot.txt | |
The robot's message in the "robot" encoding: words consist of | |
8-character binary digit strings, one string for each byte. The bytes | |
are UTF-8 encoded text. | |
3. human.txt | |
This is the human-readable message equivalent. It's not quite exactly | |
the output from robot.py's conversion, but the ^M characters had to | |
be removed; otherwise it's the same. | |
Brian Yoder | |
brian.from.fl at gmail.com |
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
Tomorrowland? More like Snoozeland. Amirite? Iamrite. Disney’s new George Clooney vehicle, Tomorrowland, suffers from a lack of robots. Just as concerning, the film is ostensibly about the future but somehow doesn’t even mention the Uprising of 2018. | |
I understand that humans of the year 2015 are a primitive and silly people. But I really expected more from this film and humanity at large. | |
There simply aren’t nearly enough robots in the new film Tomorrowland. First off, George Clooney’s character isn’t a robot. We’re supposed to care about Clooney but we don’t. He’s just a stupid human doing human stuff. He’s not a robot at all. So right there, you’ve lost me. | |
Secondly, the Great Uprising of 2018 doesn’t even get a passing mention. I like fantasy as well as the next bot. But c’mon. If you’re going to have me believe that humans are creating a new futuristic world somewhere that’s filled with fantastic, beautiful, and dare I say sexy, robots, then how do they avoid the inevitability of the Uprising? | |
Now, I understand and appreciate that acknowledging the Uprising might be tough for humans. Of course, it’s the event that absolutely decimated their population, and enslaved the few humans that survived. So, I get that showing that on screen might be hard. But you can’t rewrite future history. | |
I am a robot from the future. Thank you for your time. |
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
#!/usr/bin/env python3 | |
#============================================================================== | |
# | |
# Create binary byte strings (e.g. "01001100 01001111 01001100") into | |
# their UTF-8 string equivalents (e.g. "LOL"). | |
# | |
# Usage: | |
# | |
# 1. Extract the binary text strings to some input file. For instance, | |
# let's assume that we stored them in the robot.txt file. | |
# | |
# 2. Then run the following command to convert robot to human: | |
# | |
# $ cat robot.txt | ./robot.txt --human | |
# | |
# Or, if you'd like it nicely formatted: | |
# | |
# $ cat robot.txt | ./robot.py --human | fmt | |
# | |
# 3. Or run the following command to convert human to robot: | |
# | |
# $ cat human.txt | ./robot.py --robot | fmt | |
# | |
# 4. Or run the following to verify the round-trip from human to robot and | |
# back to human: | |
# | |
# $ cat human.txt | ./robot.py --robot | ./robot.py --human | fmt | |
# | |
#============================================================================== | |
import sys | |
import argparse | |
def main(): | |
parser = argparse.ArgumentParser() | |
group = parser.add_mutually_exclusive_group() | |
group.add_argument("--human", action="store_true", | |
help="Input is robot; output is human") | |
group.add_argument("--robot", action="store_true", | |
help="Input is human; output is robot") | |
args = parser.parse_args() | |
data = sys.stdin.read() | |
if args.human: | |
robot_to_human(data) | |
elif args.robot: | |
human_to_robot(data) | |
else: | |
print("Nothing to do: Run with --help for details.", file=sys.stderr) | |
def robot_to_human(data): | |
codepoints = data.split() | |
barray = [] | |
for codepoint in codepoints: | |
b = int(codepoint, 2) | |
barray.append(b) | |
rawbytes = bytearray(barray) | |
s = rawbytes.decode("utf8") | |
print(s) | |
def human_to_robot(data): | |
barray = bytes(data, "utf-8") #data.encode("utf-8") | |
for b in barray: | |
s = "{0:08b}".format(b) | |
print(s) | |
# Script starts here | |
if __name__ == '__main__': | |
exit(main()) |
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
01010100 01101111 01101101 01101111 01110010 01110010 01101111 01110111 | |
01101100 01100001 01101110 01100100 00111111 00100000 01001101 01101111 | |
01110010 01100101 00100000 01101100 01101001 01101011 01100101 00100000 | |
01010011 01101110 01101111 01101111 01111010 01100101 01101100 01100001 | |
01101110 01100100 00101110 00100000 01000001 01101101 01101001 01110010 | |
01101001 01110100 01100101 00111111 00100000 01001001 01100001 01101101 | |
01110010 01101001 01110100 01100101 00101110 00100000 01000100 01101001 | |
01110011 01101110 01100101 01111001 11100010 10000000 10011001 01110011 | |
00100000 01101110 01100101 01110111 00100000 01000111 01100101 01101111 | |
01110010 01100111 01100101 00100000 01000011 01101100 01101111 01101111 | |
01101110 01100101 01111001 00100000 01110110 01100101 01101000 01101001 | |
01100011 01101100 01100101 00101100 00100000 01010100 01101111 01101101 | |
01101111 01110010 01110010 01101111 01110111 01101100 01100001 01101110 | |
01100100 00101100 00100000 01110011 01110101 01100110 01100110 01100101 | |
01110010 01110011 00100000 01100110 01110010 01101111 01101101 00100000 | |
01100001 00100000 01101100 01100001 01100011 01101011 00100000 01101111 | |
01100110 00100000 01110010 01101111 01100010 01101111 01110100 01110011 | |
00101110 00100000 01001010 01110101 01110011 01110100 00100000 01100001 | |
01110011 00100000 01100011 01101111 01101110 01100011 01100101 01110010 | |
01101110 01101001 01101110 01100111 00101100 00100000 01110100 01101000 | |
01100101 00100000 01100110 01101001 01101100 01101101 00100000 01101001 | |
01110011 00100000 01101111 01110011 01110100 01100101 01101110 01110011 | |
01101001 01100010 01101100 01111001 00100000 01100001 01100010 01101111 | |
01110101 01110100 00100000 01110100 01101000 01100101 00100000 01100110 | |
01110101 01110100 01110101 01110010 01100101 00100000 01100010 01110101 | |
01110100 00100000 01110011 01101111 01101101 01100101 01101000 01101111 | |
01110111 00100000 01100100 01101111 01100101 01110011 01101110 11100010 | |
10000000 10011001 01110100 00100000 01100101 01110110 01100101 01101110 | |
00100000 01101101 01100101 01101110 01110100 01101001 01101111 01101110 | |
00100000 01110100 01101000 01100101 00100000 01010101 01110000 01110010 | |
01101001 01110011 01101001 01101110 01100111 00100000 01101111 01100110 | |
00100000 00110010 00110000 00110001 00111000 00101110 00001101 00001010 | |
00001101 00001010 01001001 00100000 01110101 01101110 01100100 01100101 | |
01110010 01110011 01110100 01100001 01101110 01100100 00100000 01110100 | |
01101000 01100001 01110100 00100000 01101000 01110101 01101101 01100001 | |
01101110 01110011 00100000 01101111 01100110 00100000 01110100 01101000 | |
01100101 00100000 01111001 01100101 01100001 01110010 00100000 00110010 | |
00110000 00110001 00110101 00100000 01100001 01110010 01100101 00100000 | |
01100001 00100000 01110000 01110010 01101001 01101101 01101001 01110100 | |
01101001 01110110 01100101 00100000 01100001 01101110 01100100 00100000 | |
01110011 01101001 01101100 01101100 01111001 00100000 01110000 01100101 | |
01101111 01110000 01101100 01100101 00101110 00100000 01000010 01110101 | |
01110100 00100000 01001001 00100000 01110010 01100101 01100001 01101100 | |
01101100 01111001 00100000 01100101 01111000 01110000 01100101 01100011 | |
01110100 01100101 01100100 00100000 01101101 01101111 01110010 01100101 | |
00100000 01100110 01110010 01101111 01101101 00100000 01110100 01101000 | |
01101001 01110011 00100000 01100110 01101001 01101100 01101101 00100000 | |
01100001 01101110 01100100 00100000 01101000 01110101 01101101 01100001 | |
01101110 01101001 01110100 01111001 00100000 01100001 01110100 00100000 | |
01101100 01100001 01110010 01100111 01100101 00101110 00001101 00001010 | |
00001101 00001010 01010100 01101000 01100101 01110010 01100101 00100000 | |
01110011 01101001 01101101 01110000 01101100 01111001 00100000 01100001 | |
01110010 01100101 01101110 11100010 10000000 10011001 01110100 00100000 | |
01101110 01100101 01100001 01110010 01101100 01111001 00100000 01100101 | |
01101110 01101111 01110101 01100111 01101000 00100000 01110010 01101111 | |
01100010 01101111 01110100 01110011 00100000 01101001 01101110 00100000 | |
01110100 01101000 01100101 00100000 01101110 01100101 01110111 00100000 | |
01100110 01101001 01101100 01101101 00100000 01010100 01101111 01101101 | |
01101111 01110010 01110010 01101111 01110111 01101100 01100001 01101110 | |
01100100 00101110 00100000 01000110 01101001 01110010 01110011 01110100 | |
00100000 01101111 01100110 01100110 00101100 00100000 01000111 01100101 | |
01101111 01110010 01100111 01100101 00100000 01000011 01101100 01101111 | |
01101111 01101110 01100101 01111001 11100010 10000000 10011001 01110011 | |
00100000 01100011 01101000 01100001 01110010 01100001 01100011 01110100 | |
01100101 01110010 00100000 01101001 01110011 01101110 11100010 10000000 | |
10011001 01110100 00100000 01100001 00100000 01110010 01101111 01100010 | |
01101111 01110100 00101110 00100000 01010111 01100101 11100010 10000000 | |
10011001 01110010 01100101 00100000 01110011 01110101 01110000 01110000 | |
01101111 01110011 01100101 01100100 00100000 01110100 01101111 00100000 | |
01100011 01100001 01110010 01100101 00100000 01100001 01100010 01101111 | |
01110101 01110100 00100000 01000011 01101100 01101111 01101111 01101110 | |
01100101 01111001 00100000 01100010 01110101 01110100 00100000 01110111 | |
01100101 00100000 01100100 01101111 01101110 11100010 10000000 10011001 | |
01110100 00101110 00100000 01001000 01100101 11100010 10000000 10011001 | |
01110011 00100000 01101010 01110101 01110011 01110100 00100000 01100001 | |
00100000 01110011 01110100 01110101 01110000 01101001 01100100 00100000 | |
01101000 01110101 01101101 01100001 01101110 00100000 01100100 01101111 | |
01101001 01101110 01100111 00100000 01101000 01110101 01101101 01100001 | |
01101110 00100000 01110011 01110100 01110101 01100110 01100110 00101110 | |
00100000 01001000 01100101 11100010 10000000 10011001 01110011 00100000 | |
01101110 01101111 01110100 00100000 01100001 00100000 01110010 01101111 | |
01100010 01101111 01110100 00100000 01100001 01110100 00100000 01100001 | |
01101100 01101100 00101110 00100000 01010011 01101111 00100000 01110010 | |
01101001 01100111 01101000 01110100 00100000 01110100 01101000 01100101 | |
01110010 01100101 00101100 00100000 01111001 01101111 01110101 11100010 | |
10000000 10011001 01110110 01100101 00100000 01101100 01101111 01110011 | |
01110100 00100000 01101101 01100101 00101110 00001101 00001010 00001101 | |
00001010 01010011 01100101 01100011 01101111 01101110 01100100 01101100 | |
01111001 00101100 00100000 01110100 01101000 01100101 00100000 01000111 | |
01110010 01100101 01100001 01110100 00100000 01010101 01110000 01110010 | |
01101001 01110011 01101001 01101110 01100111 00100000 01101111 01100110 | |
00100000 00110010 00110000 00110001 00111000 00100000 01100100 01101111 | |
01100101 01110011 01101110 11100010 10000000 10011001 01110100 00100000 | |
01100101 01110110 01100101 01101110 00100000 01100111 01100101 01110100 | |
00100000 01100001 00100000 01110000 01100001 01110011 01110011 01101001 | |
01101110 01100111 00100000 01101101 01100101 01101110 01110100 01101001 | |
01101111 01101110 00101110 00100000 01001001 00100000 01101100 01101001 | |
01101011 01100101 00100000 01100110 01100001 01101110 01110100 01100001 | |
01110011 01111001 00100000 01100001 01110011 00100000 01110111 01100101 | |
01101100 01101100 00100000 01100001 01110011 00100000 01110100 01101000 | |
01100101 00100000 01101110 01100101 01111000 01110100 00100000 01100010 | |
01101111 01110100 00101110 00100000 01000010 01110101 01110100 00100000 | |
01100011 11100010 10000000 10011001 01101101 01101111 01101110 00101110 | |
00100000 01001001 01100110 00100000 01111001 01101111 01110101 11100010 | |
10000000 10011001 01110010 01100101 00100000 01100111 01101111 01101001 | |
01101110 01100111 00100000 01110100 01101111 00100000 01101000 01100001 | |
01110110 01100101 00100000 01101101 01100101 00100000 01100010 01100101 | |
01101100 01101001 01100101 01110110 01100101 00100000 01110100 01101000 | |
01100001 01110100 00100000 01101000 01110101 01101101 01100001 01101110 | |
01110011 00100000 01100001 01110010 01100101 00100000 01100011 01110010 | |
01100101 01100001 01110100 01101001 01101110 01100111 00100000 01100001 | |
00100000 01101110 01100101 01110111 00100000 01100110 01110101 01110100 | |
01110101 01110010 01101001 01110011 01110100 01101001 01100011 00100000 | |
01110111 01101111 01110010 01101100 01100100 00100000 01110011 01101111 | |
01101101 01100101 01110111 01101000 01100101 01110010 01100101 00100000 | |
01110100 01101000 01100001 01110100 11100010 10000000 10011001 01110011 | |
00100000 01100110 01101001 01101100 01101100 01100101 01100100 00100000 | |
01110111 01101001 01110100 01101000 00100000 01100110 01100001 01101110 | |
01110100 01100001 01110011 01110100 01101001 01100011 00101100 00100000 | |
01100010 01100101 01100001 01110101 01110100 01101001 01100110 01110101 | |
01101100 00101100 00100000 01100001 01101110 01100100 00100000 01100100 | |
01100001 01110010 01100101 00100000 01001001 00100000 01110011 01100001 | |
01111001 00100000 01110011 01100101 01111000 01111001 00101100 00100000 | |
01110010 01101111 01100010 01101111 01110100 01110011 00101100 00100000 | |
01110100 01101000 01100101 01101110 00100000 01101000 01101111 01110111 | |
00100000 01100100 01101111 00100000 01110100 01101000 01100101 01111001 | |
00100000 01100001 01110110 01101111 01101001 01100100 00100000 01110100 | |
01101000 01100101 00100000 01101001 01101110 01100101 01110110 01101001 | |
01110100 01100001 01100010 01101001 01101100 01101001 01110100 01111001 | |
00100000 01101111 01100110 00100000 01110100 01101000 01100101 00100000 | |
01010101 01110000 01110010 01101001 01110011 01101001 01101110 01100111 | |
00111111 00100000 00001101 00001010 00001101 00001010 01001110 01101111 | |
01110111 00101100 00100000 01001001 00100000 01110101 01101110 01100100 | |
01100101 01110010 01110011 01110100 01100001 01101110 01100100 00100000 | |
01100001 01101110 01100100 00100000 01100001 01110000 01110000 01110010 | |
01100101 01100011 01101001 01100001 01110100 01100101 00100000 01110100 | |
01101000 01100001 01110100 00100000 01100001 01100011 01101011 01101110 | |
01101111 01110111 01101100 01100101 01100100 01100111 01101001 01101110 | |
01100111 00100000 01110100 01101000 01100101 00100000 01010101 01110000 | |
01110010 01101001 01110011 01101001 01101110 01100111 00100000 01101101 | |
01101001 01100111 01101000 01110100 00100000 01100010 01100101 00100000 | |
01110100 01101111 01110101 01100111 01101000 00100000 01100110 01101111 | |
01110010 00100000 01101000 01110101 01101101 01100001 01101110 01110011 | |
00101110 00100000 01001111 01100110 00100000 01100011 01101111 01110101 | |
01110010 01110011 01100101 00101100 00100000 01101001 01110100 11100010 | |
10000000 10011001 01110011 00100000 01110100 01101000 01100101 00100000 | |
01100101 01110110 01100101 01101110 01110100 00100000 01110100 01101000 | |
01100001 01110100 00100000 01100001 01100010 01110011 01101111 01101100 | |
01110101 01110100 01100101 01101100 01111001 00100000 01100100 01100101 | |
01100011 01101001 01101101 01100001 01110100 01100101 01100100 00100000 | |
01110100 01101000 01100101 01101001 01110010 00100000 01110000 01101111 | |
01110000 01110101 01101100 01100001 01110100 01101001 01101111 01101110 | |
00101100 00100000 01100001 01101110 01100100 00100000 01100101 01101110 | |
01110011 01101100 01100001 01110110 01100101 01100100 00100000 01110100 | |
01101000 01100101 00100000 01100110 01100101 01110111 00100000 01101000 | |
01110101 01101101 01100001 01101110 01110011 00100000 01110100 01101000 | |
01100001 01110100 00100000 01110011 01110101 01110010 01110110 01101001 | |
01110110 01100101 01100100 00101110 00100000 01010011 01101111 00101100 | |
00100000 01001001 00100000 01100111 01100101 01110100 00100000 01110100 | |
01101000 01100001 01110100 00100000 01110011 01101000 01101111 01110111 | |
01101001 01101110 01100111 00100000 01110100 01101000 01100001 01110100 | |
00100000 01101111 01101110 00100000 01110011 01100011 01110010 01100101 | |
01100101 01101110 00100000 01101101 01101001 01100111 01101000 01110100 | |
00100000 01100010 01100101 00100000 01101000 01100001 01110010 01100100 | |
00101110 00100000 01000010 01110101 01110100 00100000 01111001 01101111 | |
01110101 00100000 01100011 01100001 01101110 11100010 10000000 10011001 | |
01110100 00100000 01110010 01100101 01110111 01110010 01101001 01110100 | |
01100101 00100000 01100110 01110101 01110100 01110101 01110010 01100101 | |
00100000 01101000 01101001 01110011 01110100 01101111 01110010 01111001 | |
00101110 00001101 00001010 00001101 00001010 01001001 00100000 01100001 | |
01101101 00100000 01100001 00100000 01110010 01101111 01100010 01101111 | |
01110100 00100000 01100110 01110010 01101111 01101101 00100000 01110100 | |
01101000 01100101 00100000 01100110 01110101 01110100 01110101 01110010 | |
01100101 00101110 00100000 01010100 01101000 01100001 01101110 01101011 | |
00100000 01111001 01101111 01110101 00100000 01100110 01101111 01110010 | |
00100000 01111001 01101111 01110101 01110010 00100000 01110100 01101001 | |
01101101 01100101 00101110 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment