Created
October 3, 2012 04:59
-
-
Save ixtli/3825096 to your computer and use it in GitHub Desktop.
A tool to aid in navigation of The Rubicon.
This file contains hidden or 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/python | |
# coding: utf-8 | |
""" Rubicon Codec v.01 """ | |
import sys; | |
off = u'░'; | |
on = u'█'; | |
def enc(s): | |
outstr = ''; | |
for char in s: | |
o = ord(char); | |
out = ''; | |
for i in range(0, 8): | |
if o & 1: | |
out = on + out; | |
else: | |
out = off + out; | |
o = o >> 1; | |
outstr = outstr + out; | |
return outstr; | |
def dec(s): | |
outstr = ''; | |
count = 0; | |
curchar = 0; | |
for character in s: | |
if count == 8: | |
outstr = outstr + chr(curchar); | |
count = 0; | |
curchar = 0; | |
curchar = curchar << 1; | |
if character == on: | |
curchar = curchar | 1; | |
count = count + 1; | |
return outstr + chr(curchar); | |
if __name__ == '__main__': | |
if len(sys.argv) == 1: | |
r = sys.stdin.read(); | |
print dec(r.decode(sys.getfilesystemencoding())); | |
exit(0); | |
if len(sys.argv) < 3: | |
print "Usage: e/d <string>"; | |
exit(1); | |
if sys.argv[1][0] == 'e': | |
print enc(sys.argv[2]); | |
else: | |
print dec(sys.argv[2].decode(sys.getfilesystemencoding())); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment