tmdtest.pp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. {
  2. This file is part of the Free Pascal packages.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. Tests the MD5 program.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. program mdtest;
  12. {$h+}
  13. uses
  14. md5;
  15. var
  16. error: boolean;
  17. const
  18. Suite: array[1..7] of string = (
  19. '',
  20. 'a',
  21. 'abc',
  22. 'message digest',
  23. 'abcdefghijklmnopqrstuvwxyz',
  24. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
  25. '12345678901234567890123456789012345678901234567890123456789012345678901234567890'
  26. );
  27. Results: array[TMDVersion, Low(Suite)..High(Suite)] of string = (
  28. // MD_VERSION_2
  29. ('8350e5a3e24c153df2275c9f80692773',
  30. '32ec01ec4a6dac72c0ab96fb34c0b5d1',
  31. 'da853b0d3f88d99b30283a69e6ded6bb',
  32. 'ab4f496bfb2a530b219ff33031fe06b0',
  33. '4e8ddff3650292ab5a4108c3aa47940b',
  34. 'da33def2a42df13975352846c30338cd',
  35. 'd5976f79d83d3a0dc9806c3c66f3efd8'),
  36. // MD_VERSION_4
  37. ('31d6cfe0d16ae931b73c59d7e0c089c0',
  38. 'bde52cb31de33e46245e05fbdbd6fb24',
  39. 'a448017aaf21d8525fc10ae87aa6729d',
  40. 'd9130a8164549fe818874806e1c7014b',
  41. 'd79e1c308aa5bbcdeea8ed63df412da9',
  42. '043f8582f241db351ce627e153e7f0e4',
  43. 'e33b4ddc9c38f2199c3e7b164fcc0536'),
  44. // MD_VERSION_5
  45. ('d41d8cd98f00b204e9800998ecf8427e',
  46. '0cc175b9c0f1b6a831c399e269772661',
  47. '900150983cd24fb0d6963f7d28e17f72',
  48. 'f96b697d7cb7938d525a2f31aaf161d0',
  49. 'c3fcd3d76192e4007dfb496cca67e13b',
  50. 'd174ab98d277d9f5a5611c2c9f419d9f',
  51. '57edf4a22be3c955ac49da2e2107b67a')
  52. );
  53. procedure performTest(const Ver: TMDVersion);
  54. var
  55. I: Integer;
  56. S: String;
  57. begin
  58. for I := Low(Suite) to High(Suite) do
  59. begin
  60. S := LowerCase(MDPrint(MDString(Suite[I], Ver)));
  61. if S = Results[Ver, I] then
  62. Write('passed ')
  63. else
  64. begin
  65. error:=true;
  66. Write('failed ');
  67. end;
  68. WriteLn(' "', Suite[I], '" = ', S);
  69. end;
  70. end;
  71. begin
  72. error:=false;
  73. Writeln('Executing RFC 1319 test suite ...');
  74. performTest(MD_VERSION_2);
  75. Writeln;
  76. Writeln('Executing RFC 1320 test suite ...');
  77. performTest(MD_VERSION_4);
  78. Writeln;
  79. Writeln('Executing RFC 1321 test suite ...');
  80. performTest(MD_VERSION_5);
  81. Writeln;
  82. if (error) then
  83. halt(1);
  84. end.