solve for data, given a target crc
Project description
crcsolver
solve for data, given a target crc
Use
We'll target python's built-in crc32:
>>> import binascii
>>> binascii.crc32(b'penguin')
3854672160
Now suppose we lost the 'e', so we have b'p_nguin' and need to solve for it. With bits indexed left-to-right across the input, the missing character is at bits [8,9,10,11,12,13,14,15].
>>> from crcsolver import solve
>>> solve(b'p_nguin', [8,9,10,11,12,13,14,15], 3854672160, binascii.crc32)
b'penguin'
The solve takes what data is known, a list of bits that are unknown, a target crc result, and a crc calculating function which it will call while finding a solution.
Any n-bit CRC is solvable with at least n bits of freedom, but might not have a solution with less. Here's a failed attempt to toggle the first 8 bits of b'XXXXXXXX' to the same CRC has b'penguin'. When there is no solution, solve() returns None:
>>> solve(b'XXXXXXXX', range(8), 3854672161, binascii.crc32)
>>>
With 32 bits of freedom, a solution exists:
>>> solve(b'XXXXXXXX', range(32), 3854672161, binascii.crc32)
b'B\xb0\xfd\x95XXXX'
Note the solver doesn't know what data looks nice or not. It will find the first solution, which may not be human readable. Verify:
>>> binascii.crc32(b'B\xb0\xfd\x95XXXX')
3854672161
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for crcsolver-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29fd07fdefedd99cb60dde6b10dd256a8f42f32d0894449176bc5dfd25d8e314 |
|
MD5 | 8bf4dc94e186a41148127b4989547865 |
|
BLAKE2b-256 | a6caa6a48b511b891fbafa468cc3b591fe3fb851685c13141e33c7aa980b4c91 |