C++ Saved Program: quiescent-af

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include <conio.h>
 
typedef union uwb {
    unsigned w;
    unsigned char b[4];
} MD5union;
 
typedef unsigned DigestArray[4];
 
unsigned func0( unsigned abcd[] ){
    return ( abcd[1] & abcd[2]) | (~abcd[1] & abcd[3]);}
 
unsigned func1( unsigned abcd[] ){
    return ( abcd[3] & abcd[1]) | (~abcd[3] & abcd[2]);}
unsigned func2( unsigned abcd[] ){
    return  abcd[1] ^ abcd[2] ^ abcd[3];}
unsigned func3( unsigned abcd[] ){
    return abcd[2] ^ (abcd[1] |~ abcd[3]);}
typedef unsigned (*DgstFctn)(unsigned a[]);
unsigned *calctable( unsigned *k)
{
    double s, pwr;
    int i;
    pwr = pow( 2, 32);
    for (i=0; i<64; i++) {
        s = fabs(sin(1+i));
        k[i] = (unsigned)( s * pwr );
    }
    return k;
}
unsigned rol( unsigned r, short N )
{
    unsigned  mask1 = (1<<N) -1;
    return ((r>>(32-N)) & mask1) | ((r<<N) & ~mask1);
}

unsigned *md5( const char *msg, int mlen)
{
    /*Initialize Digest Array as A , B, C, D */
    static DigestArray h0 = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476 };
    static DgstFctn ff[] = { &func0, &func1, &func2, &func3 };
    static short M[] = { 1, 5, 3, 7 };
    static short O[] = { 0, 1, 5, 0 };
    static short rot0[] = { 7,12,17,22};
    static short rot1[] = { 5, 9,14,20};
    static short rot2[] = { 4,11,16,23};
    static short rot3[] = { 6,10,15,21};
    static short *rots[] = {rot0, rot1, rot2, rot3 };
    static unsigned kspace[64];
    static unsigned *k;
 
    static DigestArray h;
    DigestArray abcd;
    DgstFctn fctn;
    short m, o, g;
    unsigned f;
    short *rotn;
    union {
        unsigned w[16];
        char     b[64];
    }mm;
    int os = 0;
    int grp, grps, q, p;
    unsigned char *msg2;
 
    if (k==NULL) k= calctable(kspace);
 
    for (q=0; q<4; q++) h[q] = h0[q];   // initialize
 
    {
        grps  = 1 + (mlen+8)/64;
        msg2 = (unsigned char *)malloc( 64*grps);
        memcpy( msg2, msg, mlen);
        msg2[mlen] = (unsigned char)0x80; 
        q = mlen + 1;
        while (q < 64*grps){ msg2[q] = 0; q++ ; }
        {
            MD5union u;
            u.w = 8*mlen;
            q -= 8;
            memcpy(msg2+q, &u.w, 4 );
        }
    }
 
    for (grp=0; grp<grps; grp++)
    {
        memcpy( mm.b, msg2+os, 64);
        for(q=0;q<4;q++) abcd[q] = h[q];
        for (p = 0; p<4; p++) {
            fctn = ff[p];
            rotn = rots[p];
            m = M[p]; o= O[p];
            for (q=0; q<16; q++) {
                g = (m*q + o) % 16;
                f = abcd[1] + rol( abcd[0]+ fctn(abcd) + k[q+16*p] + mm.w[g], rotn[q%4]);
 
                abcd[0] = abcd[3];
                abcd[3] = abcd[2];
                abcd[2] = abcd[1];
                abcd[1] = f;
            }
        }
        for (p=0; p<4; p++)
            h[p] += abcd[p];
        os += 64;
    }
    return h;
}   
 
int main( int argc, char *argv[] )
{
	char Buffer[200];
	unsigned char Key[25];
	char MdmNo[15];// = "AN04746B15EE";
	char Pwd[15];// = "atil@123";
	char msg[25];
    int i,j,k;
    
	printf("Enter ModemNo : ");
	scanf("%s",&MdmNo);
	if(strlen(MdmNo) != 12)
	{
		printf("Incorrect Modem No Len [%d][%s]",strlen(MdmNo),MdmNo);
		return 0;
	}
    
	printf("\nEnter Password : ");
	scanf("%s",&Pwd);
    
	if(strlen(Pwd) != 8)
	{
		printf("Incorrect Pwd Len [%d][%s]",strlen(Pwd),Pwd);
		return 0;
	}

	//printf("Enter Modem No|Passwordn Example : [AN04746B15EE|camr@111] nn       -|-  ");
    
    //scanf("%.s",&msg[0]);
	sprintf(&msg[0],"%.12s|%.8s",MdmNo,Pwd);
	
printf("\n");
    // msg = "AN04746B15EE|atil@123";
   // printf("----------------------------------------------------n");
 //   printf("-------------Made by C codechamp--------------------n");
  //  printf("----------------------------------------------------nn");
  //  printf("t MD5 ENCRYPTION ALGORITHM IN C nn");
    printf("\nInput String to be Encrypted using MD5 is :  %s  ",msg);
    unsigned *d = md5((const char*)msg, strlen(msg));
    MD5union u;
    printf("\n The MD5 code for inputstring[%d]is   :  0x",(char*)strlen((char*)d));    
	i=0;
	//i += sprintf((char*)&Key[i],"0x");    
    for (j=0;j<4; j++)
    {
        u.w = d[j];
        for (k=0;k<4;k++)
        {
        	printf("%02x",u.b[k]);
        	i += sprintf((char*)&Key[i],"%02x",u.b[k]);
        }
    }
    printf("\n");
    printf("\t [%d] MD5 Encyption Successfully Completed!!!\n",i);
    sprintf((char*)&Buffer[0],"currentdate=currentdate&username=%.12s&Password=0x%.32s",MdmNo,Key);
    printf("\n Req[%s] \n",Buffer);
    //getch();
    //system("pause");
    return 0;
}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs