Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,34 +1,37 @@
|
|||
/*REXX program computes the CRC-32 (32 bit Cylic Redundancy Check), */
|
||||
/* checksum for a given string [as described in ISO 3309, ITU-T V.42].*/
|
||||
call show "The quick brown fox jumps over the lazy dog"
|
||||
call show 'Generate CRC32 Checksum For Byte Array Example'
|
||||
/*──────────────────────────────────────────────────────────────────────*/
|
||||
call show 'The quick brown fox jumps over the lazy dog' /*1st str*/
|
||||
call show 'Generate CRC32 Checksum For Byte Array Example' /*2nd str*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────SHOW subroutine─────────────────────*/
|
||||
show: procedure; parse arg Xstring; numeric digits 12; say; say
|
||||
checksum=CRC_32(Xstring) /*invoke CRC_32 to create a CRC*/
|
||||
say center(' input string [length of' length(Xstring) "bytes] ", 79, '─')
|
||||
say Xstring /*show the string on its own line*/
|
||||
say
|
||||
checksum=bitxor(checksum,'ffFFffFF'x) /*final convolution for checksum.*/
|
||||
say 'hex CRC-32 checksum =' c2x(checksum) left('',15),
|
||||
"dec CRC-32 checksum =" c2d(checksum) /*show CRC-32 in hex & dec*/
|
||||
return
|
||||
/*──────────────────────────────────CRC_32 subroutine───────────────────*/
|
||||
CRC_32: procedure; parse arg !,$ /*2nd arg is for multi-invokes. */
|
||||
CRC_32: procedure; parse arg !,$ /*2nd arg: repeated─invocations.*/
|
||||
/* [↓] build 8─bit indexed table*/
|
||||
do i=0 for 256; z=d2c(i) /* one byte at a time. */
|
||||
r=right(z, 4, '0'x) /*insure the "R" is 32 bits. */
|
||||
|
||||
do i=0 for 256; z=d2c(i) /*build the 8-bit indexed table.*/
|
||||
r=right(z,4,'0'x) /*insure the R is 32 bits. */
|
||||
do j=0 for 8 /*handle each bit of rightmost 8.*/
|
||||
rb=x2b(c2x(r)) /*convert char ──► hex ──► binary*/
|
||||
_=right(rb,1) /*remember right-most bit for IF.*/
|
||||
r=x2c(b2x(0 || left(rb,31))) /*shift it right (unsigned) 1 bit*/
|
||||
if _\==0 then r=bitxor(r,'edb88320'x) /*bit XOR grunt-work.*/
|
||||
end /*j*/
|
||||
!.z=r
|
||||
end /*i*/
|
||||
do j=0 for 8 /*handle each bit of rightmost 8.*/
|
||||
rb=x2b(c2x(r)) /*convert char ──► hex ──► binary*/
|
||||
_=right(rb,1) /*remember right-most bit for IF.*/
|
||||
r=x2c(b2x(0 || left(rb, 31))) /*shift it right (unsigned) 1 bit*/
|
||||
if _\==0 then r=bitxor(r, 'edb88320'x) /*bit XOR grunt─work.*/
|
||||
end /*j*/
|
||||
!.z=r /*assign to an 8─bit index table.*/
|
||||
end /*i*/
|
||||
|
||||
$=bitxor(word($ '0000000'x,1),'ffFFffFF'x) /*use user's CRC or default.*/
|
||||
do k=1 for length(!) /*start crunching the input data.*/
|
||||
?=bitxor(right($,1),substr(!,k,1)); $=bitxor('0'x||left($,3),!.?)
|
||||
end /*k*/
|
||||
?=bitxor(right($, 1), substr(!, k, 1))
|
||||
$=bitxor('0'x || left($, 3), !.?)
|
||||
end /*k*/
|
||||
return $ /*return with da money to invoker*/
|
||||
/*──────────────────────────────────SHOW subroutine─────────────────────*/
|
||||
show: procedure; parse arg Xstring; numeric digits 12; say; say
|
||||
checksum=CRC_32(Xstring) /*invoke CRC_32 to create a CRC*/
|
||||
checksum=bitxor(checksum,'ffFFffFF'x) /*final convolution for checksum.*/
|
||||
say center(' input string [length of' length(Xstring) "bytes] ", 79, '═')
|
||||
say Xstring /*show the string on its own line*/
|
||||
say /* ↓↓↓↓↓↓↓↓↓↓↓↓ is 15 blanks.*/
|
||||
say 'hex CRC-32 checksum =' c2x(checksum) left('', 15),
|
||||
"dec CRC-32 checksum =" c2d(checksum) /*show CRC-32 in hex & dec.*/
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue