unsigned char buffer[1024], digest[16]; if ((file = fopen (filename, "rb")) == NULL) printf ("%s can't be opened\n", filename); else { MDInit (&context); while (len = fread (buffer, 1, 1024, file)) MDUpdate (&context, buffer, len); MDFinal (digest, &context); fclose (file); printf ("MD%d (%s) = ", MD, filename); MDPrint (digest); printf ("\n"); } } /* Digests the standard input and prints the result. */ static void MDFilter () { MD_CTX context; int len; unsigned char buffer[16], digest[16]; MDInit (&context); while (len = fread (buffer, 1, 16, stdin)) MDUpdate (&context, buffer, len); MDFinal (digest, &context); MDPrint (digest); printf ("\n"); } /* Prints a message digest in hexadecimal. */ static void MDPrint (digest) unsigned char digest[16]; { unsigned int i; for (i = 0; i < 16; i++) printf ("%02x", digest[i]); } A.5 Test suite The MD5 test suite (driver option "-x") should print the following results: MD5 test suite: MD5 ("") = d41d8cd98f00b204e9800998ecf8427e MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661 MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72 MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0 MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz0123456789") = d174ab98d277d9f5a5611c2c9f419d9f MD5 ("123456789012345678901234567890123456789012345678 901234567890123456 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a the_lighthouse(REA) MỘT CHƯƠNG TRÌNH MẪU TÍNH TÓAN MD5-HASHES TRONG ASM: BỘ CHƯƠNG TRÌNH NÀY TUI CÓ ĐÓNG GÓI TRONG TẬP TÀI LIỆU NÀY CÁC BẠN HẢY DÙNG MASM V7.0 TRỞ LÊN ĐỂ BIÊN DỊCH. Sau đây tui chỉ trình bày code của file chính: Bạn hảy tạo file ASMmd5hasher.asm như sau: .386 .model flat,stdcall DlgProc proto :dword,:dword,:dword,:dword FF proto :dword,:dword,:dword,:dword,:dword,:byte,:dword GG proto :dword,:dword,:dword,:dword,:dword,:byte,:dword HH proto :dword,:dword,:dword,:dword,:dword,:byte,:dword II proto :dword,:dword,:dword,:dword,:dword,:byte,:dword procMD5hash proto :dword,:dword,:dword include \masm32\include\gdi32.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc include \masm32\include\windows.inc includelib \masm32\lib\gdi32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib MD5RESULT STRUCT dtA dd ? dtB dd ? dtC dd ? dtD dd ? MD5RESULT ENDS .const IDC_ABOUT equ 101 IDC_EDITTEXT equ 102 IDC_EDITHASH equ 103 IDD_DIALOG equ 100 IDI_ICON equ 200 MAXSIZE equ 260 .data bfBuffer db MAXSIZE dup (0) szAboutCaption db 'about md5hasher',0 szAboutText db 'md5hasher',13,10,'by roy|crisiscrackers',0 szMD5Format db '%.8x%.8x%.8x%.8x',0 .data? hInstance HINSTANCE ? stMD5Result MD5RESULT <?> .code start: invoke GetModuleHandle,0 mov hInstance,eax invoke DialogBoxParam,hInstance,IDD_DIALOG,0,addr DlgProc,0 invoke ExitProcess,eax DlgProc proc uses ebx edi esi,hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARA M cmp uMsg,WM_INITDIALOG jz initdialog cmp uMsg,WM_CLOSE jz close cmp uMsg,WM_COMMAND jz command xor eax,eax ret endcheck: mov eax,1 ret command: mov eax,wParam mov edx,wParam shr edx,16 cmp edx,BN_CLICKED jnz @f cmp ax,IDC_ABOUT jnz endcheck invoke MessageBoxA,hWnd,addr szAboutText,addr szAboutCaption,MB_OK or MB_ICONASTERISK jmp endcheck @@: cmp edx,EN_CHANGE jnz endcheck cmp ax,IDC_EDITTEXT jnz endcheck invoke GetDlgItemText,hWnd,IDC_EDITTEXT,addr bfBuffer,MAXSIZE invoke procMD5hash,addr bfBuffer,eax,addr stMD5Result invoke SendDlgItemMessageA,hWnd,IDC_EDITHASH,WM_SETTEXT,0 ,addr bfBuffer jmp endcheck initdialog: invoke LoadIconA,hInstance,IDI_ICON invoke SendMessageA,hWnd,WM_SETICON,1,eax invoke SendDlgItemMessageA,hWnd,IDC_EDITTEXT,WM_SETTEXT,0 ,0 jmp endcheck close: invoke EndDialog,hWnd,0 jmp endcheck DlgProc endp procMD5hash proc uses eax ebx ecx edx edi esi,ptBuffer:dword,dtBufferLength:dword,ptMD5Resul t:dword local dta:dword,dtb:dword,dtc:dword,dtd:dword ; phase I · padding . = d174ab98d277d9f5a5 611 c2c9f 419 d9f MD5 (" ;12 3456789 01 2 3456789 01 2 3456789 01 2 3456789 01 2 345678 9 01 2 3456789 01 2 3456 789 01 2 345678 90& quot;) = 57edf4a22be3c955ac49da2e 2 10 7b67a the_lighthouse(REA). suite: MD5 ("") = d41d8cd98f00b 204 e9 800 998ecf8427e MD5 ("a") = 0cc175b9c0f1b6a831c399e2697726 61 MD5 ("abc") = 90 015 09 83cd24fb0d6963f7d28e17f72 MD5 ("message. .const IDC_ABOUT equ 10 1 IDC_EDITTEXT equ 10 2 IDC_EDITHASH equ 10 3 IDD_DIALOG equ 10 0 IDI_ICON equ 200 MAXSIZE equ 2 60 .data bfBuffer db MAXSIZE dup (0) szAboutCaption db 'about