Created
April 27, 2020 11:32
-
-
Save pintoXD/a90e398bba5a1b6c121de4e1265d9a29 to your computer and use it in GitHub Desktop.
CRC16/ARC Python implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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