Skip to content

Instantly share code, notes, and snippets.

@ichimarusakura
Last active May 12, 2020 08:14
Show Gist options
  • Select an option

  • Save ichimarusakura/f31142ab92cceef8bbfd69fb176c4d27 to your computer and use it in GitHub Desktop.

Select an option

Save ichimarusakura/f31142ab92cceef8bbfd69fb176c4d27 to your computer and use it in GitHub Desktop.
BIN File's Checksum Algorithm
import os,codecs
hashcode = []
rg = range(0, 10000)
dict = {'BNR_BIG_ID1000':'ADA613C6','BNR_BIG_ID2000':'6E6CA712','BNR_BIG_ID3000':'ECE07F8A','BNR_BIG_ID4000':'0F89FD78','BNR_BIG_ID5000':'8D0525E0','BNR_BIG_ID5100':'2DF7BBEF','BNR_BIG_ID5300':'FFEE7A33','BNR_BIG_ID6000':'4ECF9134','BNR_BIG_ID6100':'EE3D0F3B','BNR_BIG_ID6200':'9CD650E8','BNR_BIG_ID8800':'0BFD203A','BNR_BIG_ID9001':'9DF788D5','BNR_BIG_ID7000':'CC4349AC','BNR_ID1000':'4A89EF27','BNR_ID2000':'89435BF3','BNR_ID3000':'0BCF836B','BNR_ID4000':'E8A60199','BNR_ID5000':'6A2AD901','BNR_ID5100':'CAD8470E','BNR_ID5300':'18C186D2','BNR_ID6000':'A9E06DD5','BNR_ID6100':'0912F3DA','BNR_ID6200':'7BF9AC09','BNR_ID8800':'ECD2DCDB','BNR_ID9001':'7AD87434','BNR_ID7000':'2B6CB54D','IDX_ID1000':'1082B3A6','IDX_ID2000':'D3480772','IDX_ID3000':'51C4DFEA','IDX_ID4000':'B2AD5D18','IDX_ID5000':'30218580','IDX_ID5100':'90D31B8F','IDX_ID5300':'42CADA53','IDX_ID6000':'F3EB3154','IDX_ID6100':'5319AF5B','IDX_ID6200':'21F2F088','IDX_ID8800':'B6D9805A','IDX_ID9001':'20D328B5','IDX_ID7000':'7167E9CD','IDX_MINI_ID1000':'02331C7E','IDX_MINI_ID2000':'C1F9A8AA','IDX_MINI_ID3000':'43757032','IDX_MINI_ID4000':'A01CF2C0','IDX_MINI_ID5000':'22902A58','IDX_MINI_ID5100':'8262B457','IDX_MINI_ID5300':'507B758B','IDX_MINI_ID6000':'E15A9E8C','IDX_MINI_ID6100':'41A80083','IDX_MINI_ID6200':'33435F50','IDX_MINI_ID8800':'A4682F82','IDX_MINI_ID9001':'3262876D','IDX_MINI_ID7000':'63D64634'}
for key,value in sorted(dict.items()):
str_h = value
a = bin(int('0x' + str_h[0:1], 16)).replace('0b', '').zfill(4)
b = bin(int('0x' + str_h[1:2], 16)).replace('0b', '').zfill(4)
c = bin(int('0x' + str_h[2:3], 16)).replace('0b', '').zfill(4)
d = bin(int('0x' + str_h[3:4], 16)).replace('0b', '').zfill(4)
e = bin(int('0x' + str_h[4:5], 16)).replace('0b', '').zfill(4)
f = bin(int('0x' + str_h[5:6], 16)).replace('0b', '').zfill(4)
g = bin(int('0x' + str_h[6:7], 16)).replace('0b', '').zfill(4)
h = bin(int('0x' + str_h[7:8], 16)).replace('0b', '').zfill(4)
all = a + b + c + d + e + f + g + h
def bnot(s):
s >= 0
if s == 0:
return 1
elif s < 0:
return 'warning'
else:
return 0
def n2n(s, i):
if i == 0:
x = s
return x
elif i == 1:
x = str(bnot(int(s[0:1]))) + s[1:2] + s[2:3] + s[3:4]
return x
elif i == 2:
x = s[0:1] + str(bnot(int(s[1:2]))) + s[2:3] + s[3:4]
return x
elif i == 3:
x = str(bnot(int(s[0:1]))) + str(bnot(int(s[1:2]))) + s[2:3] + s[3:4]
return x
elif i == 4:
x = s[0:1] + s[1:2] + str(bnot(int(s[2:3]))) + s[3:4]
return x
elif i == 5:
x = str(bnot(int(s[0:1]))) + s[1:2] + str(bnot(int(s[2:3]))) + s[3:4]
return x
elif i == 6:
x = s[0:1] + str(bnot(int(s[1:2]))) + str(bnot(int(s[2:3]))) + s[3:4]
return x
elif i == 7:
x = str(bnot(int(s[0:1]))) + str(bnot(int(s[1:2]))) + str(bnot(int(s[2:3]))) + s[3:4]
return x
elif i == 8:
x = s[0:1] + s[1:2] + s[2:3] + str(bnot(int(s[3:4])))
return x
elif i == 9:
x = str(bnot(int(s[0:1]))) + s[1:2] + s[2:3] + str(bnot(int(s[3:4])))
return x
st0 = all[0:2]
st1 = all[2:6]
st2 = all[6:8]
st3 = all[8:12]
st4 = all[12:14]
st5 = all[14:18]
st6 = all[18:20]
st7 = all[20:24]
st8 = all[24:26]
st9 = all[26:30]
sta = all[30:32]
for num in rg:
outname = key + str(num).zfill(4)
outcode = st0 + st1 + st2 + n2n(st3, (num//1000)%10) + st4 + n2n(st5, (num//100)%10) + st6 + n2n(st7, (num//10)%10) + st8 + n2n(st9, (num//1)%10) + sta
intoc = (int(outcode, 2))
hashcode.append(outname + ',' + str(intoc).zfill(8))
file_object = codecs.open('crc.txt', 'wb','utf16')
file_object.writelines('%s%s' % (x, os.linesep) for x in hashcode)
file_object.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment