I used crc32 to calculate checksums from strings a long time ago, but I cannot remember how I did it.
echo -n "LongString" | crc32 # no output
I found a solution [1] to calculate them with Python, but is there not a direct way to calculate that from a string?
# signed
python -c 'import binascii; print binascii.crc32("LongString")'
python -c 'import zlib; print zlib.crc32("LongString")'
# unsigned
python -c 'import binascii; print binascii.crc32("LongString") % (1<<32)'
python -c 'import zlib; print zlib.crc32("LongString") % (1<<32)'
[1] How to calculate CRC32 with Python to match online results?
The crc32() function calculates a 32-bit CRC (cyclic redundancy checksum) for a string. This function can be used to validate data integrity. Tip: To ensure that you get the correct string representation from the crc32() function, you'll need to use the %u formatter of the printf() or sprintf() function.
cksfv app from cksfv package generates CRC32 checksum as well. could you give a usage example? cksfv -c "file" prints the CRC32 to stdout. If you want to suppress the header, a cksfv -c "file" 2>/dev/null | grep -v ^\; gives the filename + CRC32 and no warning for a directory.
The most common variant of the CRC32 checksum, sometimes called CRC-32b, is based on the following generator polynomial: g(x) = x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1. This code processes one bit at a time.
This command provides a feature where-in the user can type just 'cksum' or 'cksum-' and write on stdin and then press Ctrl+D couple of times. This way cksum gives the checksum of the data entered at the input. In the example above, we actually calculated the checksum of the string “Lets check the checksum”.
Or just use the process substitution:
crc32 <(echo "LongString")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With