Click here to Skip to main content
15,867,453 members
Articles / Programming Languages / C++
Article

Message Digest Application

Rate me:
Please Sign up or sign in to vote.
3.86/5 (7 votes)
30 Mar 20042 min read 81.6K   979   27   16
A program which generates the various Message Digests using only one Class, also including the different techniques for Base 64 Encoding And Decoding

Introduction

This is class which generates the Message Digest using Various algorithms. It gives support to various algorithms such as MD4 - both 128 bits and 256 bits, MD5, RIPEMD-128, RIPEMD-160, RIPEMD-256, RIPEMD-320, SHA-1, SHA-256, SHA-384, SHA-512, HAVAL SERIES and BASE 64 Encoding and Decoding.

Using the code

This one program can be used for various purpose

  1. You can create the .dll file and can use it
  2. You can create the .exe file and use it as Console Based Utility

For creating the Console based utility

  • Include all the files except the MessageDigest.def file
  • Compile Main.cpp in VC++ 6.0 and then run it

Note:- Please remove all the files from the build expect the Main.cpp while you are creating the Console based utility.

Help is included in the Main.cpp or you can run the .exe file with parameters as (NULL, -?, -help)

For creating the dll file

Include the file MessageDigest.def file and remove the main.cpp, main.h, system.h files. Then compile the "Export.cpp" and build the MessageDigest.dll

//This is the Structure of Class which will do Everything

class Signature_Context
{

private:
  UCHAR ucCur_Size_of_Buffer;
  UCHAR ucCheck;
  UCHAR ucSignature_Type;
  UCHAR ucDigest_Length;

  DOUBLE dProgress,dDelta_Progress;
  Progress ShowProgress;

  union
  {
    FILE * OutFileStream;
    PCHAR  lpChar;
  }OutPut;

  union Finger_Prints
  {
    ULONGLONG ullValues[8];
    ULONG     ulValues[16];
    UINT    uiValues[32];
    UCHAR     ucValues[64];
    UCHAR    ucullValues[8][8];
    UCHAR    uculValues[16][4];
  }Hash;
  
  struct
  {
    UCHAR ucBlockSize;
    union
    {
      PUCHAR     ucValues;
      PSHORT     sValues;
      PULONG     ulValues;
      PULONGLONG ullValues;
    }Block;
  }Message;

  union
  {
    ULONGLONG ullLength;
    UCHAR ucChar_Codes[8];
    struct
    {
      unsigned Bit_4:6;
      unsigned Bit_3:6;
      unsigned Bit_2:6;
      unsigned Bit_1:6;
    }Bits;
  }Code_Convertor;

  // Private Functions
  LONG Initialize(UCHAR,UCHAR);
  VOID Destroy(VOID);

  LONG Expected_FileSize(ULONGLONG &);

  VOID MD4_Transform(VOID);
  VOID MD5_Transform(VOID);
  VOID SHA1_Transform(VOID);
  VOID SHA256_Transform(VOID);
  VOID SHA_384_512_Transform(VOID);
  VOID RIPEMD_128_256_Transform(VOID);
  VOID RIPEMD_160_320_Transform(VOID);
  VOID HAVAL_Transform(SHORT);

  VOID HAVAL_Tailor(VOID);

  VOID Signature_Transform(UCHAR);

  VOID Signature_Final(UCHAR);

  VOID BASE64_Encode_Update(PCHAR,ULONG &);
  VOID Base64_Encode_Final(VOID);
  VOID BASE64_Decode(PCHAR);

public:
  Signature_Context(UCHAR = MD_5, UCHAR = 0); // Parameterized Constructor
  ~Signature_Context(VOID); // Destructor

  LONG Create_Signature(PCHAR,ULONG,PCHAR,SHORT,
         UCHAR = 3,UCHAR = 0,SHORT = 0,  
             LONG = NULL,LONG = NULL);

  VOID Signature_Update(PCHAR,ULONG &);
};

Points of Interest

  1. Special Logic has been developed for Base 64 encoding and decoding
  2. A some what different implementation for calculating the Message Digest
  3. In all 16 Message Digest algorithms are supported
  4. Given support to MD4 256 bit algorithm, which require 2 copies of code running parallelly
  5. Implementation of AppendChunk method which will take in some extra input while processing (Not in Console Based)
  6. The program gives back the progress of transformation (Not in Console Based)

Special Logic used for BASE 64 Encoding and Decoding.

I had used the concept of bit datatype. Check out the cool code and also the speed which i had reduced for calculation of BASE 64 Encoding and Decoding

I wonder "Why people use the shifting logic when they had Bit Data type Which gradually increases the Execution time"

An efficient use of CALLBACK from C++

Lastly, I would like to thank Respected Sir, Shyam R. Soni for his priceless guidance through out this project. It would be never be possible without him. I would also like to thanks Dominik Reichl for his very valuable tips and guidance

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralUsefull Pin
Cem Kalyoncu16-Aug-06 23:20
Cem Kalyoncu16-Aug-06 23:20 
GeneralCompiler Errors Pin
ivax3-Oct-05 23:13
ivax3-Oct-05 23:13 
GeneralRe: Compiler Errors Pin
Cem Kalyoncu16-Aug-06 23:13
Cem Kalyoncu16-Aug-06 23:13 
GeneralMD4 -> little question... Pin
dghhngd4522-Sep-04 0:58
dghhngd4522-Sep-04 0:58 
GeneralRe: MD4 -> little question... Pin
Shinde Vikram23-Sep-04 17:31
Shinde Vikram23-Sep-04 17:31 
GeneralRe: MD4 -> little question... Pin
dghhngd4523-Sep-04 22:15
dghhngd4523-Sep-04 22:15 
GeneralRe: MD4 -> little question... Pin
Anonymous24-Sep-04 4:45
Anonymous24-Sep-04 4:45 
GeneralRe: MD4 -> little question... Pin
Shinde Vikram24-Sep-04 18:49
Shinde Vikram24-Sep-04 18:49 
GeneralRe: MD4 -> little question... Pin
Anonymous25-Sep-04 10:12
Anonymous25-Sep-04 10:12 
Generalplz give me suggestions Pin
Shinde Vikram8-Apr-04 7:22
Shinde Vikram8-Apr-04 7:22 
GeneralRe: plz give me suggestions Pin
Philippe Lhoste8-Apr-04 10:23
Philippe Lhoste8-Apr-04 10:23 
Well, I haven't seen the code, but it seems useful for me.

Perhaps people like me wonder what are the differences between the various methods. It may be a bit out of the scope of the article, but a short introduction would save a long search on the Net...

I know a bit MD5, have heard of SHA-1 and know Base64 is used with Mime, but I don't know the pros and cons of the other methods.

Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/

GeneralRe: plz give me suggestions Pin
Shinde Vikram10-Apr-04 21:37
Shinde Vikram10-Apr-04 21:37 
GeneralRe: plz give me suggestions Pin
MilanTomic7811-May-04 22:59
MilanTomic7811-May-04 22:59 
GeneralRe: plz give me suggestions Pin
Shinde Vikram13-May-04 7:18
Shinde Vikram13-May-04 7:18 
GeneralRe: plz give me suggestions Pin
MilanTomic7811-May-04 23:04
MilanTomic7811-May-04 23:04 
GeneralRe: plz give me suggestions Pin
Shinde Vikram13-May-04 6:52
Shinde Vikram13-May-04 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.