📄 md5main.cpp
字号:
pState[ 3 ] += d;
}
unsigned char *
MD5_pGenerateHomePlugKey ( unsigned char *cPassword )
{
int i, j;
char cSaltStr[ 9 ];
const int iStr[ 8 ] = { 0x08, 0x85, 0x6D, 0xAF, 0x7C, 0xF5, 0x81, 0x85 };
int iOneBits;
unsigned char cTempStr[ 64 ];
/* salt given as 0x08856DAF7CF58185
** convert the salt from hex to a string
*/
for ( i = 0; i < 8 ;++i )
{
cSaltStr[ i ] = iStr[ i ];
cSaltStr[ i + 1 ] = '\0';
}
strcpy( cTempStr, cPassword );
/* Concatenate the password and the salt */
strcat( cTempStr, cSaltStr );
/* Apply MD5 1 time, digest in Md5_cPasswordDigest */
i = 1;
UTI_vString( cTempStr, strlen( cPassword ) + 8, FALSE, FALSE );
/* Apply MD5 999 more times */
for ( i = 2; i <= 1000 ; i++ )
{
UTI_vString( Md5_cPasswordDigest, 16, FALSE, FALSE );
}
for ( i = 0; i < 8; i++ )
{
iOneBits = 0;
for ( j = 0x02; j != 0x00; j <<= 1 )
{
if ( j & Md5_cPasswordDigest[ i ] )
{
iOneBits++;
}
}
if ( ( iOneBits & 0x01 ) ) /* odd number of 1 bits in upper 7 bits */
{
Md5_cPasswordDigest[ i ] &= 0xFE; /* bit count odd already--make LSB a zero */
}
else
{
Md5_cPasswordDigest[ i ] |= 0x01; /* bit count even--make LSB a one */
}
}
return Md5_cPasswordDigest;
}
/* Check password validity */
int
MD5_iCheckPwdValidity ( unsigned char *pcPassword ) /* pointer to password */
{
int i;
if ( pcPassword == NULL )
{
printf( "No password was entered...exiting\n" );
return( 0 );
}
/* Check the length of the password entered */
if ( ( strlen( pcPassword ) < 4 ) || ( strlen( pcPassword ) > 24 ) )
{
printf( "Password length illegal, use 4-24 chars\n" );
return ( 0 );
}
/* Check that password characters are valid */
for ( i = 0; pcPassword[ i ] != '\0'; ++i )
{
/* check for valid character set (SPACE to DEL) */
if ( pcPassword[ i ] >= 0x20 && pcPassword[ i ] <= 0x7F)
{
continue;
}
else
{
printf( "Illegal character in password, CTRL and ALT characters not allowed.\n" );
return( 0 );
}
}
return ( 1 );
}
unsigned char *
MD5_pGetDigestPtr ( void )
{
return Md5_cPasswordDigest;
}
/* Digests a string and returns digest pointer. */
unsigned char *
MD5_pDigestString ( char *pString,
int iLen )
{
Md5_tContext sContext;
Md5_vInit ( &sContext );
Md5_vUpdate ( &sContext, pString, iLen );
Md5_vFinal ( &sContext );
return Md5_cPasswordDigest;
}
unsigned char *
MD5_pDigestFile ( char *pFilename )
{
FILE *pFile;
Md5_tContext sContext;
int iLen;
unsigned char cBuffer[ 1024 ];
if ( ( pFile = fopen ( pFilename, "rb" ) ) == NULL )
{
printf ("%s can't be opened\n", pFilename);
return NULL;
}
else
{
Md5_vInit ( &sContext );
while ( iLen = fread ( cBuffer, 1, 1024, pFile ) )
{
Md5_vUpdate ( &sContext, cBuffer, iLen );
}
Md5_vFinal ( &sContext );
fclose ( pFile );
return Md5_cPasswordDigest;
}
}
/* Digests a reference suite of strings and prints the results. */
void
UTI_vTestSuite ( void )
{
printf ( "MD5 test suite:\n" );
UTI_vString ( "", strlen( "" ), TRUE, TRUE );
UTI_vString ( "a", strlen( "a" ), TRUE, TRUE );
UTI_vString ( "abc", strlen( "abc" ), TRUE, TRUE );
UTI_vString ( "message digest", strlen( "message digest" ), TRUE, TRUE );
UTI_vString ( "abcdefghijklmnopqrstuvwxyz", strlen( "abcdefghijklmnopqrstuvwxyz" ), TRUE, TRUE );
UTI_vString ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
strlen( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ), TRUE, TRUE );
UTI_vString ( "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
strlen( "12345678901234567890123456789012345678901234567890123456789012345678901234567890" ), TRUE, TRUE );
}
/* Digests a file and prints the result. */
void
UTI_vFile ( char *pFilename ) /* ptr to filename to be digested */
{
unsigned char *pDigest;
pDigest = MD5_pDigestFile ( pFilename );
if ( pDigest != NULL )
{
printf ( "MD5 (%s) = 0x", pFilename );
UTI_vPrint ( pDigest, 16 );
printf ( "\n" );
}
}
/* Prints a message digest in hexadecimal. */
void
UTI_vPrint ( unsigned char *pIn, /* ptr to input binary string to be printed */
unsigned int iLen ) /* length of binary string */
{
unsigned int i;
for ( i = 0; i < iLen; i++ )
{
printf ( "%02x", pIn[ i ] );
}
}
void
UTI_vString ( char *pString, /* ptr to string to be digested */
int iLen, /* length of string */
unsigned char bPrintDigest, /* print digest flag */
unsigned char bPrintString ) /* print input string flag */
{
unsigned char *pDigest;
pDigest = MD5_pDigestString ( pString, iLen );
if ( bPrintString )
{
printf( "MD5 (\"%s\") = 0x", pString );
}
if ( bPrintDigest )
{
UTI_vPrint( pDigest, 16 );
printf( "\n" );
}
}
/*****************************************************************************************************/
void main()
{
uchar *pKey;
uchar buff[150],tmp[20],buff1[50];
uchar datbuf[130];
int i,j;
FILE *in,*out,*stream;
clrscr();
in = fopen("1.bin", "rb");
fseek(in, SEEK_SET, 0);
memset(datbuf,sizeof(datbuf),0);
fread(datbuf, 128, 1, in);
fclose(in);
stream = fopen("PWD4.TXT", "wt");
// stream = fopen("PWDR1.TXT", "wt");
// for(i=3701;i<3709;i++)
// for(i=501;i<3700;i++)
// for(i=3700;i<3709;i++)
// for(i=3709;i<7209;i++)
for(i=7209;i<7509;i++)
{
memset(tmp,sizeof(tmp),0);
sprintf(tmp,"%04x",i+256);
for(j=0;j<4;j++) tmp[j]=toupper(tmp[j]);
memset(buff,sizeof(buff),0);
strcpy(buff,"MAC:00050101");
strcat(buff,tmp);
strcat(buff,"\n");
strcat(buff,"PWD:");
memset(buff1,sizeof(buff1),0);
strcpy(buff1,"STBN-WQYE-PKDA-");
// strcpy(buff1,"CSS1-WKZ2-HYZL-");
memset(tmp,sizeof(tmp),0);
sprintf(tmp,"%04x",i+77); //just different from MAC
for(j=0;j<4;j++) tmp[j]=toupper(tmp[j]);
strcat(buff1,tmp);
strcat(buff,buff1);
strcat(buff,"\n");
fprintf(stream,buff);
pKey = MD5_pGenerateHomePlugKey(buff1);
/*
memset(buff1,sizeof(buff1),0);
sprintf(buff1," COD:%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X",pKey[0],pKey[1],pKey[2],pKey[3],pKey[4],pKey[5],pKey[6],pKey[7]);
strcat(buff,buff1);
*/
anumber.i = i + 256; // MAC from 0100 begin
datbuf[6] = anumber.buf[1];
datbuf[7] = anumber.buf[0];
memcpy(&datbuf[8],&pKey[0],8);
memset(tmp,sizeof(tmp),0);
sprintf(tmp,"%04d.bin",i);
out = fopen(tmp,"wb");
fwrite(datbuf, 128, 1, out);
fclose(out);
}
fclose(stream);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -