CRC-32: Difference between revisions

152 bytes removed ,  4 years ago
m
→‎{{header|REXX}}: simplified the code, used a template for the output section.
m (→‎{{header|REXX}}: simplified the code, used a template for the output section.)
Line 1,877:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
CRC_32: procedure; parse arg !,$; c= 'edb88320'x /*2nd arg used for repeated invocations*/
f= 'ffFFffFF'x /* [↓] build an 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 thirty-twothirty─two bits.*/
/* [↓] handle each rightmost byte bit.*/
do j=0 for 8; rb= x2b(c2x(r)) /*handle each bit of rightmost 8 bits. */
r= x2c( b2x(0 || left(rb, 31) ) ) /*shift it right (an unsigned) 1 bit.*/
if right(rb,1) then r= bitxor(r, c) /*this is a bin bit for XOR grunt─work.*/
end /*j*/
!.z= r /*assign to an eight─bit index table. */
end /*i*/
$=bitxor( word($ '0000000'x, 1), f) /*utilize the user's CRC or a default. */
 
$ do k=bitxor(word1 for length($! '0000000'x, 1), f) /*utilize the user's CRC or a default. /*start number crunching the input data*/
?= bitxor(right($,1), substr(!,k,1) )
do k=1 for length(!) /*start number crunching the input data*/
?$= bitxor(right'0'x || left($,1 3), substr( !,k,1).?)
end $=bitxor('0'x || left($, 3), !.?)/*k*/
end /*k*/
return $ /*return with cyclic redundancy check. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: procedure; parse arg Xstring; numeric digits 12; say; say
checksum= bitxor(CRC_32(Xstring), 'ffFFffFF'x) /*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; say /*show the string on its own line*/
say "dechex CRC-32CRC─32 checksum =" c2dc2x(checksum) /*show the CRC-32left('', in hex and dec.*/15),
say /*↓↓↓↓↓↓↓↓↓↓↓↓ is fifteen blanks*/
say "hexdec CRC-32CRC─32 checksum =" c2xc2d(checksum) /*show the left('',CRC─32 15),in hex and dec.*/
"dec CRC-32 checksum =" c2d(checksum) /*show the CRC-32 in hex and dec.*/
return</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
'''output'''
<pre>
══════════════════════ input string [length of 43 bytes] ══════════════════════