Adler_32_crc (adler_32_crc.adb): (Specification)


--  © Copyright 2000 by John Halleck, All Rights Reserved.
--  Adler-32 CRC.  This is the CRC used by ZLIB compression.
--  This algorithm is described in the the Zlib RFC 1950 May 1996, titled
--  "RFC 1950 ZLIB Compressed Data Format Specification".
--  It is claimed to be an extension and improvement of the Fletcher algorithm
--  used in ITU-T X.224 / ISO 8073.

package body Adler_32_CRC is

   --  These are just implemented direct from the RFC.  They are all so
   --  simple that there is not much point in any commentary other
   --  than pointing people at the RFC.


   procedure Initialize (Given : out State) is
   begin
      Given.s1 := 1;
      Given.s2 := 0;
   end Initialize;


   procedure Process_Data (Given : in out State; Byte : Unsigned_8) is
   begin
      Given.s1 := Given.s1 + Accumulation (Byte);
      Given.s2 := Given.s2 + Given.s1;
   end Process_Data;


   function Final_CRC (Given : in State) return CRC is
   begin
      return CRC (Given.s2) * 2**16  + CRC (Given.s1);
   end Final_CRC;




   function Process_String (Given : String) return CRC is
      Status : State;
   begin
      Initialize (Status);
      for I in Given'Range loop
         Process_Data (Status, Unsigned_8 (Character'Pos (Given (I))));
      end loop;
      return Final_CRC (Status);
   end Process_String;

end Adler_32_CRC;

Go to ...


This page is http://www.cc.utah.edu/~nahaj/ada/crc/adler_32_crc.adb.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 11th, 2000
And the underlying file was last modified on August 5th, 2000