#include <stdio.h> 

/*
Output should be:
da853b0d3f88d99b30283a69e6ded6bb
4e8ddff3650292ab5a4108c3aa47940b
da33def2a42df13975352846c30338cd
*/

void print_hash(unsigned char hash[]) 
{  
   int i; 
   for (i=0; i < 16; ++i) 
      printf("%02x",hash[i]); 
   printf("\n"); 
}  

int main() 
{  
   int i; 
   char text1[]={"abc"},
        text2[]={"abcdefghijklmnopqrstuvwxyz"},
        text3_1[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"},
        text3_2[]={"fghijklmnopqrstuvwxyz0123456789"}, 
        hash[16]; 
   MD2_CTX ctx; 
   
   // First hash 
   md2_init(&ctx); 
   md2_update(&ctx,text1,strlen(text1)); 
   md2_final(&ctx,hash); 
   print_hash(hash); 
   
   // Second hash (note that the MD2 object can be re-used) 
   md2_init(&ctx); 
   md2_update(&ctx,text2,strlen(text2)); 
   md2_final(&ctx,hash); 
   print_hash(hash); 
   
   // Third hash (note that the data is added in two chunks 
   md2_init(&ctx); 
   md2_update(&ctx,text3_1,strlen(text3_1)); 
   md2_update(&ctx,text3_2,strlen(text3_2)); 
   md2_final(&ctx,hash); 
   print_hash(hash); 
   
   getchar(); 
   return 0; 
}

