ADLER32: Difference between revisions

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




Line 8: Line 8:


{{PageParameters}}
{{PageParameters}}
* {{Parameter|chksum~&}} is the [[_UNSIGNED]][[LONG]] checksum returned (zero, if the given {{Parameter|dataString$}} was empty).
* {{Parameter|chksum~&}} is the [[_UNSIGNED]] [[LONG]] checksum returned (one (1), 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.




{{PageDescription}}
{{PageDescription}}
* The '''Adler-32''' checksum uses a relative simple but very fast algorithm, it has the following known properties:
** All single bit flips will be detected.
** All double bit flips will be detected.
** Burst errors up to seven bits are always detected.
* For more informations have a closer look at [https://www.intel.com/content/www/us/en/content-details/709921/intel-quickassist-technology-intel-qat-using-adler-32-checksum-and-crc32-hash-to-ensure-data-compression-integrity.html Chapters 5-7 here].
{{PageAvailability}}
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no -->
<gallery widths="48px" heights="48px" mode="nolines">
File:Qb64.png|'''none'''
File:Qbpe.png|'''v3.12.0'''
File:Apix.png
File:Win.png|'''yes'''
File:Lnx.png|'''yes'''
File:Osx.png|'''yes'''
</gallery>
<!-- Additional availability notes go below the gallery -->




{{PageExamples}}
{{PageExamples}}
;Example: Calculating the area of a circle using a [[SINGLE]] variable in this case.
;Example: Showing how the Adler-32 checksum can detect differences in two strings.
{{CodeStart}}radius = 5
{{CodeStart}}
circlearea = {{Cl|_PI}}(radius ^ 2)
{{Text|<nowiki>'this is the correct text</nowiki>|#919191}}
PRINT circlearea
t$ = {{Text|<nowiki>"QB64 Phoenix Edition"</nowiki>|#FFB100}}
{{Cl|PRINT}} {{Text|<nowiki>"Correct Text: "</nowiki>|#FFB100}}; t$
{{Cl|PRINT}} {{Text|<nowiki>"Adler-32 Sum: "</nowiki>|#FFB100}}; {{Cl|RIGHT$}}({{Text|<nowiki>"00000000"</nowiki>|#FFB100}} + {{Cl|HEX$}}({{Cl|_ADLER32}}(t$)), {{Text|8|#F580B1}})
{{Cl|PRINT}}
{{Text|<nowiki>'this text differs in just 1 bit from the above, by changing 4 to 5</nowiki>|#919191}}
{{Text|<nowiki>'ASC("4") = 52 = &B00110100</nowiki>|#919191}}
{{Text|<nowiki>'ASC("5") = 53 = &B00110101</nowiki>|#919191}}
t$ = {{Text|<nowiki>"QB65 Phoenix Edition"</nowiki>|#FFB100}}
{{Cl|PRINT}} {{Text|<nowiki>"Mangled Text: "</nowiki>|#FFB100}}; t$
{{Cl|PRINT}} {{Text|<nowiki>"Adler-32 Sum: "</nowiki>|#FFB100}}; {{Cl|RIGHT$}}({{Text|<nowiki>"00000000"</nowiki>|#FFB100}} + {{Cl|HEX$}}({{Cl|_ADLER32}}(t$)), {{Text|8|#F580B1}})
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}} 78.53982
{{Small|Example by RhoSigma}}
{{OutputStart}}
Correct Text: QB64 Phoenix Edition
Adler-32 Sum: 41F806E5
 
Mangled Text: QB65 Phoenix Edition
Adler-32 Sum: 420906E6
{{OutputEnd}}
{{OutputEnd}}




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

Latest revision as of 22:39, 25 May 2024

The _ADLER32 function returns the Adler-32 checksum of any arbitrary string.


Syntax

chksum~& = _ADLER32(dataString$)


Parameters

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


Description

  • The Adler-32 checksum uses a relative simple but very fast algorithm, it has the following known properties:
    • All single bit flips will be detected.
    • All double bit flips will be detected.
    • Burst errors up to seven bits are always detected.
  • For more informations have a closer look at Chapters 5-7 here.


Availability


Examples

Example
Showing how the Adler-32 checksum can detect differences in two strings.
'this is the correct text
t$ = "QB64 Phoenix Edition"
PRINT "Correct Text: "; t$
PRINT "Adler-32 Sum: "; RIGHT$("00000000" + HEX$(_ADLER32(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 "Adler-32 Sum: "; RIGHT$("00000000" + HEX$(_ADLER32(t$)), 8)
END
Example by RhoSigma
Correct Text: QB64 Phoenix Edition
Adler-32 Sum: 41F806E5

Mangled Text: QB65 Phoenix Edition
Adler-32 Sum: 420906E6


See also



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