Skip to content

Instantly share code, notes, and snippets.

@pintoXD
Created April 27, 2020 11:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pintoXD/a90e398bba5a1b6c121de4e1265d9a29 to your computer and use it in GitHub Desktop.
Save pintoXD/a90e398bba5a1b6c121de4e1265d9a29 to your computer and use it in GitHub Desktop.
CRC16/ARC Python implementation
def crc16(data, offset, length):
if data is None or offset < 0 or offset > len(data) - 1 and offset+length > len(data):
return 0
crc = 0x0000
for i in (range(0, length)):
# crc = crc << 8
crc ^= data[i]
# print(hex(data[i]))
print(bin(crc))
for j in range(0, 8):
if (crc & 0x0001) > 0:
crc = (crc >> 1) ^ 0xA001
else:
crc = crc >> 1
print(bin(crc))
# print(bin(0xFFFF))
return crc
if __name__ == "__main__":
print(hex(crc16("otto".encode(), 0 ,4 )))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment