Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/CRC-32/Icon/crc-32.icon
Normal file
33
Task/CRC-32/Icon/crc-32.icon
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
link hexcvt,printf
|
||||
|
||||
procedure main()
|
||||
s := "The quick brown fox jumps over the lazy dog"
|
||||
a := "414FA339"
|
||||
printf("crc(%i)=%s - implementation is %s\n",
|
||||
s,r := crc32(s),if r == a then "correct" else "in error")
|
||||
end
|
||||
|
||||
procedure crc32(s) #: return crc-32 (ISO 3309, ITU-T V.42, Gzip, PNG) of s
|
||||
static crcL,mask
|
||||
initial {
|
||||
crcL := list(256) # crc table
|
||||
p := [0,1,2,4,5,7,8,10,11,12,16,22,23,26] # polynomial terms
|
||||
mask := 2^32-1 # word size mask
|
||||
every (poly := 0) := ior(poly,ishift(1,31-p[1 to *p]))
|
||||
every c := n := 0 to *crcL-1 do { # table
|
||||
every 1 to 8 do
|
||||
c := iand(mask,
|
||||
if iand(c,1) = 1 then
|
||||
ixor(poly,ishift(c,-1))
|
||||
else
|
||||
ishift(c,-1)
|
||||
)
|
||||
crcL[n+1] := c
|
||||
}
|
||||
}
|
||||
|
||||
crc := ixor(0,mask) # invert bits
|
||||
every crc := iand(mask,
|
||||
ixor(crcL[iand(255,ixor(crc,ord(!s)))+1],ishift(crc,-8)))
|
||||
return hexstring(ixor(crc,mask)) # return hexstring
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue