PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: ToUpperCase()[Next]: UrlDecode()
\ -> Rexx -> Inbuilt PPWIZARD Functions -> UpdateCrc32()


This is an inbuilt function function provided by PPWIZARD.

This function along with 2 other "helper" functions can be used to create a CRC-32 checksum for one or more blocks of memory. The routine being pure rexx is not real fast (about 29,000-100,000 bytes/sec on an Athlon 700) but would be fine for smallish blocks of memory.

In case you don't know what a CRC is it can be used for two main reasons, firstly to create a random hash of a string and secondly it can be stored for comparison with another string's CRC at some future time. Two different strings are extremely unlikely to have the same CRC value. A CRC allows you to store the CRC and not the (possibly huge) original string.

The parameters are as follows:

  1. CRC Value on Input
    This allows you to progressively build up the CRC from a number of memory blocks. The format is exactly 4 bytes binary, for example '00112233'x. Typically (and if you wish to generated the same CRC as ZIP uses) the value for the first block is the return code from "Crc32PrePostConditioning()" called without parameters.

  2. Block Of Memory
    This is the block of memory for which the CRC is being updated. After the last block of memory you would typically pass the CRC to "Crc32PrePostConditioning()" as the one and only parameter (again this is required to generate the same CRC as ZIP would).

The return code from each call to this routine is the updated return code.

The "Crc32InDisplayableForm()" routine when passed the binary form of the CRC will return a displayable (hexadecimal) form.


Assuming you have two variables "part1" and "part2" which contain the string for which you wish to calculate a CRC then the following code will calculate and then display one that would match that calculated by the zip utilities for the same content:

;--- Calculate the CRC ------------------------
Crc32 = Crc32PrePostConditioning();        ;;Initialize CRC value
Crc32 = UpdateCrc32(Crc32, Part1);         ;;Update CRC for this block
Crc32 = UpdateCrc32(Crc32, Part2);         ;;As above
Crc32 = Crc32PrePostConditioning(Crc32);   ;;Adjust CRC

;--- Display the CRC --------------------------
say 'CRC32 = ' || Crc32InDisplayableForm(Crc32);   ;;Convert CRC to 8 byte displayable form

email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: ToUpperCase()[Next]: UrlDecode()

My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am