diff --git a/src/durandal/crc.rs b/src/durandal/crc.rs new file mode 100644 index 0000000..e266d20 --- /dev/null +++ b/src/durandal/crc.rs @@ -0,0 +1,18 @@ +fn crc_init() -> [u32; 256] +{ + let mut t = [0; 256]; + for n in 0..256 + { + t[n] = (0..8).fold(n as u32, |a, _| + {if a & 1 == 1 {0xedb88320 ^ a >> 1} else {a >> 1}}); + } + t +} + +pub fn crc32(b: &[u8], s: u32) -> u32 +{ + let t = crc_init(); + !b.iter().fold(s, |a, &o| {a >> 8 ^ t[(a & 0xff ^ o as u32) as usize]}) +} + +// EOF diff --git a/src/durandal/mod.rs b/src/durandal/mod.rs index c0ccaf3..aa9ca97 100644 --- a/src/durandal/mod.rs +++ b/src/durandal/mod.rs @@ -2,9 +2,10 @@ #[allow(dead_code)] pub mod bin; -pub mod machead; -pub mod text; +pub mod crc; pub mod image; +pub mod machead; pub mod pict; +pub mod text; // EOF