-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspdhTest.py
39 lines (33 loc) · 1.88 KB
/
spdhTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from SPDH.SPDH import SPDH
from SPDH.SPDHErrors import *
spdh = SPDH(debug=True)
strHex = "392E383136303030303031302020202020202020202020202020313131313232313634303137464F30303035303030301C4233333330301C533539323232361C613634331C6530301C68303031303031303031311C713B343736313733393030313031303031303D32303132323031303132333435363738393F1C361E453035311E493634331E4F30303830363433313131313232354143343345433344374442384542323543303030303032453946333432363230303030303038303030303030363031304130333630303030301E5030303031323203"
anotha = "392E383136303030303031302020202020202020202020202020313131313232313634303137464F30303030303030301C68303031303031303031311C46373334393932304D03"
bin = anotha.decode("hex")
lrc = 0
import operator
lrc = reduce(operator.xor, [ord(c) for c in bin])
print 'lrc: %r' % (lrc,)
spdh.setContent(strHex.decode("hex"))
outBin = spdh.getContent()
print outBin.encode('hex')
#spdh.setContent("02392E383838383838383136303030303031302020202020202020202020202020313131313232313634303137464F30303035303030301C4233333330301C533539323232361C6136343338383838381C6530301C68303031303031303031311C713B343736313733393030313031303031303D32303132323031303132333435363738393F1C361E453035311E493634333634333634331E4F30303830363433313131313232354143343345433344374442384542323543303030303032453946333432363230303030303038303030303030363031304130333630303030301E50303030313232036A".decode("hex"))
def write(name,str):
f = open(name,'w')
if ( not f ):
print 'error opening file %s' % (name,)
#for i in xrange(0, len(str) ):
# f.write(str[i])
# f.write('\n')
f.write(str)
f.close()
import difflib
s1 = strHex.upper()
s2 = outBin.encode("hex").upper()
s = difflib.SequenceMatcher(a=s1, b=s2)
print s1 == s2
for block in s.get_matching_blocks():
print "match at a[%d] and b[%d] of length %d" % block
from utils import dump
write('original', dump(strHex.decode("hex")))
write('generated', dump(outBin))