-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement GSM32 #9
Comments
OK, No problem. |
Please provide me with some data and the CRC32 results for this data. I want to verify the calculation results. Above, Thank you. |
def crc32_gsm(data: bytes) -> int:
# Generator polynomial
POLY = 0x04C11DB7
# Initial remainder
crc = 0x00000000
# Process each byte in the data
for byte in data:
crc ^= byte << 24 # Align byte to the high end of the current CRC value
for _ in range(8): # Process each bit in the byte
if crc & 0x80000000: # If the highest bit is set
crc = (crc << 1) ^ POLY
else:
crc <<= 1
crc &= 0xFFFFFFFF # Ensure crc remains within 32-bit bounds
return crc
def rearrange_data(data: bytes) -> bytes:
""" Rearrange data into the format required by the CRC algorithm """
words = []
for i in range(0, len(data), 2):
if i + 1 < len(data):
mso = data[i]
lso = data[i + 1]
else:
mso = data[i]
lso = 0
words.append(lso)
words.append(mso)
return bytes(words)
# Example usage
data = b'Test data for GSM32 CRC'
rearranged_data = rearrange_data(data)
checksum = crc32_gsm(rearranged_data)
print(f'GSM32 CRC checksum: {checksum:08X}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to implement CRC-32 calculation of GSM32 like in this document: link page 140?
The text was updated successfully, but these errors were encountered: