调用md5算法c语言源码

c md5  时间:2021-01-27  阅读:()

#include<string.h>

#include "md5c.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};vo id MD5 Init(MD5_CTX*context)

{cont ext->co unt[0]=0;conte xt->c ount[1]=0;conte xt->state[0]=0 x67452301;conte xt->state[1]=0 xEF CDAB 89;conte xt->s tate[2]=0x98B ADCF E;conte xt->state[3]=0 x 10325476;

}vo id MD5 Update(MD5_CTX*context,unsigne d char*input,uns igned int inputlen){unsigned int i=0,index=0,partlen=0;index=(context->count[0]>>3)&0x3F;partlen=64- index;conte xt->c ount[0]+=inp utle n<<3;if(conte xt->c ount[0]<(inp utle n<<3))conte xt->c o unt[1]++;conte xt->count[1]+=inp utle n>>29;if(inputlen>=partlen)

{me mcpy(&conte xt->buffer[inde x],input,p artle n);

MD5 Trans form(co ntext->state,co ntext->buffer);fo r(i=partle n;i+64<=inp utlen;i+=64)

MD5 Tra ns form(co ntext->stat e,&input[i]);ind e x=0;

}else

{i=0;

}memcpy(&context->buffer[index],&input[i],inputlen-i);

}void MD5Final(MD5_CTX*context,unsigned char digest[16])

{uns igned int index=0,padlen=0;uns igned char b its[8];index=(context->count[0]>>3)&0x3F;

padlen=(index<56)?(56-index):(120-index);

MD5 Enc ode(bits,c onte xt->count,8);

MD5Upd ate(c onte xt,PADDING,padle n);

MD5Up date(conte xt,b its,8);

MD 5 Enco de(d igest,conte xt->s tate,16);

}void MD5 Encode(unsigned char *output,unsigned int*input,unsigned int len){unsigned int i=0,j=0;while(j<len)

{outp ut[j]=input[i]&0 xFF;output[j+1]=(inp ut[i]>>8)&0xFF;outp ut[j+2]=(inp ut[i]>>16)&0xFF;outp ut[j+3]=(inp ut[i]>>24)&0xF F;i++;j+=4;

}

}vo id MD5Deco de(unsigne d int*output,unsigned char*input,unsigned int len){uns igne d int i=0,j=0;while(j<len)

{output[i]=(inp ut[j]) |

(inp ut[j+1]<<8) |

(input[j+2]<<16) |

(input[j+3]<<24);i++;j+=4;

}

}vo id MD5 Trans form(unsigned int state[4],uns igned char b lock[64])

{uns igned int a=state[0];uns ig ned int b=state[1];uns igne d int c=state[2];uns i gned int d=state[3];uns ign ed int x[64];

MD5Decode(x,block,64);

FF(a,b,c,d,x[0],7,0xd76aa478);

FF(d,a,b,c,x[ 1], 12,0xe8c7b756);

FF(c,d,a,b,x[2], 17,0x242070db);

FF(b,c,d,a,x[3],22,0xc 1bdceee);

FF(a,b,c,d,x[4],7,0xf57c0faf);

FF(d,a,b,c,x[5], 12,0x4787c62a);

FF(c,d,a,b,x[6], 17,0xa8304613);F F(b,c,d,a,x[7],22,0 x fd469501);FF(a,b,c,d,x[8],7,0x698098d8);FF(d,a,b,c,x[9], 12,0x8b44f7af);FF(c,d,a,b,x[10], 17,0xffff5bb1);FF(b,c,d,a,x[1 1],22,0x895cd7be);FF(a,b,c,d,x[12],7,0x6b901122);FF(d,a,b,c,x[13], 12,0xfd987193);FF(c,d,a,b,x[14], 17,0xa679438e);FF(b,c,d,a,x[15],22,0x49b40821);GG(a,b,c,d,x[ 1],5,0xf61 e2562);GG(d,a,b,c,x[6],9,0xc040b340);GG(c,d,a,b,x[11], 14,0x265e5a51);GG(b,c,d,a,x[0],20,0xe9b6c7aa);GG(a,b,c,d,x[5],5,0xd62 f105d);GG(d,a,b,c,x[10],9, 0 x2441453);GG(c,d,a,b,x[15], 14,0xd8a1 e681);GG(b,c,d,a,x[4],20,0xe7d3fbc8);GG(a,b,c,d,x[9],5,0x21 e 1 cde6);GG(d, a,b,c,x[14],9,0xc33707d6);GG(c,d,a,b,x[3], 14,0xf4d50d87);GG(b,c,d,a,x[8],20,0x455a14 ed);GG(a,b, c,d,x[13],5,0xa9e3e905);GG(d,a,b,c,x[2],9,0xfcefa3 f8);GG(c,d, a,b,x[7], 14,0x676 f02d9);GG(b,c,d,a,x[12],20,0x8 d2 a4c 8 a);HH(a,b,c,d,x[5],4,0xfffa3942);HH(d,a,b, c,x[8], 11,0x8771 f681);HH(c,d,a,b,x[11], 16,0x6d9d6122);HH(b,c,d,a,x[14],23,0xfde5380 c);HH(a,b, c,d,x[ 1],4,0xa4beea44);HH(d,a,b,c,x[4], 11,0x4bdec fa9);HH(c,d,a,b,x[7], 16,0xf6bb 4b60);HH(b,c,d,a,x[10],23,0xbebfbc70);HH(a,b,c,d,x[13],4,0x289b7ec6);HH(d, a,b,c,x[0], 11,0xe a a 127fa);HH(c,d,a,b,x[3], 16,0xd4e f3085);HH(b,c,d,a,x[6],23, 0x4881 d05);HH(a,b,c,d,x[9],4,0xd9d4d039);HH(d,a,b,c,x[12], 11,0xe6db99e5);HH(c,d,a,b,x[15], 16,0x1fa27cf8);HH(b, c,d,a,x[2],23,0xc4 ac5665);

II(a,b,c,d,x[0],6,0xf4292244);

II(d,a,b,c,x[7], 10,0x432aff97);

II(c,d,a,b,x[14], 15,0xab9423a7);

II(b,c,d,a,x[5],21,0xfc93 a039);

II(a,b,c,d,x[12],6,0x655b59c3);

II(d,a,b,c,x[3], 10,0x8 f0ccc92);

II(c,d,a,b,x[10], 15,0xffeff47d);

II(b,c,d,a,x[ 1],21,0x85845dd 1);

II(a,b,c,d,x[ 8],6,0x6fa87e4f);

II(d,a,b,c,x[15], 10,0xfe2ce6e0);

II(c,d,a,b,x[6], 15,0xa3014314);

II(b, c,d,a,x[13],21,0x4e0811a1);

II(a,b,c,d,x[4],6,0xf7537e82);

II(d,a,b,c,x[11], 10,0xbd3af235);

II(c,d,a,b,x[2], 15,0x2 ad7d2bb);

II(b,c,d,a,x[9],21,0xeb86d391);st ate[0]+=a;s tate[1]+=b;s tate[2]+=c;stat e[3]+=d;

}

