summaryrefslogtreecommitdiffstats
path: root/test_20121121/vonneumann.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_20121121/vonneumann.py')
-rwxr-xr-xtest_20121121/vonneumann.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/test_20121121/vonneumann.py b/test_20121121/vonneumann.py
new file mode 100755
index 0000000..3e71e9d
--- /dev/null
+++ b/test_20121121/vonneumann.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+import sys
+
+def pairs(fin):
+ for c in fin.read():
+ bits = bin(ord(c))[2:].zfill(8)
+ while len(bits) >= 2:
+ yield bits[0:2]
+ bits = bits[2:]
+
+def main(fin, fout):
+
+ bits = ""
+
+ for p in pairs(fin):
+ if p == "11" or p == "00":
+ continue
+ bits += p[0]
+ if len(bits) == 8:
+ fout.write(chr(int(bits, 2)))
+ bits = ""
+
+
+if __name__=="__main__":
+ if len(sys.argv) == 1:
+ fin = sys.stdin
+ fout = sys.stdout
+ elif len(sys.argv) == 3:
+ fin = open(sys.argv[1], 'r')
+ fout = open(sys.argv[2], 'w')
+ print "working..."
+ else:
+ print "ERROR: wrong number of arguments (in_file + out_file OR none)"
+
+ main(fin, fout)
+ fin.close()
+ fout.close()