How to resolve the algorithm MD4 step by step in the Ada programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm MD4 step by step in the Ada programming language

Table of Contents

Problem Statement

Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifies the MD4 algorithm. RFC 6150 declares that MD4 is obsolete.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm MD4 step by step in the Ada programming language

Source code in the ada programming language

with Ada.Text_IO;

with CryptAda.Digests.Message_Digests.MD4;
with CryptAda.Digests.Hashes;
with CryptAda.Pragmatics;
with CryptAda.Utils.Format;

procedure RC_MD4 is
   use CryptAda.Digests.Message_Digests;
   use CryptAda.Digests;
   use CryptAda.Pragmatics;

   function To_Byte_Array (Item : String) return Byte_Array is
      Result : Byte_Array (Item'Range);
   begin
      for I in Result'Range loop
         Result (I) := Byte (Character'Pos (Item (I)));
      end loop;
      return Result;
   end To_Byte_Array;

   Text    : constant String                := "Rosetta Code";
   Bytes   : constant Byte_Array            := To_Byte_Array (Text);
   Handle  : constant Message_Digest_Handle := MD4.Get_Message_Digest_Handle;
   Pointer : constant Message_Digest_Ptr    := Get_Message_Digest_Ptr (Handle);
   Hash    : Hashes.Hash;
begin
   Digest_Start  (Pointer);
   Digest_Update (Pointer, Bytes);
   Digest_End    (Pointer, Hash);

   Ada.Text_IO.Put_Line
     ("""" & Text & """: " & CryptAda.Utils.Format.To_Hex_String (Hashes.Get_Bytes (Hash)));
end RC_MD4;


  

You may also check:How to resolve the algorithm Variables step by step in the Joy programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Brainf*** programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the Jsish programming language
You may also check:How to resolve the algorithm Price fraction step by step in the Oforth programming language
You may also check:How to resolve the algorithm Amicable pairs step by step in the Ada programming language