Tham khảo tài liệu 'hacker professional ebook part 142', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Arguments may be any combination -sstring - digests string -t - runs time trial -x - runs test script filename - digests file none - digests standard input int main argc argv int argc char argv int i if argc 1 for i 1 i argc i if argv i 0 - argv i 1 s MDString argv i 2 else if strcmp argv i -t 0 MDTimeTrial else if strcmp argv i -x 0 MDTestSuite else MDFile argv i else MDFilter return 0 Digests a string and prints the result. static void MDString string char string MD_CTX context unsigned char digest 16 unsigned int len strlen string MDInit context MDUpdate context string len MDFinal digest context printf MD d s MD string MDPrint digest printf n Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks. static void MDTimeTrial MD_CTX context time_t endTime startTime unsigned char block TEST_BLOCK_LEN digest 16 unsigned int i printf MD d time trial. Digesting d d-byte blocks . MD TEST_BLOCK_LEN TEST_BLOCK_COUNT Initialize block for i 0 i TEST_BLOCK_LEN i block i unsigned char i 0xff Start timer time startTime Digest blocks MDInit context for i 0 i TEST_BLOCK_COUNT i MDUpdate context block TEST_BLOCK_LEN MDFinal digest context Stop timer time endTime printf done n printf Digest MDPrint digest printf nTime ld seconds n long endTime-startTime printf Speed ld bytes second n long TEST_BLOCK_LEN long TEST_BLOCK_COUNT endTime-startTime Digests a reference suite of strings and prints the results. static void MDTestSuite printf MD d test suite n MD MDString MDString a MDString abc MDString message digest MDString abcdefghijklmnopqrstuvwxyz MDString ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz0123456789 MDString 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 Digests a file and prints the result. static void MDFile filename char filename FILE file MD_CTX context int len unsigned char buffer 1024 digest 16