]> git.somenet.org - pub/jan/netsec2.git/blob - exercise1/task1/somedecode.py
finish exercise3
[pub/jan/netsec2.git] / exercise1 / task1 / somedecode.py
1 #!/usr/bin/env python
2
3 import csv
4 import binascii
5
6 def somedecode(filename):
7   with open(filename, 'rb') as csvfile:
8     spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
9     header = last = None
10     ln = 0
11     v = ""
12     
13     for row in spamreader:
14       if header is None:
15         header = row
16         continue
17       if last is None:
18         last = row
19         continue
20       
21       va = str(int((float(row[1])-float(last[1])-0.05)*10))
22       if va not in ["0","1"]:
23         va = "1"
24
25       v = v+va
26       ln += 1
27       if ln == 8:
28         print binascii.unhexlify('%x' % int(v, 2)),
29         v = ""
30         ln = 0
31       last = row
32
33 if __name__ == "__main__":
34         somedecode("filtered.dehexed.csv")
35