]> git.somenet.org - pub/jan/netsec2.git/blob - exercise1/task2/parse_stream_data.py
change workdir structure
[pub/jan/netsec2.git] / exercise1 / task2 / parse_stream_data.py
1 #!/usr/bin/python
2
3 from pprint import pprint
4
5 fullstr = ""
6
7 #with open('intermediate_stream_data.txt', 'r') as infile:
8 with open('stream_data.txt', 'r') as infile:
9     for line in infile:
10         if len(line) > 0:
11             i = int(line)
12             bin = "{0:06b}".format(i)
13             fullstr += bin
14
15 bytelist = [ fullstr[i:i+8] for i in range(0, len(fullstr), 8) ]
16
17 solution = ""
18
19 for bchar in bytelist:
20     solution += chr(int(bchar, 2))
21
22 print ("%s" % solution)
23 print ("len: %d" % len(solution))