md5test.c
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:1k
源码类别:

WEB邮件程序

开发平台:

C/C++

  1. /*
  2. ** Copyright 1998 - 2000 Double Precision, Inc.
  3. ** See COPYING for distribution information.
  4. */
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include "md5.h"
  8. int main()
  9. {
  10. static const char * const teststr[]={
  11. "",
  12. "a",
  13. "abc",
  14. "message digest",
  15. "abcdefghijklmnopqrstuvwxyz",
  16. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
  17. "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
  18. char *salts[4]={"abcdef","01234567","76543210","QWERTY"};
  19. char *passwds[4]={ "rosebud",
  20. "trust noone",
  21. "trust, but verify",
  22. "for the world is hollow, and I have touched the sky"};
  23. int i,j;
  24. printf("MD5 test suite:n");
  25. for (i=0; i<(int)sizeof(teststr)/sizeof(teststr[0]); i++)
  26. {
  27. MD5_DIGEST digest;
  28. md5_digest(teststr[i], strlen(teststr[i]), digest);
  29. printf("MD5 ("%s") = ", teststr[i]);
  30. for (j=0; j<sizeof(digest); j++)
  31. printf("%02x", digest[j]);
  32. printf("n");
  33. }
  34. for (i=0; i<sizeof(salts)/sizeof(salts[0]); i++)
  35. printf("Salt: %snPassword: %snHash:%snn",
  36. salts[i], passwds[i],
  37. md5_crypt_redhat(passwds[i], salts[i]));
  38. return (0);
  39. }