Программа для прослушивания журнала АРК Томск http://blindage.org/?p=6627
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

synacode.pas 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. {==============================================================================|
  2. | Project : Ararat Synapse | 002.002.001 |
  3. |==============================================================================|
  4. | Content: Coding and decoding support |
  5. |==============================================================================|
  6. | Copyright (c)1999-2012, Lukas Gebauer |
  7. | All rights reserved. |
  8. | |
  9. | Redistribution and use in source and binary forms, with or without |
  10. | modification, are permitted provided that the following conditions are met: |
  11. | |
  12. | Redistributions of source code must retain the above copyright notice, this |
  13. | list of conditions and the following disclaimer. |
  14. | |
  15. | Redistributions in binary form must reproduce the above copyright notice, |
  16. | this list of conditions and the following disclaimer in the documentation |
  17. | and/or other materials provided with the distribution. |
  18. | |
  19. | Neither the name of Lukas Gebauer nor the names of its contributors may |
  20. | be used to endorse or promote products derived from this software without |
  21. | specific prior written permission. |
  22. | |
  23. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
  24. | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
  25. | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
  26. | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
  27. | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
  28. | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
  29. | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
  30. | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  31. | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
  32. | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
  33. | DAMAGE. |
  34. |==============================================================================|
  35. | The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
  36. | Portions created by Lukas Gebauer are Copyright (c)2000-2012. |
  37. | All Rights Reserved. |
  38. |==============================================================================|
  39. | Contributor(s): |
  40. |==============================================================================|
  41. | History: see HISTORY.HTM from distribution package |
  42. | (Found at URL: http://www.ararat.cz/synapse/) |
  43. |==============================================================================}
  44. {:@abstract(Various encoding and decoding support)}
  45. {$IFDEF FPC}
  46. {$MODE DELPHI}
  47. {$ENDIF}
  48. {$Q-}
  49. {$R-}
  50. {$H+}
  51. {$TYPEDADDRESS OFF}
  52. {$IFDEF UNICODE}
  53. {$WARN IMPLICIT_STRING_CAST OFF}
  54. {$WARN IMPLICIT_STRING_CAST_LOSS OFF}
  55. {$WARN SUSPICIOUS_TYPECAST OFF}
  56. {$ENDIF}
  57. unit synacode;
  58. interface
  59. uses
  60. SysUtils;
  61. type
  62. TSpecials = set of AnsiChar;
  63. const
  64. SpecialChar: TSpecials =
  65. ['=', '(', ')', '[', ']', '<', '>', ':', ';', ',', '@', '/', '?', '\',
  66. '"', '_'];
  67. NonAsciiChar: TSpecials =
  68. [#0..#31, #127..#255];
  69. URLFullSpecialChar: TSpecials =
  70. [';', '/', '?', ':', '@', '=', '&', '#', '+'];
  71. URLSpecialChar: TSpecials =
  72. [#$00..#$20, '_', '<', '>', '"', '%', '{', '}', '|', '\', '^', '~', '[', ']',
  73. '`', #$7F..#$FF];
  74. TableBase64 =
  75. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  76. TableBase64mod =
  77. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,=';
  78. TableUU =
  79. '`!"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_';
  80. TableXX =
  81. '+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  82. ReTablebase64 =
  83. #$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$3E +#$40
  84. +#$40 +#$40 +#$3F +#$34 +#$35 +#$36 +#$37 +#$38 +#$39 +#$3A +#$3B +#$3C
  85. +#$3D +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$00 +#$01 +#$02 +#$03
  86. +#$04 +#$05 +#$06 +#$07 +#$08 +#$09 +#$0A +#$0B +#$0C +#$0D +#$0E +#$0F
  87. +#$10 +#$11 +#$12 +#$13 +#$14 +#$15 +#$16 +#$17 +#$18 +#$19 +#$40 +#$40
  88. +#$40 +#$40 +#$40 +#$40 +#$1A +#$1B +#$1C +#$1D +#$1E +#$1F +#$20 +#$21
  89. +#$22 +#$23 +#$24 +#$25 +#$26 +#$27 +#$28 +#$29 +#$2A +#$2B +#$2C +#$2D
  90. +#$2E +#$2F +#$30 +#$31 +#$32 +#$33 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40;
  91. ReTableUU =
  92. #$01 +#$02 +#$03 +#$04 +#$05 +#$06 +#$07 +#$08 +#$09 +#$0A +#$0B +#$0C
  93. +#$0D +#$0E +#$0F +#$10 +#$11 +#$12 +#$13 +#$14 +#$15 +#$16 +#$17 +#$18
  94. +#$19 +#$1A +#$1B +#$1C +#$1D +#$1E +#$1F +#$20 +#$21 +#$22 +#$23 +#$24
  95. +#$25 +#$26 +#$27 +#$28 +#$29 +#$2A +#$2B +#$2C +#$2D +#$2E +#$2F +#$30
  96. +#$31 +#$32 +#$33 +#$34 +#$35 +#$36 +#$37 +#$38 +#$39 +#$3A +#$3B +#$3C
  97. +#$3D +#$3E +#$3F +#$00 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40
  98. +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40
  99. +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40;
  100. ReTableXX =
  101. #$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$00 +#$40
  102. +#$01 +#$40 +#$40 +#$02 +#$03 +#$04 +#$05 +#$06 +#$07 +#$08 +#$09 +#$0A
  103. +#$0B +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$0C +#$0D +#$0E +#$0F
  104. +#$10 +#$11 +#$12 +#$13 +#$14 +#$15 +#$16 +#$17 +#$18 +#$19 +#$1A +#$1B
  105. +#$1C +#$1D +#$1E +#$1F +#$20 +#$21 +#$22 +#$23 +#$24 +#$25 +#$40 +#$40
  106. +#$40 +#$40 +#$40 +#$40 +#$26 +#$27 +#$28 +#$29 +#$2A +#$2B +#$2C +#$2D
  107. +#$2E +#$2F +#$30 +#$31 +#$32 +#$33 +#$34 +#$35 +#$36 +#$37 +#$38 +#$39
  108. +#$3A +#$3B +#$3C +#$3D +#$3E +#$3F +#$40 +#$40 +#$40 +#$40 +#$40 +#$40;
  109. {:Decodes triplet encoding with a given character delimiter. It is used for
  110. decoding quoted-printable or URL encoding.}
  111. function DecodeTriplet(const Value: AnsiString; Delimiter: AnsiChar): AnsiString;
  112. {:Decodes a string from quoted printable form. (also decodes triplet sequences
  113. like '=7F')}
  114. function DecodeQuotedPrintable(const Value: AnsiString): AnsiString;
  115. {:Decodes a string of URL encoding. (also decodes triplet sequences like '%7F')}
  116. function DecodeURL(const Value: AnsiString): AnsiString;
  117. {:Performs triplet encoding with a given character delimiter. Used for encoding
  118. quoted-printable or URL encoding.}
  119. function EncodeTriplet(const Value: AnsiString; Delimiter: AnsiChar;
  120. Specials: TSpecials): AnsiString;
  121. {:Encodes a string to triplet quoted printable form. All @link(NonAsciiChar)
  122. are encoded.}
  123. function EncodeQuotedPrintable(const Value: AnsiString): AnsiString;
  124. {:Encodes a string to triplet quoted printable form. All @link(NonAsciiChar) and
  125. @link(SpecialChar) are encoded.}
  126. function EncodeSafeQuotedPrintable(const Value: AnsiString): AnsiString;
  127. {:Encodes a string to URL format. Used for encoding data from a form field in
  128. HTTP, etc. (Encodes all critical characters including characters used as URL
  129. delimiters ('/',':', etc.)}
  130. function EncodeURLElement(const Value: AnsiString): AnsiString;
  131. {:Encodes a string to URL format. Used to encode critical characters in all
  132. URLs.}
  133. function EncodeURL(const Value: AnsiString): AnsiString;
  134. {:Decode 4to3 encoding with given table. If some element is not found in table,
  135. first item from table is used. This is good for buggy coded items by Microsoft
  136. Outlook. This software sometimes using wrong table for UUcode, where is used
  137. ' ' instead '`'.}
  138. function Decode4to3(const Value, Table: AnsiString): AnsiString;
  139. {:Decode 4to3 encoding with given REVERSE table. Using this function with
  140. reverse table is much faster then @link(Decode4to3). This function is used
  141. internally for Base64, UU or XX decoding.}
  142. function Decode4to3Ex(const Value, Table: AnsiString): AnsiString;
  143. {:Encode by system 3to4 (used by Base64, UU coding, etc) by given table.}
  144. function Encode3to4(const Value, Table: AnsiString): AnsiString;
  145. {:Decode string from base64 format.}
  146. function DecodeBase64(const Value: AnsiString): AnsiString;
  147. {:Encodes a string to base64 format.}
  148. function EncodeBase64(const Value: AnsiString): AnsiString;
  149. {:Decode string from modified base64 format. (used in IMAP, for example.)}
  150. function DecodeBase64mod(const Value: AnsiString): AnsiString;
  151. {:Encodes a string to modified base64 format. (used in IMAP, for example.)}
  152. function EncodeBase64mod(const Value: AnsiString): AnsiString;
  153. {:Decodes a string from UUcode format.}
  154. function DecodeUU(const Value: AnsiString): AnsiString;
  155. {:encode UUcode. it encode only datas, you must also add header and footer for
  156. proper encode.}
  157. function EncodeUU(const Value: AnsiString): AnsiString;
  158. {:Decodes a string from XXcode format.}
  159. function DecodeXX(const Value: AnsiString): AnsiString;
  160. {:decode line with Yenc code. This code is sometimes used in newsgroups.}
  161. function DecodeYEnc(const Value: AnsiString): AnsiString;
  162. {:Returns a new CRC32 value after adding a new byte of data.}
  163. function UpdateCrc32(Value: Byte; Crc32: Integer): Integer;
  164. {:return CRC32 from a value string.}
  165. function Crc32(const Value: AnsiString): Integer;
  166. {:Returns a new CRC16 value after adding a new byte of data.}
  167. function UpdateCrc16(Value: Byte; Crc16: Word): Word;
  168. {:return CRC16 from a value string.}
  169. function Crc16(const Value: AnsiString): Word;
  170. {:Returns a binary string with a RSA-MD5 hashing of "Value" string.}
  171. function MD5(const Value: AnsiString): AnsiString;
  172. {:Returns a binary string with HMAC-MD5 hash.}
  173. function HMAC_MD5(Text, Key: AnsiString): AnsiString;
  174. {:Returns a binary string with a RSA-MD5 hashing of string what is constructed
  175. by repeating "value" until length is "Len".}
  176. function MD5LongHash(const Value: AnsiString; Len: integer): AnsiString;
  177. {:Returns a binary string with a SHA-1 hashing of "Value" string.}
  178. function SHA1(const Value: AnsiString): AnsiString;
  179. {:Returns a binary string with HMAC-SHA1 hash.}
  180. function HMAC_SHA1(Text, Key: AnsiString): AnsiString;
  181. {:Returns a binary string with a SHA-1 hashing of string what is constructed
  182. by repeating "value" until length is "Len".}
  183. function SHA1LongHash(const Value: AnsiString; Len: integer): AnsiString;
  184. {:Returns a binary string with a RSA-MD4 hashing of "Value" string.}
  185. function MD4(const Value: AnsiString): AnsiString;
  186. implementation
  187. const
  188. Crc32Tab: array[0..255] of Integer = (
  189. Integer($00000000), Integer($77073096), Integer($EE0E612C), Integer($990951BA),
  190. Integer($076DC419), Integer($706AF48F), Integer($E963A535), Integer($9E6495A3),
  191. Integer($0EDB8832), Integer($79DCB8A4), Integer($E0D5E91E), Integer($97D2D988),
  192. Integer($09B64C2B), Integer($7EB17CBD), Integer($E7B82D07), Integer($90BF1D91),
  193. Integer($1DB71064), Integer($6AB020F2), Integer($F3B97148), Integer($84BE41DE),
  194. Integer($1ADAD47D), Integer($6DDDE4EB), Integer($F4D4B551), Integer($83D385C7),
  195. Integer($136C9856), Integer($646BA8C0), Integer($FD62F97A), Integer($8A65C9EC),
  196. Integer($14015C4F), Integer($63066CD9), Integer($FA0F3D63), Integer($8D080DF5),
  197. Integer($3B6E20C8), Integer($4C69105E), Integer($D56041E4), Integer($A2677172),
  198. Integer($3C03E4D1), Integer($4B04D447), Integer($D20D85FD), Integer($A50AB56B),
  199. Integer($35B5A8FA), Integer($42B2986C), Integer($DBBBC9D6), Integer($ACBCF940),
  200. Integer($32D86CE3), Integer($45DF5C75), Integer($DCD60DCF), Integer($ABD13D59),
  201. Integer($26D930AC), Integer($51DE003A), Integer($C8D75180), Integer($BFD06116),
  202. Integer($21B4F4B5), Integer($56B3C423), Integer($CFBA9599), Integer($B8BDA50F),
  203. Integer($2802B89E), Integer($5F058808), Integer($C60CD9B2), Integer($B10BE924),
  204. Integer($2F6F7C87), Integer($58684C11), Integer($C1611DAB), Integer($B6662D3D),
  205. Integer($76DC4190), Integer($01DB7106), Integer($98D220BC), Integer($EFD5102A),
  206. Integer($71B18589), Integer($06B6B51F), Integer($9FBFE4A5), Integer($E8B8D433),
  207. Integer($7807C9A2), Integer($0F00F934), Integer($9609A88E), Integer($E10E9818),
  208. Integer($7F6A0DBB), Integer($086D3D2D), Integer($91646C97), Integer($E6635C01),
  209. Integer($6B6B51F4), Integer($1C6C6162), Integer($856530D8), Integer($F262004E),
  210. Integer($6C0695ED), Integer($1B01A57B), Integer($8208F4C1), Integer($F50FC457),
  211. Integer($65B0D9C6), Integer($12B7E950), Integer($8BBEB8EA), Integer($FCB9887C),
  212. Integer($62DD1DDF), Integer($15DA2D49), Integer($8CD37CF3), Integer($FBD44C65),
  213. Integer($4DB26158), Integer($3AB551CE), Integer($A3BC0074), Integer($D4BB30E2),
  214. Integer($4ADFA541), Integer($3DD895D7), Integer($A4D1C46D), Integer($D3D6F4FB),
  215. Integer($4369E96A), Integer($346ED9FC), Integer($AD678846), Integer($DA60B8D0),
  216. Integer($44042D73), Integer($33031DE5), Integer($AA0A4C5F), Integer($DD0D7CC9),
  217. Integer($5005713C), Integer($270241AA), Integer($BE0B1010), Integer($C90C2086),
  218. Integer($5768B525), Integer($206F85B3), Integer($B966D409), Integer($CE61E49F),
  219. Integer($5EDEF90E), Integer($29D9C998), Integer($B0D09822), Integer($C7D7A8B4),
  220. Integer($59B33D17), Integer($2EB40D81), Integer($B7BD5C3B), Integer($C0BA6CAD),
  221. Integer($EDB88320), Integer($9ABFB3B6), Integer($03B6E20C), Integer($74B1D29A),
  222. Integer($EAD54739), Integer($9DD277AF), Integer($04DB2615), Integer($73DC1683),
  223. Integer($E3630B12), Integer($94643B84), Integer($0D6D6A3E), Integer($7A6A5AA8),
  224. Integer($E40ECF0B), Integer($9309FF9D), Integer($0A00AE27), Integer($7D079EB1),
  225. Integer($F00F9344), Integer($8708A3D2), Integer($1E01F268), Integer($6906C2FE),
  226. Integer($F762575D), Integer($806567CB), Integer($196C3671), Integer($6E6B06E7),
  227. Integer($FED41B76), Integer($89D32BE0), Integer($10DA7A5A), Integer($67DD4ACC),
  228. Integer($F9B9DF6F), Integer($8EBEEFF9), Integer($17B7BE43), Integer($60B08ED5),
  229. Integer($D6D6A3E8), Integer($A1D1937E), Integer($38D8C2C4), Integer($4FDFF252),
  230. Integer($D1BB67F1), Integer($A6BC5767), Integer($3FB506DD), Integer($48B2364B),
  231. Integer($D80D2BDA), Integer($AF0A1B4C), Integer($36034AF6), Integer($41047A60),
  232. Integer($DF60EFC3), Integer($A867DF55), Integer($316E8EEF), Integer($4669BE79),
  233. Integer($CB61B38C), Integer($BC66831A), Integer($256FD2A0), Integer($5268E236),
  234. Integer($CC0C7795), Integer($BB0B4703), Integer($220216B9), Integer($5505262F),
  235. Integer($C5BA3BBE), Integer($B2BD0B28), Integer($2BB45A92), Integer($5CB36A04),
  236. Integer($C2D7FFA7), Integer($B5D0CF31), Integer($2CD99E8B), Integer($5BDEAE1D),
  237. Integer($9B64C2B0), Integer($EC63F226), Integer($756AA39C), Integer($026D930A),
  238. Integer($9C0906A9), Integer($EB0E363F), Integer($72076785), Integer($05005713),
  239. Integer($95BF4A82), Integer($E2B87A14), Integer($7BB12BAE), Integer($0CB61B38),
  240. Integer($92D28E9B), Integer($E5D5BE0D), Integer($7CDCEFB7), Integer($0BDBDF21),
  241. Integer($86D3D2D4), Integer($F1D4E242), Integer($68DDB3F8), Integer($1FDA836E),
  242. Integer($81BE16CD), Integer($F6B9265B), Integer($6FB077E1), Integer($18B74777),
  243. Integer($88085AE6), Integer($FF0F6A70), Integer($66063BCA), Integer($11010B5C),
  244. Integer($8F659EFF), Integer($F862AE69), Integer($616BFFD3), Integer($166CCF45),
  245. Integer($A00AE278), Integer($D70DD2EE), Integer($4E048354), Integer($3903B3C2),
  246. Integer($A7672661), Integer($D06016F7), Integer($4969474D), Integer($3E6E77DB),
  247. Integer($AED16A4A), Integer($D9D65ADC), Integer($40DF0B66), Integer($37D83BF0),
  248. Integer($A9BCAE53), Integer($DEBB9EC5), Integer($47B2CF7F), Integer($30B5FFE9),
  249. Integer($BDBDF21C), Integer($CABAC28A), Integer($53B39330), Integer($24B4A3A6),
  250. Integer($BAD03605), Integer($CDD70693), Integer($54DE5729), Integer($23D967BF),
  251. Integer($B3667A2E), Integer($C4614AB8), Integer($5D681B02), Integer($2A6F2B94),
  252. Integer($B40BBE37), Integer($C30C8EA1), Integer($5A05DF1B), Integer($2D02EF8D)
  253. );
  254. Crc16Tab: array[0..255] of Word = (
  255. $0000, $1189, $2312, $329B, $4624, $57AD, $6536, $74BF,
  256. $8C48, $9DC1, $AF5A, $BED3, $CA6C, $DBE5, $E97E, $F8F7,
  257. $1081, $0108, $3393, $221A, $56A5, $472C, $75B7, $643E,
  258. $9CC9, $8D40, $BFDB, $AE52, $DAED, $CB64, $F9FF, $E876,
  259. $2102, $308B, $0210, $1399, $6726, $76AF, $4434, $55BD,
  260. $AD4A, $BCC3, $8E58, $9FD1, $EB6E, $FAE7, $C87C, $D9F5,
  261. $3183, $200A, $1291, $0318, $77A7, $662E, $54B5, $453C,
  262. $BDCB, $AC42, $9ED9, $8F50, $FBEF, $EA66, $D8FD, $C974,
  263. $4204, $538D, $6116, $709F, $0420, $15A9, $2732, $36BB,
  264. $CE4C, $DFC5, $ED5E, $FCD7, $8868, $99E1, $AB7A, $BAF3,
  265. $5285, $430C, $7197, $601E, $14A1, $0528, $37B3, $263A,
  266. $DECD, $CF44, $FDDF, $EC56, $98E9, $8960, $BBFB, $AA72,
  267. $6306, $728F, $4014, $519D, $2522, $34AB, $0630, $17B9,
  268. $EF4E, $FEC7, $CC5C, $DDD5, $A96A, $B8E3, $8A78, $9BF1,
  269. $7387, $620E, $5095, $411C, $35A3, $242A, $16B1, $0738,
  270. $FFCF, $EE46, $DCDD, $CD54, $B9EB, $A862, $9AF9, $8B70,
  271. $8408, $9581, $A71A, $B693, $C22C, $D3A5, $E13E, $F0B7,
  272. $0840, $19C9, $2B52, $3ADB, $4E64, $5FED, $6D76, $7CFF,
  273. $9489, $8500, $B79B, $A612, $D2AD, $C324, $F1BF, $E036,
  274. $18C1, $0948, $3BD3, $2A5A, $5EE5, $4F6C, $7DF7, $6C7E,
  275. $A50A, $B483, $8618, $9791, $E32E, $F2A7, $C03C, $D1B5,
  276. $2942, $38CB, $0A50, $1BD9, $6F66, $7EEF, $4C74, $5DFD,
  277. $B58B, $A402, $9699, $8710, $F3AF, $E226, $D0BD, $C134,
  278. $39C3, $284A, $1AD1, $0B58, $7FE7, $6E6E, $5CF5, $4D7C,
  279. $C60C, $D785, $E51E, $F497, $8028, $91A1, $A33A, $B2B3,
  280. $4A44, $5BCD, $6956, $78DF, $0C60, $1DE9, $2F72, $3EFB,
  281. $D68D, $C704, $F59F, $E416, $90A9, $8120, $B3BB, $A232,
  282. $5AC5, $4B4C, $79D7, $685E, $1CE1, $0D68, $3FF3, $2E7A,
  283. $E70E, $F687, $C41C, $D595, $A12A, $B0A3, $8238, $93B1,
  284. $6B46, $7ACF, $4854, $59DD, $2D62, $3CEB, $0E70, $1FF9,
  285. $F78F, $E606, $D49D, $C514, $B1AB, $A022, $92B9, $8330,
  286. $7BC7, $6A4E, $58D5, $495C, $3DE3, $2C6A, $1EF1, $0F78
  287. );
  288. procedure ArrByteToLong(var ArByte: Array of byte; var ArLong: Array of Integer);
  289. {$IFDEF CIL}
  290. var
  291. n: integer;
  292. {$ENDIF}
  293. begin
  294. if (High(ArByte) + 1) > ((High(ArLong) + 1) * 4) then
  295. Exit;
  296. {$IFDEF CIL}
  297. for n := 0 to ((high(ArByte) + 1) div 4) - 1 do
  298. ArLong[n] := ArByte[n * 4 + 0]
  299. + (ArByte[n * 4 + 1] shl 8)
  300. + (ArByte[n * 4 + 2] shl 16)
  301. + (ArByte[n * 4 + 3] shl 24);
  302. {$ELSE}
  303. Move(ArByte[0], ArLong[0], High(ArByte) + 1);
  304. {$ENDIF}
  305. end;
  306. procedure ArrLongToByte(var ArLong: Array of Integer; var ArByte: Array of byte);
  307. {$IFDEF CIL}
  308. var
  309. n: integer;
  310. {$ENDIF}
  311. begin
  312. if (High(ArByte) + 1) < ((High(ArLong) + 1) * 4) then
  313. Exit;
  314. {$IFDEF CIL}
  315. for n := 0 to high(ArLong) do
  316. begin
  317. ArByte[n * 4 + 0] := ArLong[n] and $000000FF;
  318. ArByte[n * 4 + 1] := (ArLong[n] shr 8) and $000000FF;
  319. ArByte[n * 4 + 2] := (ArLong[n] shr 16) and $000000FF;
  320. ArByte[n * 4 + 3] := (ArLong[n] shr 24) and $000000FF;
  321. end;
  322. {$ELSE}
  323. Move(ArLong[0], ArByte[0], High(ArByte) + 1);
  324. {$ENDIF}
  325. end;
  326. type
  327. TMDCtx = record
  328. State: array[0..3] of Integer;
  329. Count: array[0..1] of Integer;
  330. BufAnsiChar: array[0..63] of Byte;
  331. BufLong: array[0..15] of Integer;
  332. end;
  333. TSHA1Ctx= record
  334. Hi, Lo: integer;
  335. Buffer: array[0..63] of byte;
  336. Index: integer;
  337. Hash: array[0..4] of Integer;
  338. HashByte: array[0..19] of byte;
  339. end;
  340. TMDTransform = procedure(var Buf: array of LongInt; const Data: array of LongInt);
  341. {==============================================================================}
  342. function DecodeTriplet(const Value: AnsiString; Delimiter: AnsiChar): AnsiString;
  343. var
  344. x, l, lv: Integer;
  345. c: AnsiChar;
  346. b: Byte;
  347. bad: Boolean;
  348. begin
  349. lv := Length(Value);
  350. SetLength(Result, lv);
  351. x := 1;
  352. l := 1;
  353. while x <= lv do
  354. begin
  355. c := Value[x];
  356. Inc(x);
  357. if c <> Delimiter then
  358. begin
  359. Result[l] := c;
  360. Inc(l);
  361. end
  362. else
  363. if x < lv then
  364. begin
  365. Case Value[x] Of
  366. #13:
  367. if (Value[x + 1] = #10) then
  368. Inc(x, 2)
  369. else
  370. Inc(x);
  371. #10:
  372. if (Value[x + 1] = #13) then
  373. Inc(x, 2)
  374. else
  375. Inc(x);
  376. else
  377. begin
  378. bad := False;
  379. Case Value[x] Of
  380. '0'..'9': b := (Byte(Value[x]) - 48) Shl 4;
  381. 'a'..'f', 'A'..'F': b := ((Byte(Value[x]) And 7) + 9) shl 4;
  382. else
  383. begin
  384. b := 0;
  385. bad := True;
  386. end;
  387. end;
  388. Case Value[x + 1] Of
  389. '0'..'9': b := b Or (Byte(Value[x + 1]) - 48);
  390. 'a'..'f', 'A'..'F': b := b Or ((Byte(Value[x + 1]) And 7) + 9);
  391. else
  392. bad := True;
  393. end;
  394. if bad then
  395. begin
  396. Result[l] := c;
  397. Inc(l);
  398. end
  399. else
  400. begin
  401. Inc(x, 2);
  402. Result[l] := AnsiChar(b);
  403. Inc(l);
  404. end;
  405. end;
  406. end;
  407. end
  408. else
  409. break;
  410. end;
  411. Dec(l);
  412. SetLength(Result, l);
  413. end;
  414. {==============================================================================}
  415. function DecodeQuotedPrintable(const Value: AnsiString): AnsiString;
  416. begin
  417. Result := DecodeTriplet(Value, '=');
  418. end;
  419. {==============================================================================}
  420. function DecodeURL(const Value: AnsiString): AnsiString;
  421. begin
  422. Result := DecodeTriplet(Value, '%');
  423. end;
  424. {==============================================================================}
  425. function EncodeTriplet(const Value: AnsiString; Delimiter: AnsiChar;
  426. Specials: TSpecials): AnsiString;
  427. var
  428. n, l: Integer;
  429. s: AnsiString;
  430. c: AnsiChar;
  431. begin
  432. SetLength(Result, Length(Value) * 3);
  433. l := 1;
  434. for n := 1 to Length(Value) do
  435. begin
  436. c := Value[n];
  437. if c in Specials then
  438. begin
  439. Result[l] := Delimiter;
  440. Inc(l);
  441. s := IntToHex(Ord(c), 2);
  442. Result[l] := s[1];
  443. Inc(l);
  444. Result[l] := s[2];
  445. Inc(l);
  446. end
  447. else
  448. begin
  449. Result[l] := c;
  450. Inc(l);
  451. end;
  452. end;
  453. Dec(l);
  454. SetLength(Result, l);
  455. end;
  456. {==============================================================================}
  457. function EncodeQuotedPrintable(const Value: AnsiString): AnsiString;
  458. begin
  459. Result := EncodeTriplet(Value, '=', ['='] + NonAsciiChar);
  460. end;
  461. {==============================================================================}
  462. function EncodeSafeQuotedPrintable(const Value: AnsiString): AnsiString;
  463. begin
  464. Result := EncodeTriplet(Value, '=', SpecialChar + NonAsciiChar);
  465. end;
  466. {==============================================================================}
  467. function EncodeURLElement(const Value: AnsiString): AnsiString;
  468. begin
  469. Result := EncodeTriplet(Value, '%', URLSpecialChar + URLFullSpecialChar);
  470. end;
  471. {==============================================================================}
  472. function EncodeURL(const Value: AnsiString): AnsiString;
  473. begin
  474. Result := EncodeTriplet(Value, '%', URLSpecialChar);
  475. end;
  476. {==============================================================================}
  477. function Decode4to3(const Value, Table: AnsiString): AnsiString;
  478. var
  479. x, y, n, l: Integer;
  480. d: array[0..3] of Byte;
  481. begin
  482. SetLength(Result, Length(Value));
  483. x := 1;
  484. l := 1;
  485. while x <= Length(Value) do
  486. begin
  487. for n := 0 to 3 do
  488. begin
  489. if x > Length(Value) then
  490. d[n] := 64
  491. else
  492. begin
  493. y := Pos(Value[x], Table);
  494. if y < 1 then
  495. y := 1;
  496. d[n] := y - 1;
  497. end;
  498. Inc(x);
  499. end;
  500. Result[l] := AnsiChar((D[0] and $3F) shl 2 + (D[1] and $30) shr 4);
  501. Inc(l);
  502. if d[2] <> 64 then
  503. begin
  504. Result[l] := AnsiChar((D[1] and $0F) shl 4 + (D[2] and $3C) shr 2);
  505. Inc(l);
  506. if d[3] <> 64 then
  507. begin
  508. Result[l] := AnsiChar((D[2] and $03) shl 6 + (D[3] and $3F));
  509. Inc(l);
  510. end;
  511. end;
  512. end;
  513. Dec(l);
  514. SetLength(Result, l);
  515. end;
  516. {==============================================================================}
  517. function Decode4to3Ex(const Value, Table: AnsiString): AnsiString;
  518. var
  519. x, y, lv: Integer;
  520. d: integer;
  521. dl: integer;
  522. c: byte;
  523. p: integer;
  524. begin
  525. lv := Length(Value);
  526. SetLength(Result, lv);
  527. x := 1;
  528. dl := 4;
  529. d := 0;
  530. p := 1;
  531. while x <= lv do
  532. begin
  533. y := Ord(Value[x]);
  534. if y in [33..127] then
  535. c := Ord(Table[y - 32])
  536. else
  537. c := 64;
  538. Inc(x);
  539. if c > 63 then
  540. continue;
  541. d := (d shl 6) or c;
  542. dec(dl);
  543. if dl <> 0 then
  544. continue;
  545. Result[p] := AnsiChar((d shr 16) and $ff);
  546. inc(p);
  547. Result[p] := AnsiChar((d shr 8) and $ff);
  548. inc(p);
  549. Result[p] := AnsiChar(d and $ff);
  550. inc(p);
  551. d := 0;
  552. dl := 4;
  553. end;
  554. case dl of
  555. 1:
  556. begin
  557. d := d shr 2;
  558. Result[p] := AnsiChar((d shr 8) and $ff);
  559. inc(p);
  560. Result[p] := AnsiChar(d and $ff);
  561. inc(p);
  562. end;
  563. 2:
  564. begin
  565. d := d shr 4;
  566. Result[p] := AnsiChar(d and $ff);
  567. inc(p);
  568. end;
  569. end;
  570. SetLength(Result, p - 1);
  571. end;
  572. {==============================================================================}
  573. function Encode3to4(const Value, Table: AnsiString): AnsiString;
  574. var
  575. c: Byte;
  576. n, l: Integer;
  577. Count: Integer;
  578. DOut: array[0..3] of Byte;
  579. begin
  580. setlength(Result, ((Length(Value) + 2) div 3) * 4);
  581. l := 1;
  582. Count := 1;
  583. while Count <= Length(Value) do
  584. begin
  585. c := Ord(Value[Count]);
  586. Inc(Count);
  587. DOut[0] := (c and $FC) shr 2;
  588. DOut[1] := (c and $03) shl 4;
  589. if Count <= Length(Value) then
  590. begin
  591. c := Ord(Value[Count]);
  592. Inc(Count);
  593. DOut[1] := DOut[1] + (c and $F0) shr 4;
  594. DOut[2] := (c and $0F) shl 2;
  595. if Count <= Length(Value) then
  596. begin
  597. c := Ord(Value[Count]);
  598. Inc(Count);
  599. DOut[2] := DOut[2] + (c and $C0) shr 6;
  600. DOut[3] := (c and $3F);
  601. end
  602. else
  603. begin
  604. DOut[3] := $40;
  605. end;
  606. end
  607. else
  608. begin
  609. DOut[2] := $40;
  610. DOut[3] := $40;
  611. end;
  612. for n := 0 to 3 do
  613. begin
  614. if (DOut[n] + 1) <= Length(Table) then
  615. begin
  616. Result[l] := Table[DOut[n] + 1];
  617. Inc(l);
  618. end;
  619. end;
  620. end;
  621. SetLength(Result, l - 1);
  622. end;
  623. {==============================================================================}
  624. function DecodeBase64(const Value: AnsiString): AnsiString;
  625. begin
  626. Result := Decode4to3Ex(Value, ReTableBase64);
  627. end;
  628. {==============================================================================}
  629. function EncodeBase64(const Value: AnsiString): AnsiString;
  630. begin
  631. Result := Encode3to4(Value, TableBase64);
  632. end;
  633. {==============================================================================}
  634. function DecodeBase64mod(const Value: AnsiString): AnsiString;
  635. begin
  636. Result := Decode4to3(Value, TableBase64mod);
  637. end;
  638. {==============================================================================}
  639. function EncodeBase64mod(const Value: AnsiString): AnsiString;
  640. begin
  641. Result := Encode3to4(Value, TableBase64mod);
  642. end;
  643. {==============================================================================}
  644. function DecodeUU(const Value: AnsiString): AnsiString;
  645. var
  646. s: AnsiString;
  647. uut: AnsiString;
  648. x: Integer;
  649. begin
  650. Result := '';
  651. uut := TableUU;
  652. s := trim(UpperCase(Value));
  653. if s = '' then Exit;
  654. if Pos('BEGIN', s) = 1 then
  655. Exit;
  656. if Pos('END', s) = 1 then
  657. Exit;
  658. if Pos('TABLE', s) = 1 then
  659. Exit; //ignore Table yet (set custom UUT)
  660. //begin decoding
  661. x := Pos(Value[1], uut) - 1;
  662. case (x mod 3) of
  663. 0: x :=(x div 3)* 4;
  664. 1: x :=((x div 3) * 4) + 2;
  665. 2: x :=((x div 3) * 4) + 3;
  666. end;
  667. //x - lenght UU line
  668. s := Copy(Value, 2, x);
  669. if s = '' then
  670. Exit;
  671. s := s + StringOfChar(' ', x - length(s));
  672. Result := Decode4to3(s, uut);
  673. end;
  674. {==============================================================================}
  675. function EncodeUU(const Value: AnsiString): AnsiString;
  676. begin
  677. Result := '';
  678. if Length(Value) < Length(TableUU) then
  679. Result := TableUU[Length(Value) + 1] + Encode3to4(Value, TableUU);
  680. end;
  681. {==============================================================================}
  682. function DecodeXX(const Value: AnsiString): AnsiString;
  683. var
  684. s: AnsiString;
  685. x: Integer;
  686. begin
  687. Result := '';
  688. s := trim(UpperCase(Value));
  689. if s = '' then
  690. Exit;
  691. if Pos('BEGIN', s) = 1 then
  692. Exit;
  693. if Pos('END', s) = 1 then
  694. Exit;
  695. //begin decoding
  696. x := Pos(Value[1], TableXX) - 1;
  697. case (x mod 3) of
  698. 0: x :=(x div 3)* 4;
  699. 1: x :=((x div 3) * 4) + 2;
  700. 2: x :=((x div 3) * 4) + 3;
  701. end;
  702. //x - lenght XX line
  703. s := Copy(Value, 2, x);
  704. if s = '' then
  705. Exit;
  706. s := s + StringOfChar(' ', x - length(s));
  707. Result := Decode4to3(s, TableXX);
  708. end;
  709. {==============================================================================}
  710. function DecodeYEnc(const Value: AnsiString): AnsiString;
  711. var
  712. C : Byte;
  713. i: integer;
  714. begin
  715. Result := '';
  716. i := 1;
  717. while i <= Length(Value) do
  718. begin
  719. c := Ord(Value[i]);
  720. Inc(i);
  721. if c = Ord('=') then
  722. begin
  723. c := Ord(Value[i]);
  724. Inc(i);
  725. Dec(c, 64);
  726. end;
  727. Dec(C, 42);
  728. Result := Result + AnsiChar(C);
  729. end;
  730. end;
  731. {==============================================================================}
  732. function UpdateCrc32(Value: Byte; Crc32: Integer): Integer;
  733. begin
  734. Result := (Crc32 shr 8)
  735. xor crc32tab[Byte(Value xor (Crc32 and Integer($000000FF)))];
  736. end;
  737. {==============================================================================}
  738. function Crc32(const Value: AnsiString): Integer;
  739. var
  740. n: Integer;
  741. begin
  742. Result := Integer($FFFFFFFF);
  743. for n := 1 to Length(Value) do
  744. Result := UpdateCrc32(Ord(Value[n]), Result);
  745. Result := not Result;
  746. end;
  747. {==============================================================================}
  748. function UpdateCrc16(Value: Byte; Crc16: Word): Word;
  749. begin
  750. Result := ((Crc16 shr 8) and $00FF) xor
  751. crc16tab[Byte(Crc16 xor (Word(Value)) and $00FF)];
  752. end;
  753. {==============================================================================}
  754. function Crc16(const Value: AnsiString): Word;
  755. var
  756. n: Integer;
  757. begin
  758. Result := $FFFF;
  759. for n := 1 to Length(Value) do
  760. Result := UpdateCrc16(Ord(Value[n]), Result);
  761. end;
  762. {==============================================================================}
  763. procedure MDInit(var MDContext: TMDCtx);
  764. var
  765. n: integer;
  766. begin
  767. MDContext.Count[0] := 0;
  768. MDContext.Count[1] := 0;
  769. for n := 0 to high(MDContext.BufAnsiChar) do
  770. MDContext.BufAnsiChar[n] := 0;
  771. for n := 0 to high(MDContext.BufLong) do
  772. MDContext.BufLong[n] := 0;
  773. MDContext.State[0] := Integer($67452301);
  774. MDContext.State[1] := Integer($EFCDAB89);
  775. MDContext.State[2] := Integer($98BADCFE);
  776. MDContext.State[3] := Integer($10325476);
  777. end;
  778. procedure MD5Transform(var Buf: array of LongInt; const Data: array of LongInt);
  779. var
  780. A, B, C, D: LongInt;
  781. procedure Round1(var W: LongInt; X, Y, Z, Data: LongInt; S: Byte);
  782. begin
  783. Inc(W, (Z xor (X and (Y xor Z))) + Data);
  784. W := (W shl S) or (W shr (32 - S));
  785. Inc(W, X);
  786. end;
  787. procedure Round2(var W: LongInt; X, Y, Z, Data: LongInt; S: Byte);
  788. begin
  789. Inc(W, (Y xor (Z and (X xor Y))) + Data);
  790. W := (W shl S) or (W shr (32 - S));
  791. Inc(W, X);
  792. end;
  793. procedure Round3(var W: LongInt; X, Y, Z, Data: LongInt; S: Byte);
  794. begin
  795. Inc(W, (X xor Y xor Z) + Data);
  796. W := (W shl S) or (W shr (32 - S));
  797. Inc(W, X);
  798. end;
  799. procedure Round4(var W: LongInt; X, Y, Z, Data: LongInt; S: Byte);
  800. begin
  801. Inc(W, (Y xor (X or not Z)) + Data);
  802. W := (W shl S) or (W shr (32 - S));
  803. Inc(W, X);
  804. end;
  805. begin
  806. A := Buf[0];
  807. B := Buf[1];
  808. C := Buf[2];
  809. D := Buf[3];
  810. Round1(A, B, C, D, Data[0] + Longint($D76AA478), 7);
  811. Round1(D, A, B, C, Data[1] + Longint($E8C7B756), 12);
  812. Round1(C, D, A, B, Data[2] + Longint($242070DB), 17);
  813. Round1(B, C, D, A, Data[3] + Longint($C1BDCEEE), 22);
  814. Round1(A, B, C, D, Data[4] + Longint($F57C0FAF), 7);
  815. Round1(D, A, B, C, Data[5] + Longint($4787C62A), 12);
  816. Round1(C, D, A, B, Data[6] + Longint($A8304613), 17);
  817. Round1(B, C, D, A, Data[7] + Longint($FD469501), 22);
  818. Round1(A, B, C, D, Data[8] + Longint($698098D8), 7);
  819. Round1(D, A, B, C, Data[9] + Longint($8B44F7AF), 12);
  820. Round1(C, D, A, B, Data[10] + Longint($FFFF5BB1), 17);
  821. Round1(B, C, D, A, Data[11] + Longint($895CD7BE), 22);
  822. Round1(A, B, C, D, Data[12] + Longint($6B901122), 7);
  823. Round1(D, A, B, C, Data[13] + Longint($FD987193), 12);
  824. Round1(C, D, A, B, Data[14] + Longint($A679438E), 17);
  825. Round1(B, C, D, A, Data[15] + Longint($49B40821), 22);
  826. Round2(A, B, C, D, Data[1] + Longint($F61E2562), 5);
  827. Round2(D, A, B, C, Data[6] + Longint($C040B340), 9);
  828. Round2(C, D, A, B, Data[11] + Longint($265E5A51), 14);
  829. Round2(B, C, D, A, Data[0] + Longint($E9B6C7AA), 20);
  830. Round2(A, B, C, D, Data[5] + Longint($D62F105D), 5);
  831. Round2(D, A, B, C, Data[10] + Longint($02441453), 9);
  832. Round2(C, D, A, B, Data[15] + Longint($D8A1E681), 14);
  833. Round2(B, C, D, A, Data[4] + Longint($E7D3FBC8), 20);
  834. Round2(A, B, C, D, Data[9] + Longint($21E1CDE6), 5);
  835. Round2(D, A, B, C, Data[14] + Longint($C33707D6), 9);
  836. Round2(C, D, A, B, Data[3] + Longint($F4D50D87), 14);
  837. Round2(B, C, D, A, Data[8] + Longint($455A14ED), 20);
  838. Round2(A, B, C, D, Data[13] + Longint($A9E3E905), 5);
  839. Round2(D, A, B, C, Data[2] + Longint($FCEFA3F8), 9);
  840. Round2(C, D, A, B, Data[7] + Longint($676F02D9), 14);
  841. Round2(B, C, D, A, Data[12] + Longint($8D2A4C8A), 20);
  842. Round3(A, B, C, D, Data[5] + Longint($FFFA3942), 4);
  843. Round3(D, A, B, C, Data[8] + Longint($8771F681), 11);
  844. Round3(C, D, A, B, Data[11] + Longint($6D9D6122), 16);
  845. Round3(B, C, D, A, Data[14] + Longint($FDE5380C), 23);
  846. Round3(A, B, C, D, Data[1] + Longint($A4BEEA44), 4);
  847. Round3(D, A, B, C, Data[4] + Longint($4BDECFA9), 11);
  848. Round3(C, D, A, B, Data[7] + Longint($F6BB4B60), 16);
  849. Round3(B, C, D, A, Data[10] + Longint($BEBFBC70), 23);
  850. Round3(A, B, C, D, Data[13] + Longint($289B7EC6), 4);
  851. Round3(D, A, B, C, Data[0] + Longint($EAA127FA), 11);
  852. Round3(C, D, A, B, Data[3] + Longint($D4EF3085), 16);
  853. Round3(B, C, D, A, Data[6] + Longint($04881D05), 23);
  854. Round3(A, B, C, D, Data[9] + Longint($D9D4D039), 4);
  855. Round3(D, A, B, C, Data[12] + Longint($E6DB99E5), 11);
  856. Round3(C, D, A, B, Data[15] + Longint($1FA27CF8), 16);
  857. Round3(B, C, D, A, Data[2] + Longint($C4AC5665), 23);
  858. Round4(A, B, C, D, Data[0] + Longint($F4292244), 6);
  859. Round4(D, A, B, C, Data[7] + Longint($432AFF97), 10);
  860. Round4(C, D, A, B, Data[14] + Longint($AB9423A7), 15);
  861. Round4(B, C, D, A, Data[5] + Longint($FC93A039), 21);
  862. Round4(A, B, C, D, Data[12] + Longint($655B59C3), 6);
  863. Round4(D, A, B, C, Data[3] + Longint($8F0CCC92), 10);
  864. Round4(C, D, A, B, Data[10] + Longint($FFEFF47D), 15);
  865. Round4(B, C, D, A, Data[1] + Longint($85845DD1), 21);
  866. Round4(A, B, C, D, Data[8] + Longint($6FA87E4F), 6);
  867. Round4(D, A, B, C, Data[15] + Longint($FE2CE6E0), 10);
  868. Round4(C, D, A, B, Data[6] + Longint($A3014314), 15);
  869. Round4(B, C, D, A, Data[13] + Longint($4E0811A1), 21);
  870. Round4(A, B, C, D, Data[4] + Longint($F7537E82), 6);
  871. Round4(D, A, B, C, Data[11] + Longint($BD3AF235), 10);
  872. Round4(C, D, A, B, Data[2] + Longint($2AD7D2BB), 15);
  873. Round4(B, C, D, A, Data[9] + Longint($EB86D391), 21);
  874. Inc(Buf[0], A);
  875. Inc(Buf[1], B);
  876. Inc(Buf[2], C);
  877. Inc(Buf[3], D);
  878. end;
  879. //fixed by James McAdams
  880. procedure MDUpdate(var MDContext: TMDCtx; const Data: AnsiString; transform: TMDTransform);
  881. var
  882. Index, partLen, InputLen, I: integer;
  883. {$IFDEF CIL}
  884. n: integer;
  885. {$ENDIF}
  886. begin
  887. InputLen := Length(Data);
  888. with MDContext do
  889. begin
  890. Index := (Count[0] shr 3) and $3F;
  891. Inc(Count[0], InputLen shl 3);
  892. if Count[0] < (InputLen shl 3) then
  893. Inc(Count[1]);
  894. Inc(Count[1], InputLen shr 29);
  895. partLen := 64 - Index;
  896. if InputLen >= partLen then
  897. begin
  898. ArrLongToByte(BufLong, BufAnsiChar);
  899. {$IFDEF CIL}
  900. for n := 1 to partLen do
  901. BufAnsiChar[index - 1 + n] := Ord(Data[n]);
  902. {$ELSE}
  903. Move(Data[1], BufAnsiChar[Index], partLen);
  904. {$ENDIF}
  905. ArrByteToLong(BufAnsiChar, BufLong);
  906. Transform(State, Buflong);
  907. I := partLen;
  908. while I + 63 < InputLen do
  909. begin
  910. ArrLongToByte(BufLong, BufAnsiChar);
  911. {$IFDEF CIL}
  912. for n := 1 to 64 do
  913. BufAnsiChar[n - 1] := Ord(Data[i + n]);
  914. {$ELSE}
  915. Move(Data[I+1], BufAnsiChar, 64);
  916. {$ENDIF}
  917. ArrByteToLong(BufAnsiChar, BufLong);
  918. Transform(State, Buflong);
  919. inc(I, 64);
  920. end;
  921. Index := 0;
  922. end
  923. else
  924. I := 0;
  925. ArrLongToByte(BufLong, BufAnsiChar);
  926. {$IFDEF CIL}
  927. for n := 1 to InputLen-I do
  928. BufAnsiChar[Index + n - 1] := Ord(Data[i + n]);
  929. {$ELSE}
  930. Move(Data[I+1], BufAnsiChar[Index], InputLen-I);
  931. {$ENDIF}
  932. ArrByteToLong(BufAnsiChar, BufLong);
  933. end
  934. end;
  935. function MDFinal(var MDContext: TMDCtx; transform: TMDTransform): AnsiString;
  936. var
  937. Cnt: Word;
  938. P: Byte;
  939. digest: array[0..15] of Byte;
  940. i: Integer;
  941. n: integer;
  942. begin
  943. for I := 0 to 15 do
  944. Digest[I] := I + 1;
  945. with MDContext do
  946. begin
  947. Cnt := (Count[0] shr 3) and $3F;
  948. P := Cnt;
  949. BufAnsiChar[P] := $80;
  950. Inc(P);
  951. Cnt := 64 - 1 - Cnt;
  952. if Cnt < 8 then
  953. begin
  954. for n := 0 to cnt - 1 do
  955. BufAnsiChar[P + n] := 0;
  956. ArrByteToLong(BufAnsiChar, BufLong);
  957. // FillChar(BufAnsiChar[P], Cnt, #0);
  958. Transform(State, BufLong);
  959. ArrLongToByte(BufLong, BufAnsiChar);
  960. for n := 0 to 55 do
  961. BufAnsiChar[n] := 0;
  962. ArrByteToLong(BufAnsiChar, BufLong);
  963. // FillChar(BufAnsiChar, 56, #0);
  964. end
  965. else
  966. begin
  967. for n := 0 to Cnt - 8 - 1 do
  968. BufAnsiChar[p + n] := 0;
  969. ArrByteToLong(BufAnsiChar, BufLong);
  970. // FillChar(BufAnsiChar[P], Cnt - 8, #0);
  971. end;
  972. BufLong[14] := Count[0];
  973. BufLong[15] := Count[1];
  974. Transform(State, BufLong);
  975. ArrLongToByte(State, Digest);
  976. // Move(State, Digest, 16);
  977. Result := '';
  978. for i := 0 to 15 do
  979. Result := Result + AnsiChar(digest[i]);
  980. end;
  981. // FillChar(MD5Context, SizeOf(TMD5Ctx), #0)
  982. end;
  983. {==============================================================================}
  984. function MD5(const Value: AnsiString): AnsiString;
  985. var
  986. MDContext: TMDCtx;
  987. begin
  988. MDInit(MDContext);
  989. MDUpdate(MDContext, Value, @MD5Transform);
  990. Result := MDFinal(MDContext, @MD5Transform);
  991. end;
  992. {==============================================================================}
  993. function HMAC_MD5(Text, Key: AnsiString): AnsiString;
  994. var
  995. ipad, opad, s: AnsiString;
  996. n: Integer;
  997. MDContext: TMDCtx;
  998. begin
  999. if Length(Key) > 64 then
  1000. Key := md5(Key);
  1001. ipad := StringOfChar(#$36, 64);
  1002. opad := StringOfChar(#$5C, 64);
  1003. for n := 1 to Length(Key) do
  1004. begin
  1005. ipad[n] := AnsiChar(Byte(ipad[n]) xor Byte(Key[n]));
  1006. opad[n] := AnsiChar(Byte(opad[n]) xor Byte(Key[n]));
  1007. end;
  1008. MDInit(MDContext);
  1009. MDUpdate(MDContext, ipad, @MD5Transform);
  1010. MDUpdate(MDContext, Text, @MD5Transform);
  1011. s := MDFinal(MDContext, @MD5Transform);
  1012. MDInit(MDContext);
  1013. MDUpdate(MDContext, opad, @MD5Transform);
  1014. MDUpdate(MDContext, s, @MD5Transform);
  1015. Result := MDFinal(MDContext, @MD5Transform);
  1016. end;
  1017. {==============================================================================}
  1018. function MD5LongHash(const Value: AnsiString; Len: integer): AnsiString;
  1019. var
  1020. cnt, rest: integer;
  1021. l: integer;
  1022. n: integer;
  1023. MDContext: TMDCtx;
  1024. begin
  1025. l := length(Value);
  1026. cnt := Len div l;
  1027. rest := Len mod l;
  1028. MDInit(MDContext);
  1029. for n := 1 to cnt do
  1030. MDUpdate(MDContext, Value, @MD5Transform);
  1031. if rest > 0 then
  1032. MDUpdate(MDContext, Copy(Value, 1, rest), @MD5Transform);
  1033. Result := MDFinal(MDContext, @MD5Transform);
  1034. end;
  1035. {==============================================================================}
  1036. // SHA1 is based on sources by Dave Barton (davebarton@bigfoot.com)
  1037. procedure SHA1init( var SHA1Context: TSHA1Ctx );
  1038. var
  1039. n: integer;
  1040. begin
  1041. SHA1Context.Hi := 0;
  1042. SHA1Context.Lo := 0;
  1043. SHA1Context.Index := 0;
  1044. for n := 0 to High(SHA1Context.Buffer) do
  1045. SHA1Context.Buffer[n] := 0;
  1046. for n := 0 to High(SHA1Context.HashByte) do
  1047. SHA1Context.HashByte[n] := 0;
  1048. // FillChar(SHA1Context, SizeOf(TSHA1Ctx), #0);
  1049. SHA1Context.Hash[0] := integer($67452301);
  1050. SHA1Context.Hash[1] := integer($EFCDAB89);
  1051. SHA1Context.Hash[2] := integer($98BADCFE);
  1052. SHA1Context.Hash[3] := integer($10325476);
  1053. SHA1Context.Hash[4] := integer($C3D2E1F0);
  1054. end;
  1055. //******************************************************************************
  1056. function RB(A: integer): integer;
  1057. begin
  1058. Result := (A shr 24) or ((A shr 8) and $FF00) or ((A shl 8) and $FF0000) or (A shl 24);
  1059. end;
  1060. procedure SHA1Compress(var Data: TSHA1Ctx);
  1061. var
  1062. A, B, C, D, E, T: integer;
  1063. W: array[0..79] of integer;
  1064. i: integer;
  1065. n: integer;
  1066. function F1(x, y, z: integer): integer;
  1067. begin
  1068. Result := z xor (x and (y xor z));
  1069. end;
  1070. function F2(x, y, z: integer): integer;
  1071. begin
  1072. Result := x xor y xor z;
  1073. end;
  1074. function F3(x, y, z: integer): integer;
  1075. begin
  1076. Result := (x and y) or (z and (x or y));
  1077. end;
  1078. function LRot32(X: integer; c: integer): integer;
  1079. begin
  1080. result := (x shl c) or (x shr (32 - c));
  1081. end;
  1082. begin
  1083. ArrByteToLong(Data.Buffer, W);
  1084. // Move(Data.Buffer, W, Sizeof(Data.Buffer));
  1085. for i := 0 to 15 do
  1086. W[i] := RB(W[i]);
  1087. for i := 16 to 79 do
  1088. W[i] := LRot32(W[i-3] xor W[i-8] xor W[i-14] xor W[i-16], 1);
  1089. A := Data.Hash[0];
  1090. B := Data.Hash[1];
  1091. C := Data.Hash[2];
  1092. D := Data.Hash[3];
  1093. E := Data.Hash[4];
  1094. for i := 0 to 19 do
  1095. begin
  1096. T := LRot32(A, 5) + F1(B, C, D) + E + W[i] + integer($5A827999);
  1097. E := D;
  1098. D := C;
  1099. C := LRot32(B, 30);
  1100. B := A;
  1101. A := T;
  1102. end;
  1103. for i := 20 to 39 do
  1104. begin
  1105. T := LRot32(A, 5) + F2(B, C, D) + E + W[i] + integer($6ED9EBA1);
  1106. E := D;
  1107. D := C;
  1108. C := LRot32(B, 30);
  1109. B := A;
  1110. A := T;
  1111. end;
  1112. for i := 40 to 59 do
  1113. begin
  1114. T := LRot32(A, 5) + F3(B, C, D) + E + W[i] + integer($8F1BBCDC);
  1115. E := D;
  1116. D := C;
  1117. C := LRot32(B, 30);
  1118. B := A;
  1119. A := T;
  1120. end;
  1121. for i := 60 to 79 do
  1122. begin
  1123. T := LRot32(A, 5) + F2(B, C, D) + E + W[i] + integer($CA62C1D6);
  1124. E := D;
  1125. D := C;
  1126. C := LRot32(B, 30);
  1127. B := A;
  1128. A := T;
  1129. end;
  1130. Data.Hash[0] := Data.Hash[0] + A;
  1131. Data.Hash[1] := Data.Hash[1] + B;
  1132. Data.Hash[2] := Data.Hash[2] + C;
  1133. Data.Hash[3] := Data.Hash[3] + D;
  1134. Data.Hash[4] := Data.Hash[4] + E;
  1135. for n := 0 to high(w) do
  1136. w[n] := 0;
  1137. // FillChar(W, Sizeof(W), 0);
  1138. for n := 0 to high(Data.Buffer) do
  1139. Data.Buffer[n] := 0;
  1140. // FillChar(Data.Buffer, Sizeof(Data.Buffer), 0);
  1141. end;
  1142. //******************************************************************************
  1143. procedure SHA1Update(var Context: TSHA1Ctx; const Data: AnsiString);
  1144. var
  1145. Len: integer;
  1146. n: integer;
  1147. i, k: integer;
  1148. begin
  1149. Len := Length(data);
  1150. for k := 0 to 7 do
  1151. begin
  1152. i := Context.Lo;
  1153. Inc(Context.Lo, Len);
  1154. if Context.Lo < i then
  1155. Inc(Context.Hi);
  1156. end;
  1157. for n := 1 to len do
  1158. begin
  1159. Context.Buffer[Context.Index] := byte(Data[n]);
  1160. Inc(Context.Index);
  1161. if Context.Index = 64 then
  1162. begin
  1163. Context.Index := 0;
  1164. SHA1Compress(Context);
  1165. end;
  1166. end;
  1167. end;
  1168. //******************************************************************************
  1169. function SHA1Final(var Context: TSHA1Ctx): AnsiString;
  1170. type
  1171. Pinteger = ^integer;
  1172. var
  1173. i: integer;
  1174. procedure ItoArr(var Ar: Array of byte; I, value: Integer);
  1175. begin
  1176. Ar[i + 0] := Value and $000000FF;
  1177. Ar[i + 1] := (Value shr 8) and $000000FF;
  1178. Ar[i + 2] := (Value shr 16) and $000000FF;
  1179. Ar[i + 3] := (Value shr 24) and $000000FF;
  1180. end;
  1181. begin
  1182. Context.Buffer[Context.Index] := $80;
  1183. if Context.Index >= 56 then
  1184. SHA1Compress(Context);
  1185. ItoArr(Context.Buffer, 56, RB(Context.Hi));
  1186. ItoArr(Context.Buffer, 60, RB(Context.Lo));
  1187. // Pinteger(@Context.Buffer[56])^ := RB(Context.Hi);
  1188. // Pinteger(@Context.Buffer[60])^ := RB(Context.Lo);
  1189. SHA1Compress(Context);
  1190. Context.Hash[0] := RB(Context.Hash[0]);
  1191. Context.Hash[1] := RB(Context.Hash[1]);
  1192. Context.Hash[2] := RB(Context.Hash[2]);
  1193. Context.Hash[3] := RB(Context.Hash[3]);
  1194. Context.Hash[4] := RB(Context.Hash[4]);
  1195. ArrLongToByte(Context.Hash, Context.HashByte);
  1196. Result := '';
  1197. for i := 0 to 19 do
  1198. Result := Result + AnsiChar(Context.HashByte[i]);
  1199. end;
  1200. function SHA1(const Value: AnsiString): AnsiString;
  1201. var
  1202. SHA1Context: TSHA1Ctx;
  1203. begin
  1204. SHA1Init(SHA1Context);
  1205. SHA1Update(SHA1Context, Value);
  1206. Result := SHA1Final(SHA1Context);
  1207. end;
  1208. {==============================================================================}
  1209. function HMAC_SHA1(Text, Key: AnsiString): AnsiString;
  1210. var
  1211. ipad, opad, s: AnsiString;
  1212. n: Integer;
  1213. SHA1Context: TSHA1Ctx;
  1214. begin
  1215. if Length(Key) > 64 then
  1216. Key := SHA1(Key);
  1217. ipad := StringOfChar(#$36, 64);
  1218. opad := StringOfChar(#$5C, 64);
  1219. for n := 1 to Length(Key) do
  1220. begin
  1221. ipad[n] := AnsiChar(Byte(ipad[n]) xor Byte(Key[n]));
  1222. opad[n] := AnsiChar(Byte(opad[n]) xor Byte(Key[n]));
  1223. end;
  1224. SHA1Init(SHA1Context);
  1225. SHA1Update(SHA1Context, ipad);
  1226. SHA1Update(SHA1Context, Text);
  1227. s := SHA1Final(SHA1Context);
  1228. SHA1Init(SHA1Context);
  1229. SHA1Update(SHA1Context, opad);
  1230. SHA1Update(SHA1Context, s);
  1231. Result := SHA1Final(SHA1Context);
  1232. end;
  1233. {==============================================================================}
  1234. function SHA1LongHash(const Value: AnsiString; Len: integer): AnsiString;
  1235. var
  1236. cnt, rest: integer;
  1237. l: integer;
  1238. n: integer;
  1239. SHA1Context: TSHA1Ctx;
  1240. begin
  1241. l := length(Value);
  1242. cnt := Len div l;
  1243. rest := Len mod l;
  1244. SHA1Init(SHA1Context);
  1245. for n := 1 to cnt do
  1246. SHA1Update(SHA1Context, Value);
  1247. if rest > 0 then
  1248. SHA1Update(SHA1Context, Copy(Value, 1, rest));
  1249. Result := SHA1Final(SHA1Context);
  1250. end;
  1251. {==============================================================================}
  1252. procedure MD4Transform(var Buf: array of LongInt; const Data: array of LongInt);
  1253. var
  1254. A, B, C, D: LongInt;
  1255. function LRot32(a, b: longint): longint;
  1256. begin
  1257. Result:= (a shl b) or (a shr (32 - b));
  1258. end;
  1259. begin
  1260. A := Buf[0];
  1261. B := Buf[1];
  1262. C := Buf[2];
  1263. D := Buf[3];
  1264. A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 0], 3);
  1265. D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 1], 7);
  1266. C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 2], 11);
  1267. B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 3], 19);
  1268. A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 4], 3);
  1269. D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 5], 7);
  1270. C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 6], 11);
  1271. B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 7], 19);
  1272. A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 8], 3);
  1273. D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 9], 7);
  1274. C:= LRot32(C + (B xor (D and (A xor B))) + Data[10], 11);
  1275. B:= LRot32(B + (A xor (C and (D xor A))) + Data[11], 19);
  1276. A:= LRot32(A + (D xor (B and (C xor D))) + Data[12], 3);
  1277. D:= LRot32(D + (C xor (A and (B xor C))) + Data[13], 7);
  1278. C:= LRot32(C + (B xor (D and (A xor B))) + Data[14], 11);
  1279. B:= LRot32(B + (A xor (C and (D xor A))) + Data[15], 19);
  1280. A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 0] + longint($5a827999), 3);
  1281. D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 4] + longint($5a827999), 5);
  1282. C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 8] + longint($5a827999), 9);
  1283. B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[12] + longint($5a827999), 13);
  1284. A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 1] + longint($5a827999), 3);
  1285. D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 5] + longint($5a827999), 5);
  1286. C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 9] + longint($5a827999), 9);
  1287. B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[13] + longint($5a827999), 13);
  1288. A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 2] + longint($5a827999), 3);
  1289. D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 6] + longint($5a827999), 5);
  1290. C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[10] + longint($5a827999), 9);
  1291. B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[14] + longint($5a827999), 13);
  1292. A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 3] + longint($5a827999), 3);
  1293. D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 7] + longint($5a827999), 5);
  1294. C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[11] + longint($5a827999), 9);
  1295. B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[15] + longint($5a827999), 13);
  1296. A:= LRot32(A + (B xor C xor D) + Data[ 0] + longint($6ed9eba1), 3);
  1297. D:= LRot32(D + (A xor B xor C) + Data[ 8] + longint($6ed9eba1), 9);
  1298. C:= LRot32(C + (D xor A xor B) + Data[ 4] + longint($6ed9eba1), 11);
  1299. B:= LRot32(B + (C xor D xor A) + Data[12] + longint($6ed9eba1), 15);
  1300. A:= LRot32(A + (B xor C xor D) + Data[ 2] + longint($6ed9eba1), 3);
  1301. D:= LRot32(D + (A xor B xor C) + Data[10] + longint($6ed9eba1), 9);
  1302. C:= LRot32(C + (D xor A xor B) + Data[ 6] + longint($6ed9eba1), 11);
  1303. B:= LRot32(B + (C xor D xor A) + Data[14] + longint($6ed9eba1), 15);
  1304. A:= LRot32(A + (B xor C xor D) + Data[ 1] + longint($6ed9eba1), 3);
  1305. D:= LRot32(D + (A xor B xor C) + Data[ 9] + longint($6ed9eba1), 9);
  1306. C:= LRot32(C + (D xor A xor B) + Data[ 5] + longint($6ed9eba1), 11);
  1307. B:= LRot32(B + (C xor D xor A) + Data[13] + longint($6ed9eba1), 15);
  1308. A:= LRot32(A + (B xor C xor D) + Data[ 3] + longint($6ed9eba1), 3);
  1309. D:= LRot32(D + (A xor B xor C) + Data[11] + longint($6ed9eba1), 9);
  1310. C:= LRot32(C + (D xor A xor B) + Data[ 7] + longint($6ed9eba1), 11);
  1311. B:= LRot32(B + (C xor D xor A) + Data[15] + longint($6ed9eba1), 15);
  1312. Inc(Buf[0], A);
  1313. Inc(Buf[1], B);
  1314. Inc(Buf[2], C);
  1315. Inc(Buf[3], D);
  1316. end;
  1317. {==============================================================================}
  1318. function MD4(const Value: AnsiString): AnsiString;
  1319. var
  1320. MDContext: TMDCtx;
  1321. begin
  1322. MDInit(MDContext);
  1323. MDUpdate(MDContext, Value, @MD4Transform);
  1324. Result := MDFinal(MDContext, @MD4Transform);
  1325. end;
  1326. {==============================================================================}
  1327. end.