当前位置:首页 » 编程语言 » md5c语言实现

md5c语言实现

发布时间: 2023-06-17 19:46:08

① 求c语言调用md5函数的函数,注意是直接输入字符串就能获得的,不要输入文件名的那种

c语言标准库没有这个函数,随便给你搜了一下别人的实现

/*md5.h*/
#ifndef MD5_H
#define MD5_H

typedef struct
{
unsigned int count[2];
unsigned int state[4];
unsigned char buffer[64];
}MD5_CTX;

#define F(x,y,z) ((x & y) | (~x & z))
#define G(x,y,z) ((x & z) | (y & ~z))
#define H(x,y,z) (x^y^z)
#define I(x,y,z) (y ^ (x | ~z))
#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))
#define FF(a,b,c,d,x,s,ac) \
{ \
a += F(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define GG(a,b,c,d,x,s,ac) \
{ \
a += G(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define HH(a,b,c,d,x,s,ac) \
{ \
a += H(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define II(a,b,c,d,x,s,ac) \
{ \
a += I(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
void MD5Init(MD5_CTX *context);
void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen);
void MD5Final(MD5_CTX *context,unsigned char digest[16]);
void MD5Transform(unsigned int state[4],unsigned char block[64]);
void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len);
void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len);

#endif

/*md5.c*/
#include <memory.h>
#include "md5.h"

unsigned char PADDING[]={0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

void MD5Init(MD5_CTX *context)
{
context->count[0] = 0;
context->count[1] = 0;
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
}
void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen)
{
unsigned int i = 0,index = 0,partlen = 0;
index = (context->count[0] >> 3) & 0x3F;
partlen = 64 - index;
context->count[0] += inputlen << 3;
if(context->count[0] < (inputlen << 3))
context->count[1]++;
context->count[1] += inputlen >> 29;

if(inputlen >= partlen)
{
memcpy(&context->buffer[index],input,partlen);
MD5Transform(context->state,context->buffer);
for(i = partlen;i+64 <= inputlen;i+=64)
MD5Transform(context->state,&input[i]);
index = 0;
}
else
{
i = 0;
}
memcpy(&context->buffer[index],&input[i],inputlen-i);
}
void MD5Final(MD5_CTX *context,unsigned char digest[16])
{
unsigned int index = 0,padlen = 0;
unsigned char bits[8];
index = (context->count[0] >> 3) & 0x3F;
padlen = (index < 56)?(56-index):(120-index);
MD5Encode(bits,context->count,8);
MD5Update(context,PADDING,padlen);
MD5Update(context,bits,8);
MD5Encode(digest,context->state,16);
}
void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len)
{
unsigned int i = 0,j = 0;
while(j < len)
{
output[j] = input[i] & 0xFF;
output[j+1] = (input[i] >> 8) & 0xFF;
output[j+2] = (input[i] >> 16) & 0xFF;
output[j+3] = (input[i] >> 24) & 0xFF;
i++;
j+=4;
}
}
void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len)
{
unsigned int i = 0,j = 0;
while(j < len)
{
output[i] = (input[j]) |
(input[j+1] << 8) |
(input[j+2] << 16) |
(input[j+3] << 24);
i++;
j+=4;
}
}
void MD5Transform(unsigned int state[4],unsigned char block[64])
{
unsigned int a = state[0];
unsigned int b = state[1];
unsigned int c = state[2];
unsigned int d = state[3];
unsigned int x[64];
MD5Decode(x,block,64);
FF(a, b, c, d, x[ 0], 7, 0xd76aa478); /* 1 */
FF(d, a, b, c, x[ 1], 12, 0xe8c7b756); /* 2 */
FF(c, d, a, b, x[ 2], 17, 0x242070db); /* 3 */
FF(b, c, d, a, x[ 3], 22, 0xc1bdceee); /* 4 */
FF(a, b, c, d, x[ 4], 7, 0xf57c0faf); /* 5 */
FF(d, a, b, c, x[ 5], 12, 0x4787c62a); /* 6 */
FF(c, d, a, b, x[ 6], 17, 0xa8304613); /* 7 */
FF(b, c, d, a, x[ 7], 22, 0xfd469501); /* 8 */
FF(a, b, c, d, x[ 8], 7, 0x698098d8); /* 9 */
FF(d, a, b, c, x[ 9], 12, 0x8b44f7af); /* 10 */
FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */
FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */
FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */
FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */
FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */
FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 */

/* Round 2 */
GG(a, b, c, d, x[ 1], 5, 0xf61e2562); /* 17 */
GG(d, a, b, c, x[ 6], 9, 0xc040b340); /* 18 */
GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */
GG(b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /* 20 */
GG(a, b, c, d, x[ 5], 5, 0xd62f105d); /* 21 */
GG(d, a, b, c, x[10], 9, 0x2441453); /* 22 */
GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */
GG(b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /* 24 */
GG(a, b, c, d, x[ 9], 5, 0x21e1cde6); /* 25 */
GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */
GG(c, d, a, b, x[ 3], 14, 0xf4d50d87); /* 27 */
GG(b, c, d, a, x[ 8], 20, 0x455a14ed); /* 28 */
GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */
GG(d, a, b, c, x[ 2], 9, 0xfcefa3f8); /* 30 */
GG(c, d, a, b, x[ 7], 14, 0x676f02d9); /* 31 */
GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */

/* Round 3 */
HH(a, b, c, d, x[ 5], 4, 0xfffa3942); /* 33 */
HH(d, a, b, c, x[ 8], 11, 0x8771f681); /* 34 */
HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */
HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */
HH(a, b, c, d, x[ 1], 4, 0xa4beea44); /* 37 */
HH(d, a, b, c, x[ 4], 11, 0x4bdecfa9); /* 38 */
HH(c, d, a, b, x[ 7], 16, 0xf6bb4b60); /* 39 */
HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */
HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */
HH(d, a, b, c, x[ 0], 11, 0xeaa127fa); /* 42 */
HH(c, d, a, b, x[ 3], 16, 0xd4ef3085); /* 43 */
HH(b, c, d, a, x[ 6], 23, 0x4881d05); /* 44 */
HH(a, b, c, d, x[ 9], 4, 0xd9d4d039); /* 45 */
HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */
HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */
HH(b, c, d, a, x[ 2], 23, 0xc4ac5665); /* 48 */

/* Round 4 */
II(a, b, c, d, x[ 0], 6, 0xf4292244); /* 49 */
II(d, a, b, c, x[ 7], 10, 0x432aff97); /* 50 */
II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */
II(b, c, d, a, x[ 5], 21, 0xfc93a039); /* 52 */
II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */
II(d, a, b, c, x[ 3], 10, 0x8f0ccc92); /* 54 */
II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */
II(b, c, d, a, x[ 1], 21, 0x85845dd1); /* 56 */
II(a, b, c, d, x[ 8], 6, 0x6fa87e4f); /* 57 */
II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */
II(c, d, a, b, x[ 6], 15, 0xa3014314); /* 59 */
II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */
II(a, b, c, d, x[ 4], 6, 0xf7537e82); /* 61 */
II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */
II(c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /* 63 */
II(b, c, d, a, x[ 9], 21, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
}

② C语言求文件MD5的函数用法

C语言没有内置的MD5函数,可以在以下页面找到C语言实现程序和MD5的算法介绍:

http://tools.ietf.org/html/rfc1321

③ 用c语言实现python的md5功能

题中所示代码中,python实现了计算空字符串的MD5值,并对MD5的值的十六进制的字符串所表示的字节进行BASE64处理。

不像Python内部有实现md5功能,根据ANSI C标准,C语言的标准库里是没有md5功能的;

但是RFC1231规定了MD5功能的C实现并提供了附件,可以直接用,也可以直接获取现成的实现,在编译链接时指定正确的.h头文件和.lib静态链接库文件;

这里我采取前者的做法(电脑上没有装VC,有VC就简单很多,使用的是minGW)大概六七百行代码左右。

然后这里展示不完,给个实现效果图

BASE64的编码原理

④ c语言实现MD5加密算法,出现问题求解

找不到md5.h的头文件 将你的md5.h头文件跟你的c文件放在同一目录下

⑤ 请教MD5算法 用C语言实现

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#ifdefined(__APPLE__)
#defineCOMMON_DIGEST_FOR_OPENSSL
#include<CommonCrypto/CommonDigest.h>
#defineSHA1CC_SHA1
#else
#include<openssl/md5.h>
#endif

//这是我自己写的函数,用于计算MD5
//参数str:要转换的字符串
//参数lengthL:字符串的长度可以用strlen(str)直接获取参数str的长度
//返回值:MD5字符串
char*str2md5(constchar*str,intlength){
intn;
MD5_CTXc;
unsignedchardigest[16];
char*out=(char*)malloc(33);

MD5_Init(&c);

while(length>0){
if(length>512){
MD5_Update(&c,str,512);
}else{
MD5_Update(&c,str,length);
}
length-=512;
str+=512;
}

MD5_Final(digest,&c);

for(n=0;n<16;++n){
snprintf(&(out[n*2]),16*2,"%02x",(unsignedint)digest[n]);
}

returnout;
}

intmain(intargc,char**argv){
char*output=str2md5("hello",strlen("hello"));

printf("%s ",output);
//上面会输出hello的MD5字符串:
//
free(output);
return0;
}

⑥ 求生成MD5码的c或c++代码

自己用C语言写的简单的MD5算法实现。

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>

typedef unsigned char BYTE;
typedef unsigned int UINT;
typedef UINT MD5_SUB_ARRAY[16];
typedef UINT MD5_TRANSORM_FUNC(UINT,UINT,UINT);
typedef struct
{
UINT a;
UINT b;
UINT c;
UINT d;
MD5_SUB_ARRAY sub_array;
}MD5_TRANSFORM_PARAM;

const double MAX_INT = (double)0xFFFFFFFF + 1.0;

const UINT MD5_TRANSFORM_MATRIX[4][16][3] =
{

{
{ 0, 7, 1}, { 1,12, 2}, { 2,17, 3}, { 3,22, 4},
{ 4, 7, 5}, { 5,12, 6}, { 6,17, 7}, { 7,22, 8},
{ 8, 7, 9}, { 9,12,10}, {10,17,11}, {11,22,12},
{12, 7,13}, {13,12,14}, {14,17,15}, {15,22,16},
},

{
{ 1, 5,17}, { 6, 9,18}, {11,14,19}, { 0,20,20},
{ 5, 5,21}, {10, 9,22}, {15,14,23}, { 4,20,24},
{ 9, 5,25}, {14, 9,26}, { 3,14,27}, { 8,20,28},
{13, 5,29}, { 2, 9,30}, { 7,14,31}, {12,20,32},
},

{
{5, 4, 33}, { 8,11,34}, {11,16,35},{14, 23,36},
{1, 4, 37}, { 4,11,38}, { 7,16,39},{10, 23,40},
{13,4, 41}, { 0,11,42}, { 3,16,43},{ 6, 23,44},
{9, 4, 45}, {12,11,46}, {15,16,47},{ 2, 23,48},
},

{
{ 0,6,49}, { 7,10,50}, {14,15,51},{ 5, 21,52},
{12,6,53}, { 3,10,54}, {10,15,55},{ 1, 21,56},
{ 8,6,57}, {15,10,58}, { 6,15,59},{13, 21,60},
{ 4,6,61}, {11,10,62}, { 2,15,63},{ 9, 21,64},
},
};

static UINT MD5_TRANSFORM_ARRAY[65];

void MD5_Init()
{
int x;
for(x = 1; x <= 64; x++)
{
MD5_TRANSFORM_ARRAY[x] = (UINT)(MAX_INT * fabs(sin(x)));
}
}

UINT F(UINT x,UINT y,UINT z)
{
return ((x & y) | ((~x) & z));
}

UINT G(UINT x,UINT y,UINT z)
{
return ((x & z) | (y & (~z)));
}

UINT H(UINT x,UINT y,UINT z)
{
return (x ^ y ^ z);
}

UINT I(UINT x,UINT y,UINT z)
{
return (y ^ (x | (~z)));
}

BYTE* MD5_prepare_data(const BYTE* data,int len,int* new_len)
{
int rest,fill,size;
BYTE* new_data;
UINT bit_len;

// (1) 字节补齐
rest = len % 56;
if (rest <= 56) fill = 56 - rest;
else fill = (64 - rest) + 56;

new_data = (BYTE*)malloc(len + fill + 8);
if (NULL == new_data) return NULL;

if (len > 0) memcpy(new_data,data,len);
if (fill > 0) memset(new_data + len,0x80,1);
if (fill > 1) memset(new_data + len + 1,0,fill - 1);

size = fill + len;

// (2) 附加数据的比特长度
bit_len = len * 8;
// (64位二进制数表示的)比特长度的低32位
memset(new_data + size + 0,(bit_len & 0x000000FF), 1);
memset(new_data + size + 1,(bit_len & 0x0000FF00) >> 8, 1);
memset(new_data + size + 2,(bit_len & 0x00FF0000) >> 16,1);
memset(new_data + size + 3,(bit_len & 0xFF000000) >> 24,1);
// 不考虑比特长度超出32位无符号数表示范围,所以高32位总是0
memset(new_data + size + 4,0,4);

*new_len = size + 8;

return new_data;
}

void MD5_transform(MD5_TRANSFORM_PARAM* param,int ring,MD5_TRANSORM_FUNC func)
{
UINT a,b,c,d,s,k,i;
UINT abcd[4];
UINT *X,*T;
int index;

abcd[0] = param->a;
abcd[1] = param->b;
abcd[2] = param->c;
abcd[3] = param->d;
X = param->sub_array;
T = MD5_TRANSFORM_ARRAY;

for(index = 0; index < 16; index++)
{
a = abcd[(3 * index + 0) % 4];
b = abcd[(3 * index + 1) % 4];
c = abcd[(3 * index + 2) % 4];
d = abcd[(3 * index + 3) % 4];

k = MD5_TRANSFORM_MATRIX[ring][index][0];
s = MD5_TRANSFORM_MATRIX[ring][index][1];
i = MD5_TRANSFORM_MATRIX[ring][index][2];

a = a + func(b,c,d) + X[k] + T[i];
a = ( a << s) | ( a >> (32 - s)); // 循环左移
a = a + b;

abcd[(3 * index + 0) % 4] = a;
}

param->a = abcd[0];
param->b = abcd[1];
param->c = abcd[2];
param->d = abcd[3];
}

int MD5(const BYTE* data,int len)
{
int x,y,new_len;
MD5_TRANSFORM_PARAM param;
UINT AA,BB,CC,DD;
BYTE* buf;

MD5_Init();

buf = MD5_prepare_data(data,len,&new_len);
if (buf == NULL) return -1;

AA = 0x67452301;
BB = 0xefcdab89;
CC = 0x98badcfe;
DD = 0x10325476;

for(x = 0; x < new_len / 64; x++)
{
param.a = AA;
param.b = BB;
param.c = CC;
param.d = DD;

for(y = 0; y < 16; y++)
{
param.sub_array[y] = buf[64 * x + 4 * y + 0];
param.sub_array[y] += buf[64 * x + 4 * y + 1] << 8;
param.sub_array[y] += buf[64 * x + 4 * y + 2] << 16;
param.sub_array[y] += buf[64 * x + 4 * y + 3] << 24;
}
MD5_transform(¶m,0,F);
MD5_transform(¶m,1,G);
MD5_transform(¶m,2,H);
MD5_transform(¶m,3,I);

AA += param.a;
BB += param.b;
CC += param.c;
DD += param.d;
}

printf("MD5(\"%s\")=",data);

printf("%02X%02X%02X%02X",
(AA & 0x000000FF),
(AA & 0x0000FF00) >> 8,
(AA & 0x00FF0000) >> 16,
(AA & 0xFF000000) >> 24);

printf("%02X%02X%02X%02X",
(BB & 0x000000FF),
(BB & 0x0000FF00) >> 8,
(BB & 0x00FF0000) >> 16,
(BB & 0xFF000000) >> 24);

printf("%02X%02X%02X%02X",
(CC & 0x000000FF),
(CC & 0x0000FF00) >> 8,
(CC & 0x00FF0000) >> 16,
(CC & 0xFF000000) >> 24);

printf("%02X%02X%02X%02X",
(DD & 0x000000FF),
(DD & 0x0000FF00) >> 8,
(DD & 0x00FF0000) >> 16,
(DD & 0xFF000000) >> 24);

printf("\n");

return 0;
}

int main()
{
MD5("",0);
MD5("a",1);
MD5("abc",3);
MD5("message digest",14);
MD5("abcdefghijklmnopqrstuvwxyz",26);

return 0;
}

⑦ C语言怎么实现对一长串字符进行MD5加密

#include<stdio.h>
#include<stdlib.h>

#defineARR_LEN100

#defineF(x,y,z)((x&y)|(~x&z))
#defineG(x,y,z)((x&z)|(y&~z))
#defineH(x,y,z)(x^y^z)
#defineI(x,y,z)(y^(x|~z))
#defineROTATE_LEFT(x,n)((x<<n)|(x>>(32-n)))
#defineFF(a,b,c,d,x,s,ac)
{
a+=F(b,c,d)+x+ac;
a=ROTATE_LEFT(a,s);
a+=b;
}
#defineGG(a,b,c,d,x,s,ac)
{
a+=G(b,c,d)+x+ac;
a=ROTATE_LEFT(a,s);
a+=b;
}
#defineHH(a,b,c,d,x,s,ac)
{
a+=H(b,c,d)+x+ac;
a=ROTATE_LEFT(a,s);
a+=b;
}
#defineII(a,b,c,d,x,s,ac)
{
a+=I(b,c,d)+x+ac;
a=ROTATE_LEFT(a,s);
a+=b;
}

typedefstruct{
unsignedintcount[2];
unsignedintstate[4];
unsignedcharbuffer[64];
}MD5_CTX;

voidMD5Init(MD5_CTX*context);
voidMD5Update(MD5_CTX*context,unsignedchar*input,unsignedintinputlen);
voidMD5Final(MD5_CTX*context,unsignedchardigest[16]);
voidMD5Transform(unsignedintstate[4],unsignedcharblock[64]);
voidMD5Encode(unsignedchar*output,unsignedint*input,unsignedintlen);
voidMD5Decode(unsignedint*output,unsignedchar*input,unsignedintlen);

unsignedcharPADDING[]={
0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

voidMD5Init(MD5_CTX*context){
context->count[0]=0;
context->count[1]=0;
context->state[0]=0x67452301;
context->state[1]=0xEFCDAB89;
context->state[2]=0x98BADCFE;
context->state[3]=0x10325476;
}

voidMD5Update(MD5_CTX*context,unsignedchar*input,unsignedintinputlen){
unsignedinti=0,index=0,partlen=0;
index=(context->count[0]>>3)&0x3F;
partlen=64-index;
context->count[0]+=inputlen<<3;
if(context->count[0]<(inputlen<<3))
context->count[1]++;
context->count[1]+=inputlen>>29;

if(inputlen>=partlen){
memcpy(&context->buffer[index],input,partlen);
MD5Transform(context->state,context->buffer);
for(i=partlen;i+64<=inputlen;i+=64)
MD5Transform(context->state,&input[i]);
index=0;
}
else{
i=0;
}
memcpy(&context->buffer[index],&input[i],inputlen-i);
}

voidMD5Final(MD5_CTX*context,unsignedchardigest[16]){
unsignedintindex=0,padlen=0;
unsignedcharbits[8];
index=(context->count[0]>>3)&0x3F;
padlen=(index<56)?(56-index):(120-index);
MD5Encode(bits,context->count,8);
MD5Update(context,PADDING,padlen);
MD5Update(context,bits,8);
MD5Encode(digest,context->state,16);
}

voidMD5Encode(unsignedchar*output,unsignedint*input,unsignedintlen){
unsignedinti=0,j=0;
while(j<len){
output[j]=input[i]&0xFF;
output[j+1]=(input[i]>>8)&0xFF;
output[j+2]=(input[i]>>16)&0xFF;
output[j+3]=(input[i]>>24)&0xFF;
i++;
j+=4;
}
}

voidMD5Decode(unsignedint*output,unsignedchar*input,unsignedintlen){
unsignedinti=0,j=0;
while(j<len){
output[i]=(input[j])|
(input[j+1]<<8)|
(input[j+2]<<16)|
(input[j+3]<<24);
i++;
j+=4;
}
}

voidMD5Transform(unsignedintstate[4],unsignedcharblock[64]){
unsignedinta=state[0];
unsignedintb=state[1];
unsignedintc=state[2];
unsignedintd=state[3];
unsignedintx[64];
MD5Decode(x,block,64);
FF(a,b,c,d,x[0],7,0xd76aa478);/*1*/
FF(d,a,b,c,x[1],12,0xe8c7b756);/*2*/
FF(c,d,a,b,x[2],17,0x242070db);/*3*/
FF(b,c,d,a,x[3],22,0xc1bdceee);/*4*/
FF(a,b,c,d,x[4],7,0xf57c0faf);/*5*/
FF(d,a,b,c,x[5],12,0x4787c62a);/*6*/
FF(c,d,a,b,x[6],17,0xa8304613);/*7*/
FF(b,c,d,a,x[7],22,0xfd469501);/*8*/
FF(a,b,c,d,x[8],7,0x698098d8);/*9*/
FF(d,a,b,c,x[9],12,0x8b44f7af);/*10*/
FF(c,d,a,b,x[10],17,0xffff5bb1);/*11*/
FF(b,c,d,a,x[11],22,0x895cd7be);/*12*/
FF(a,b,c,d,x[12],7,0x6b901122);/*13*/
FF(d,a,b,c,x[13],12,0xfd987193);/*14*/
FF(c,d,a,b,x[14],17,0xa679438e);/*15*/
FF(b,c,d,a,x[15],22,0x49b40821);/*16*/

/*Round2*/
GG(a,b,c,d,x[1],5,0xf61e2562);/*17*/
GG(d,a,b,c,x[6],9,0xc040b340);/*18*/
GG(c,d,a,b,x[11],14,0x265e5a51);/*19*/
GG(b,c,d,a,x[0],20,0xe9b6c7aa);/*20*/
GG(a,b,c,d,x[5],5,0xd62f105d);/*21*/
GG(d,a,b,c,x[10],9,0x2441453);/*22*/
GG(c,d,a,b,x[15],14,0xd8a1e681);/*23*/
GG(b,c,d,a,x[4],20,0xe7d3fbc8);/*24*/
GG(a,b,c,d,x[9],5,0x21e1cde6);/*25*/
GG(d,a,b,c,x[14],9,0xc33707d6);/*26*/
GG(c,d,a,b,x[3],14,0xf4d50d87);/*27*/
GG(b,c,d,a,x[8],20,0x455a14ed);/*28*/
GG(a,b,c,d,x[13],5,0xa9e3e905);/*29*/
GG(d,a,b,c,x[2],9,0xfcefa3f8);/*30*/
GG(c,d,a,b,x[7],14,0x676f02d9);/*31*/
GG(b,c,d,a,x[12],20,0x8d2a4c8a);/*32*/

/*Round3*/
HH(a,b,c,d,x[5],4,0xfffa3942);/*33*/
HH(d,a,b,c,x[8],11,0x8771f681);/*34*/
HH(c,d,a,b,x[11],16,0x6d9d6122);/*35*/
HH(b,c,d,a,x[14],23,0xfde5380c);/*36*/
HH(a,b,c,d,x[1],4,0xa4beea44);/*37*/
HH(d,a,b,c,x[4],11,0x4bdecfa9);/*38*/
HH(c,d,a,b,x[7],16,0xf6bb4b60);/*39*/
HH(b,c,d,a,x[10],23,0xbebfbc70);/*40*/
HH(a,b,c,d,x[13],4,0x289b7ec6);/*41*/
HH(d,a,b,c,x[0],11,0xeaa127fa);/*42*/
HH(c,d,a,b,x[3],16,0xd4ef3085);/*43*/
HH(b,c,d,a,x[6],23,0x4881d05);/*44*/
HH(a,b,c,d,x[9],4,0xd9d4d039);/*45*/
HH(d,a,b,c,x[12],11,0xe6db99e5);/*46*/
HH(c,d,a,b,x[15],16,0x1fa27cf8);/*47*/
HH(b,c,d,a,x[2],23,0xc4ac5665);/*48*/

/*Round4*/
II(a,b,c,d,x[0],6,0xf4292244);/*49*/
II(d,a,b,c,x[7],10,0x432aff97);/*50*/
II(c,d,a,b,x[14],15,0xab9423a7);/*51*/
II(b,c,d,a,x[5],21,0xfc93a039);/*52*/
II(a,b,c,d,x[12],6,0x655b59c3);/*53*/
II(d,a,b,c,x[3],10,0x8f0ccc92);/*54*/
II(c,d,a,b,x[10],15,0xffeff47d);/*55*/
II(b,c,d,a,x[1],21,0x85845dd1);/*56*/
II(a,b,c,d,x[8],6,0x6fa87e4f);/*57*/
II(d,a,b,c,x[15],10,0xfe2ce6e0);/*58*/
II(c,d,a,b,x[6],15,0xa3014314);/*59*/
II(b,c,d,a,x[13],21,0x4e0811a1);/*60*/
II(a,b,c,d,x[4],6,0xf7537e82);/*61*/
II(d,a,b,c,x[11],10,0xbd3af235);/*62*/
II(c,d,a,b,x[2],15,0x2ad7d2bb);/*63*/
II(b,c,d,a,x[9],21,0xeb86d391);/*64*/
state[0]+=a;
state[1]+=b;
state[2]+=c;
state[3]+=d;
}

intmain(intargc,char*argv[]){
inti;
unsignedcharencrypt[ARR_LEN];
unsignedchardecrypt[16];
MD5_CTXmd5;

printf("【测试1】 ");
printf("加密前:Bai ");
printf("加密后: ");
printf(" ");
printf("【测试2】 ");
printf("加密前:Bihaifeng ");
printf("加密后: ");
printf(" ");
printf("====================================================== ");

printf("请输入需MD5加密的字符串: ");
gets(encrypt);
printf(" ");
printf("====================================================== ");

MD5Init(&md5);
MD5Update(&md5,encrypt,strlen((char*)encrypt));
MD5Final(&md5,decrypt);

printf("加密前:%s 加密后:",encrypt);
for(i=0;i<16;i++){
printf("%02x",decrypt[i]);
}
printf(" ");

getch();
return0;
}

运行结果

以上源代码非原创~~

⑧ md5是什么 如何计算MD5

MD5即Message-Digest Algorithm 5(信息-摘要算法5),用于确保信息传输完整一致。是计算机广泛使用的杂凑算法之一(又译摘要算法、哈希算法),主流编程语言普遍已有MD5实现。

MD5算法具有以下特点:

1、压缩性:任意长度的数据,算出的MD5值长度都是固定的。

2、容易计算:从原数据计算出MD5值很容易。

3、抗修改性:对原数据进行任何改动,哪怕只修改1个字节,所得到的MD5值都有很大区别。

4、强抗碰撞:已知原数据和其MD5值,想找到一个具有相同MD5值的数据(即伪造数据)是非常困难的。

MD5的作用是让大容量信息在用数字签名软件签署私人密钥前被"压缩"成一种保密的格式(就是把一个任意长度的字节串变换成一定长的16进制数字串)。

大家都知道,地球上任何人都有自己独一无二的指纹,这常常成为司法机关鉴别罪犯身份最值得信赖的方法;与之类似,MD5就可以为任何文件(不管其大小、格式、数量)产生一个同样独一无二的MD5“数字指纹”,如果任何人对文件做了任何改动,其MD5也就是对应的“数字指纹”都会发生变化。

热点内容
整个服务器搭建教程 发布:2025-02-12 11:48:16 浏览:579
我的世界服务器人多的 发布:2025-02-12 11:48:12 浏览:347
为实现分页存储管理需要哪些硬件支持 发布:2025-02-12 11:46:34 浏览:539
编程下载线 发布:2025-02-12 11:41:48 浏览:210
json存储数据 发布:2025-02-12 11:41:39 浏览:219
天龙八部脚本免费 发布:2025-02-12 11:30:12 浏览:501
卡罗拉的配置一般买哪个好一点 发布:2025-02-12 11:20:03 浏览:743
没有服务器的IP怎么连上 发布:2025-02-12 11:19:55 浏览:80
编程sqs 发布:2025-02-12 11:09:55 浏览:239
electron脱离编译环境 发布:2025-02-12 11:08:21 浏览:69