中国安防论坛

 找回密码
 注册
查看: 4642|回复: 1

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
) `$ V, x5 S* m7 d1 i#include "md5.h"
Y+ N8 E; n/ D5 R- A V
: l6 E# ^1 e: ^/* Constants for MD5Transform routine.
*/
% a; T0 ?8 l2 j4 b, ^$ v$ w# J* ?
3 u' U3 `8 ~9 z
1 |. |* H3 _. u. X#define S11 7
( i, q+ M- _% L3 {+ q #define S12 12
" n, g. j, l! l9 ?5 ` #define S13 17
" x; i a! g0 h/ ^ #define S14 22
" g! u% q' P5 b* ?4 G6 ` #define S21 5
, I; {) H ^; ^, a, ^0 ? #define S22 9
4 n! |8 k# l4 \$ ~5 O#define S23 14
: r. s4 b( g9 p+ v) f7 t#define S24 20
4 ?8 P' t0 M# \4 M! t \ `$ Q #define S31 4
) R% T4 R1 r5 ~#define S32 11
8 v y) J) y& S* p: Z#define S33 16
5 L: P8 L& ~4 X2 z) J #define S34 23
' x8 U2 ]/ X5 v6 |8 Z1 T #define S41 6
* G7 K7 f, x. T: }2 X W#define S42 10
8 d+ V7 X3 [* Y. B* Y# a#define S43 15
0 Q/ |$ t6 F8 b3 m4 [ #define S44 21
' t" i% f; X! Y. C+ f
, O8 O" Q3 K2 l! _. Z: Rstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
. B& S- X3 E7 p/ p+ @8 a static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
8 D4 O: k! S7 j. j" w5 j+ q static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
* R1 G' v9 x" h; Fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
8 v' p& y( u: Y3 }6 C* l* Dstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
* \: h; C& F0 j
% R; Z2 w1 ?/ Y& R static unsigned char PADDING[64] = {
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
# W( ]" _& D. d, J: d+ q% L};
9 x4 h( o6 e# O% _' }* h3 h
/ q5 v5 S; |1 k/* F, G, H and I are basic MD5 functions.
*/
# ^/ P* d9 E& a- \#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
- L2 B/ f1 ~( I' \ #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
5 p! A8 m: c! e: R$ t6 O #define H(x, y, z) ((x) ^ (y) ^ (z))
$ `2 b. \$ j6 N& m. f5 L6 W+ x#define I(x, y, z) ((y) ^ ((x) | (~z)))
: ]% ]+ i$ j2 v
4 K8 |# w, K* Z- Y! p/* ROTATE_LEFT rotates x left n bits.
*/
) j u2 a& a6 M* D, ^# I! W#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
) A- `2 R# Y% }2 y
3 h" G0 v/ m* i$ c* v0 X/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ f) z- K1 u) Q2 Q# HRotation is separate from addition to prevent recomputation.
*/
- s* R% N/ @3 q# l0 j; a1 ]& q #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 \; X8 R! d6 B" T#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, ^6 v) D U& p k8 C& x #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% M# e" T' Q5 W1 G4 r #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
5 A, T3 k. I* T$ m
* s7 f* i) m7 v+ C/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
' c& m! y) r' i {# `2 y8 { void MD5Init (context)
% G: K: f! l- c2 e5 C+ ^ MD5_CTX *context; /* context */
) i2 b# C& Q8 i$ X+ s {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
0 l Q. p" h& S c*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
5 A, ]; t! x9 [2 q }
, _& v- y& T M
" D! R( y7 _. D% Z /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
+ p* k. V) X& S1 q/ |, Qvoid MD5Update (context, input, inputLen)
' ~( l( b9 d/ }+ \% C5 m. BMD5_CTX *context; /* context */
! N( h% }& s, n! e* runsigned char *input; /* input block */
5 o% h2 W. |; H% a, y$ ^0 B( D unsigned int inputLen; /* length of input block */
& x3 }& _) q3 \# ]7 t. r% W {
unsigned int i, index, partLen;
2 ^8 @4 E+ _# G; `* i
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
0 B) B' c0 e3 v# ] x
/* Update number of bits */
if ((context->count[0] += ((UINT4)inputLen << 3))
&
不在競爭中變坏,就在沉默中變態

安防知名大师

探花

Rank: 7Rank: 7Rank: 7

积分
1057
QQ
发表于 2004-11-26 20:22:48 | 显示全部楼层

md5加密算法C++程序


: f0 F: i" m3 {( Y/ R
/ Z2 |6 `, D: x3 r1 F" k7 k8 ]
guoyun786@sohu.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

安豆网|Archiver|手机版|中国安防论坛 ( 粤ICP备09063021号 )

GMT+8, 2025-2-19 06:52 , Processed in 0.080589 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表