MD5(2)

/* Round 4 */ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; /* Zeroize sensitive information. */ MD5_memset ((POINTER)x, 0, sizeof (x)); } /* Encodes input (UINT4) into output (unsigned char). Assumes len is a multiple of 4. */ void CSecurity::Encode( unsigned char *output, UINT4 *input, size_t len ) { size_t i, j; for (i = 0, j = 0; j < len; i++, j += 4) { output[j] = (unsigned char)(input & 0xff); output[j+1] = (unsigned char)((input >> 8) & 0xff); output[j+2] = (unsigned char)((input >> 16) & 0xff); output[j+3] = (unsigned char)((input >> 24) & 0xff); } } /* Decodes input (unsigned char) into output (UINT4). Assumes len is a multiple of 4. */ void CSecurity::Decode( UINT4 *output, unsigned char *input, size_t len ) { size_t i, j; for (i = 0, j = 0; j < len; i++, j += 4) output = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); } /* Note: Replace "for loop" with standard memcpy if possible. */ void CSecurity::MD5_memcpy( POINTER output, POINTER input, size_t len ) { size_t i; for (i = 0; i < len; i++) output = input; } /* Note: Replace "for loop" with standard memset if possible. */ void CSecurity::MD5_memset( POINTER output, int value, size_t len ) { size_t i; for (i = 0; i < len; i++) ((char *)output) = (char)value; } /* Digests a string and prints the result. */ void CSecurity::MD5( const char *string ,char *lpMD5StringBuffer ) { MD5_CTX context; unsigned char digest[16]; /*char output1[33]; */static char output[33]={""}; /*size_t*/size_t len = strlen (string); int i; MD5Init( &context); MD5Update( &context, (unsigned char*)string, len ); MD5Final( digest, &context ); for (i = 0; i < 16; i++) { sprintf(&(lpMD5StringBuffer[2*i]),"%02x",(unsigned char)digest); sprintf(&(lpMD5StringBuffer[2*i+1]),"%02x",(unsigned char)(digest<<4)); } for(i=0;i<32;i++) { output=lpMD5StringBuffer; } } /* get the string add one. */ void CSecurity::StringAddOne( char * orstring ) { size_t len; size_t i,n; len = strlen(orstring); n = len - 1; for(i = n; i >= 0; i--) { if(orstring=='9') { orstring = 'A'; break; } else if(orstring=='Z') { orstring='a'; break; } else if(orstring=='z') { orstring='0'; continue; } else orstring += 1; break; } } =============================stdafx.h=====================================// stdafx.h : 標準系統包含文件的包含文件,// 或是常用但不常更改的項目特定的包含文件//#pragma once//導出#define SECURITY_EXPORTS#define WIN32_LEAN_AND_MEAN // 從 Windows 頭中排除極少使用的資料// Windows 頭文件:#include // TODO: 在此處引用程序要求的附加頭文件============================stdafx.cpp========================================// stdafx.cpp : 只包括標準包含文件的源文件// Security.pch 將成爲預編譯頭// stdafx.obj 將包含預編譯類型信息#include "stdafx.h"// TODO: 在 STDAFX.H 中//引用任何所需的附加頭文件,而不是在此文件中引用=====================================================================以上程序使用命令:@cl /GD /LD Security.cpp stdafx.cpp 編譯即可
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章