//下边是头文件

#ifndefMD5_H

#define MD5_H

typedef struct

{uns igned int count[2];uns ign ed 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=RO TATE_LEFT(a,s);a+=b; }

#define HH(a,b,c,d,x,s,ac) {a+=H(b,c,d)+x+ac; a=RO TATE_LEF T(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; }vo id MD5 Init(MD5_CTX*context);void MD5Update(MD5_CTX*context,unsigned char *input,unsigned int inputlen);void MD5Final(MD5_CTX*context,unsigned char digest[16]);vo id MD 5Trans form(uns igned int state[4],uns igne d char b lo ck[64]);void MD5 Encode(unsigned char *output,unsigned int*input,unsigned int len);void MD5Dec ode(uns igned int*output,uns igned char*input,unsigned int len);#end i f

//调用方法int main(int argc,char*argv[])

{unsigned char encrypt[]="ad";//21232f297a57a5a743894a0e4a801 fc3uns igne d char encrypt1 []="min";unsigned char decrypt[16];

MD5_CTX md5;

MD5 Init(&md5);

MD 5Update(&md5,encrypt,strl en((c har*)encrypt));

MD5Up date(&md5,encrypt1,strlen((char*)encryp t1));

MD5F inal(&md5,decrypt);

}

快云科技:香港沙田CN2云服务器低至29元/月起;美国高防弹性云/洛杉矶CUVIP低至33.6元/月起

快云科技怎么样?快云科技是一家成立于2020年的新起国内主机商,资质齐全 持有IDC ICP ISP等正规商家。云服务器网(yuntue.com)小编之前已经介绍过很多快云科技的香港及美国云服务器了,这次再介绍一下新的优惠方案。目前,香港云沙田CN2云服务器低至29元/月起;美国超防弹性云/洛杉矶CUVIP低至33.6元/月起。快云科技的云主机架构采用KVM虚拟化技术,全盘SSD硬盘,RAID10...

ZJI-全场八折优惠,香港服务器 600元起,还有日本/美国/韩国服务器

月付/年付优惠码:zji  下物理服务器/VDS/虚拟主机空间订单八折终身优惠(长期有效)一、ZJI官网点击直达ZJI官方网站二、特惠香港日本服务器香港大埔:http://hkdb.speedtest.zji.net/香港葵湾:http://hkkw.speedtest.zji.net/日本大阪:http://jpsk.speedtest.zji.net/日本大阪一型 ...

百星数据(60元/月,600元/年)日本/韩国/香港cn2 gia云服务器,2核2G/40G/5M带宽

百星数据(baixidc),2012年开始运作至今,主要提供境外自营云服务器和独立服务器出租业务,根据网络线路的不同划分为:美国cera 9929、美国cn2 gia、香港cn2 gia、韩国cn2 gia、日本cn2 gia等云服务器及物理服务器业务。目前,百星数据 推出的日本、韩国、香港cn2 gia云服务器,2核2G/40G/5M带宽低至60元/月,600元/年。百星数据优惠码:优惠码:30...

c md5为你推荐
cf蜗牛外挂我想让cf用什么外挂可以让号被封了要最快那种。最好永久封了最好316不锈钢和304哪个好保温杯不锈钢316和304哪个好传奇类手游哪个好传奇哪个版本比较好玩 最好玩的传奇手游排行榜江门旅游景点哪个好玩的地方江门有什么地方好玩的?小说软件哪个好用免费有什么好用的免费小说软件51空间登录51空间,怎么添加啊?怎么登陆?群空间登录怎样进入群空间yy空间登录怎么进入YY音乐空间google广告申请申请Google广告要多长时间呢东莞电信宽带在东莞报装办理电信宽带好不好用,需要多少钱,在哪里报装
新网域名管理 优惠码 外国域名 表格样式 免费ftp空间申请 日本bb瘦 idc资讯 国外免费asp空间 怎么建立邮箱 shuang12 vul 阿里云免费邮箱 西安主机 免费网络 双十二促销 register.com godaddy域名 瓦工工具 次世代主机 国外bt网站 更多