CRC32: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE: _CRC32}}
{{DISPLAYTITLE: _CRC32}}
The '''_CRC32''' function returns the [[Wikipedia:Cyclic_redundancy_check|Crc-32]] checksum of any arbitrary string.
The '''_CRC32''' function returns the [[Wikipedia:Cyclic redundancy check|Crc-32]] checksum of any arbitrary string.




Line 8: Line 8:


{{PageParameters}}
{{PageParameters}}
* {{Parameter|chksum~&}} is the [[_UNSIGNED]] [[LONG]] checksum returned (zero (0), if the given {{Parameter|dataString$}} was empty).
* {{Parameter|chksum~&}} is the [[_UNSIGNED]] [[LONG]] checksum returned (''zero(0)'', if the given {{Parameter|dataString$}} was empty).
* {{Parameter|dataString$}} is any literal or variable [[STRING]] to build the checksum from.
* {{Parameter|dataString$}} is any literal or variable [[STRING]] to build the checksum from.


Line 62: Line 62:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=2681 Featured in our "Keyword of the Day" series]
* [[_DEFLATE$]], [[_INFLATE$]]
* [[_DEFLATE$]], [[_INFLATE$]]
* [[_ADLER32]], [[_MD5$]]
* [[_ADLER32]], [[_MD5$]]

Latest revision as of 00:33, 18 November 2024

The _CRC32 function returns the Crc-32 checksum of any arbitrary string.


Syntax

chksum~& = _CRC32(dataString$)


Parameters

  • chksum~& is the _UNSIGNED LONG checksum returned (zero(0), if the given dataString$ was empty).
  • dataString$ is any literal or variable STRING to build the checksum from.


Description

  • The Crc-32 checksum algorithm is slower than _ADLER32 but is usually more resistant against random collisions, it has the following known properties:
    • All single bit flips will be detected.
    • All double bit flips will be detected.
    • All 32-bit bursts of errors will be detected.
    • Has a hamming distance of 4 for data lengths up to 91706 bytes.
    • Has a hamming distance of 5 for data lengths up to 2974 bytes.
  • For more informations have a closer look at Chapters 5-7 here.


Availability


Examples

Example
Showing how the Crc-32 checksum can detect differences in two strings.
'this is the correct text
t$ = "QB64 Phoenix Edition"
PRINT "Correct Text: "; t$
PRINT "  Crc-32 Sum: "; RIGHT$("00000000" + HEX$(_CRC32(t$)), 8)
PRINT
'this text differs in just 1 bit from the above, by changing 4 to 5
'ASC("4") = 52 = &B00110100
'ASC("5") = 53 = &B00110101
t$ = "QB65 Phoenix Edition"
PRINT "Mangled Text: "; t$
PRINT "  Crc-32 Sum: "; RIGHT$("00000000" + HEX$(_CRC32(t$)), 8)
END
Example by RhoSigma
Correct Text: QB64 Phoenix Edition
  Crc-32 Sum: 691EE005

Mangled Text: QB65 Phoenix Edition
  Crc-32 Sum: EEB82B46


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link