Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,22 @@
func crc32 buf$[] .
for i = 0 to 0xff
rem = i
for j to 8
if bitand rem 1 = 1
rem = bitxor bitshift rem -1 0xedb88320
else
rem = bitshift rem -1
.
.
table[] &= rem
.
crc = 0xffffffff
for c$ in buf$[]
c = strcode c$
crb = bitxor bitand crc 0xff c
crc = bitxor (bitshift crc -8) table[crb + 1]
.
return bitnot crc
.
s$ = "The quick brown fox jumps over the lazy dog"
print crc32 strchars s$

View file

@ -0,0 +1,29 @@
type
TCrc32 = array[0..255] of longword;
function CreateCrcTable(): TCrc32;
begin
for var i: longword := 0 to 255 do
begin
var rem := i;
for var j := 0 to 7 do
if (rem and 1) > 0 then rem := (rem shr 1) xor $edb88320
else rem := rem shr 1;
result[i] := rem
end;
end;
const
Crc32Table = CreateCrcTable;
function Crc32(s: string): longword;
begin
result := $ffffffff;
foreach var c in s do
result := (result shr 8) xor Crc32Table[(result and $ff) xor byte(c)];
result := not result
end;
begin
writeln('crc32 = ', crc32('The quick brown fox jumps over the lazy dog').ToString('X'));
end.

View file

@ -0,0 +1,27 @@
func create_crc32_table {
256.of {|k|
8.times {
if (k & 1) {
k >>= 1
k ^= 0xedb88320
}
else {
k >>= 1
}
}
k
}
}
func crc32(str, crc = 0) {
static crc_table = create_crc32_table()
crc &= 0xffffffff
crc ^= 0xffffffff
str.codes.each {|c|
crc = ((crc >> 8) ^ crc_table[(crc & 0xff) ^ c])
}
return ((crc & 0xffffffff) ^ 0xffffffff)
}
say crc32("The quick brown fox jumps over the lazy dog").as_hex
say crc32("over the lazy dog", crc32("The quick brown fox jumps ")).as_hex