CRC-32: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: simplified the code, used a template for the output section.) |
|||
Line 1,877: | Line 1,877: | ||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
CRC_32: procedure; parse arg !,$; |
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─two bits.*/ |
|||
/* [↓] handle each rightmost byte bit.*/ |
/* [↓] 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=1 for length(! ) /*start number crunching the input data*/ |
|||
?= bitxor(right($,1), substr(!,k,1) ) |
|||
do k=1 for length(!) /*start number crunching the input data*/ |
|||
$= bitxor('0'x || left($, 3), !.?) |
|||
end /*k*/ |
|||
end /*k*/ |
|||
return $ /*return with cyclic redundancy check. */ |
return $ /*return with cyclic redundancy check. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
show: procedure; parse arg Xstring; numeric digits 12; say; say |
show: procedure; parse arg Xstring; numeric digits 12; say; say |
||
checksum=CRC_32(Xstring) |
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 center(' input string [length of' length(Xstring) "bytes] ", 79, '═') |
||
say Xstring |
say Xstring; say /*show the string on its own line*/ |
||
⚫ | |||
say /*↓↓↓↓↓↓↓↓↓↓↓↓ is fifteen blanks*/ |
|||
"dec CRC─32 checksum =" c2d(checksum) /*show the CRC─32 in hex and dec.*/ |
|||
⚫ | |||
return</lang> |
return</lang> |
||
{{out|output|text= when using the internal default input:}} |
|||
'''output''' |
|||
<pre> |
<pre> |
||
══════════════════════ input string [length of 43 bytes] ══════════════════════ |
══════════════════════ input string [length of 43 bytes] ══════════════════════ |