📄 mddriver.c
字号:
/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
rights reserved.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include "md5.h"
static void MDPrint (unsigned char digest[16])
{
unsigned int i;
for (i = 0; i < 16; i++)
printf ("%02x", digest[i]);
}
static void MD5String (char *string)
{
MD5_CTX context;
unsigned char digest[16];
unsigned int len = strlen (string);
MD5Init (&context);
MD5Update (&context, string, len);
MD5Final (digest, &context);
printf ("MD5 (\"%s\") = ", string);
MDPrint (digest);
printf ("\n");
}
static void MD5File (char *filename)
{
FILE *file;
MD5_CTX context;
int len;
unsigned char buffer[1024], digest[16];
if ((file = fopen (filename, "rb")) == NULL)
{
printf ("%s can't be opened\n", filename);
}
else
{
MD5Init (&context);
while (len = fread (buffer, 1, 1024, file))
MD5Update (&context, buffer, len);
MD5Final (digest, &context);
fclose (file);
printf ("MD5 (%s) = ", filename);
MDPrint (digest);
printf ("\n");
}
}
int main()
{
char all_chars[] = "0123456789";
char tmp[128];
int spacelen = strlen(all_chars);
int pwlen = 8;
char *tmpspace[8+1];
int i;
unsigned char digest[16];
MD5_CTX context;
DWORD dwTime = GetTickCount();
memset(tmp, '\0', sizeof(tmp));
tmpspace[0]=&all_chars[0];
for (i=1; i<=pwlen; i++) {
tmpspace[i]=0;
}
while(!tmpspace[pwlen]) {
for (i=0; i<=pwlen; i++) {
if(tmpspace[i] != 0)
tmp[i]=*tmpspace[i];//构造一个新的字符串
else
break;
}
MD5Init (&context);
MD5Update (&context, (unsigned char*)tmp, strlen(tmp));
MD5Final (digest, &context);
tmpspace[0]++;//指针移动到标准数组的下一个,注意此处的tmpspace[0]只是一个简单的指针而已
for (i=0; i<pwlen; i++) {
if (tmpspace[i] > &all_chars[spacelen -1]) {
tmpspace[i] = &all_chars[0];
if (tmpspace[i+1] !=0)
tmpspace[i+1]++;
else
tmpspace[i+1] = &all_chars[0];
}//if
}//for
}
dwTime = GetTickCount() - dwTime;
printf("spend time: %d seconds\n",dwTime/1000);
///////////////////////////////////////////////////////////////////////////////
printf ("MD5 test suite:\n");
MD5String ("");
MD5String ("a");
MD5String ("abc");
MD5String ("message digest");
MD5String ("abcdefghijklmnopqrstuvwxyz");
MD5String
("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
MD5String
("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
getchar();
/*
MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
d174ab98d277d9f5a5611c2c9f419d9f
MD5 ("123456789012345678901234567890123456789012345678901234567890123456
78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -