Advertisement
Guest User

VBA MD5

a guest
Mar 17th, 2012
1,979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '*******************************************************************************
  2. ' MODULE:       CMD5
  3. ' FILENAME:     C:\My Code\vb\md5\CMD5.cls
  4. ' AUTHOR:       Phil Fresle
  5. ' CREATED:      16-Feb-2001
  6. ' COPYRIGHT:    Copyright 2001 Frez Systems Limited. All Rights Reserved.
  7. '
  8. ' DESCRIPTION:
  9. ' Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm,
  10. ' as set out in the memo RFC1321.
  11. '
  12. ' This class is used to generate an MD5 'digest' or 'signature' of a string. The
  13. ' MD5 algorithm is one of the industry standard methods for generating digital
  14. ' signatures. It is generically known as a digest, digital signature, one-way
  15. ' encryption, hash or checksum algorithm. A common use for MD5 is for password
  16. ' encryption as it is one-way in nature, that does not mean that your passwords
  17. ' are not free from a dictionary attack. If you are using the
  18. ' routine for passwords, you can make it a little more secure by concatenating
  19. ' some known random characters to the password before you generate the signature
  20. ' and on subsequent tests, so even if a hacker knows you are using MD5 for
  21. ' your passwords, the random characters will make it harder to dictionary attack.
  22. '
  23. ' *** CAUTION ***
  24. ' See the comment attached to the MD5 method below regarding use on systems
  25. ' with different character sets.
  26. '
  27. ' This is 'free' software with the following restrictions:
  28. '
  29. ' You may not redistribute this code as a 'sample' or 'demo'. However, you are free
  30. ' to use the source code in your own code, but you may not claim that you created
  31. ' the sample code. It is expressly forbidden to sell or profit from this source code
  32. ' other than by the knowledge gained or the enhanced value added by your own code.
  33. '
  34. ' Use of this software is also done so at your own risk. The code is supplied as
  35. ' is without warranty or guarantee of any kind.
  36. '
  37. ' Should you wish to commission some derivative work based on this code provided
  38. ' here, or any consultancy work, please do not hesitate to contact us.
  39. '
  40. ' Web Site:  http://www.frez.co.uk
  41. ' E-mail:    sales@frez.co.uk
  42. '
  43. ' MODIFICATION HISTORY:
  44. ' 1.0       16-Feb-2001
  45. '           Phil Fresle
  46. '           Initial Version
  47. '*******************************************************************************
  48. Option Explicit
  49.  
  50. Private Const BITS_TO_A_BYTE  As Long = 8
  51. Private Const BYTES_TO_A_WORD As Long = 4
  52. Private Const BITS_TO_A_WORD  As Long = BYTES_TO_A_WORD * BITS_TO_A_BYTE
  53.  
  54. Private m_lOnBits(0 To 30) As Long
  55. Private m_l2Power(0 To 30) As Long
  56.  
  57. '*******************************************************************************
  58. ' Class_Initialize (SUB)
  59. '
  60. ' DESCRIPTION:
  61. ' We will usually get quicker results by preparing arrays of bit patterns and
  62. ' powers of 2 ahead of time instead of calculating them every time, unless of
  63. ' course the methods are only ever getting called once per instantiation of the
  64. ' class.
  65. '*******************************************************************************
  66. Private Sub Class_Initialize()
  67.     ' Could have done this with a loop calculating each value, but simply
  68.    ' assigning the values is quicker - BITS SET FROM RIGHT
  69.    m_lOnBits(0) = 1            ' 00000000000000000000000000000001
  70.    m_lOnBits(1) = 3            ' 00000000000000000000000000000011
  71.    m_lOnBits(2) = 7            ' 00000000000000000000000000000111
  72.    m_lOnBits(3) = 15           ' 00000000000000000000000000001111
  73.    m_lOnBits(4) = 31           ' 00000000000000000000000000011111
  74.    m_lOnBits(5) = 63           ' 00000000000000000000000000111111
  75.    m_lOnBits(6) = 127          ' 00000000000000000000000001111111
  76.    m_lOnBits(7) = 255          ' 00000000000000000000000011111111
  77.    m_lOnBits(8) = 511          ' 00000000000000000000000111111111
  78.    m_lOnBits(9) = 1023         ' 00000000000000000000001111111111
  79.    m_lOnBits(10) = 2047        ' 00000000000000000000011111111111
  80.    m_lOnBits(11) = 4095        ' 00000000000000000000111111111111
  81.    m_lOnBits(12) = 8191        ' 00000000000000000001111111111111
  82.    m_lOnBits(13) = 16383       ' 00000000000000000011111111111111
  83.    m_lOnBits(14) = 32767       ' 00000000000000000111111111111111
  84.    m_lOnBits(15) = 65535       ' 00000000000000001111111111111111
  85.    m_lOnBits(16) = 131071      ' 00000000000000011111111111111111
  86.    m_lOnBits(17) = 262143      ' 00000000000000111111111111111111
  87.    m_lOnBits(18) = 524287      ' 00000000000001111111111111111111
  88.    m_lOnBits(19) = 1048575     ' 00000000000011111111111111111111
  89.    m_lOnBits(20) = 2097151     ' 00000000000111111111111111111111
  90.    m_lOnBits(21) = 4194303     ' 00000000001111111111111111111111
  91.    m_lOnBits(22) = 8388607     ' 00000000011111111111111111111111
  92.    m_lOnBits(23) = 16777215    ' 00000000111111111111111111111111
  93.    m_lOnBits(24) = 33554431    ' 00000001111111111111111111111111
  94.    m_lOnBits(25) = 67108863    ' 00000011111111111111111111111111
  95.    m_lOnBits(26) = 134217727   ' 00000111111111111111111111111111
  96.    m_lOnBits(27) = 268435455   ' 00001111111111111111111111111111
  97.    m_lOnBits(28) = 536870911   ' 00011111111111111111111111111111
  98.    m_lOnBits(29) = 1073741823  ' 00111111111111111111111111111111
  99.    m_lOnBits(30) = 2147483647  ' 01111111111111111111111111111111
  100.    
  101.     ' Could have done this with a loop calculating each value, but simply
  102.    ' assigning the values is quicker - POWERS OF 2
  103.    m_l2Power(0) = 1            ' 00000000000000000000000000000001
  104.    m_l2Power(1) = 2            ' 00000000000000000000000000000010
  105.    m_l2Power(2) = 4            ' 00000000000000000000000000000100
  106.    m_l2Power(3) = 8            ' 00000000000000000000000000001000
  107.    m_l2Power(4) = 16           ' 00000000000000000000000000010000
  108.    m_l2Power(5) = 32           ' 00000000000000000000000000100000
  109.    m_l2Power(6) = 64           ' 00000000000000000000000001000000
  110.    m_l2Power(7) = 128          ' 00000000000000000000000010000000
  111.    m_l2Power(8) = 256          ' 00000000000000000000000100000000
  112.    m_l2Power(9) = 512          ' 00000000000000000000001000000000
  113.    m_l2Power(10) = 1024        ' 00000000000000000000010000000000
  114.    m_l2Power(11) = 2048        ' 00000000000000000000100000000000
  115.    m_l2Power(12) = 4096        ' 00000000000000000001000000000000
  116.    m_l2Power(13) = 8192        ' 00000000000000000010000000000000
  117.    m_l2Power(14) = 16384       ' 00000000000000000100000000000000
  118.    m_l2Power(15) = 32768       ' 00000000000000001000000000000000
  119.    m_l2Power(16) = 65536       ' 00000000000000010000000000000000
  120.    m_l2Power(17) = 131072      ' 00000000000000100000000000000000
  121.    m_l2Power(18) = 262144      ' 00000000000001000000000000000000
  122.    m_l2Power(19) = 524288      ' 00000000000010000000000000000000
  123.    m_l2Power(20) = 1048576     ' 00000000000100000000000000000000
  124.    m_l2Power(21) = 2097152     ' 00000000001000000000000000000000
  125.    m_l2Power(22) = 4194304     ' 00000000010000000000000000000000
  126.    m_l2Power(23) = 8388608     ' 00000000100000000000000000000000
  127.    m_l2Power(24) = 16777216    ' 00000001000000000000000000000000
  128.    m_l2Power(25) = 33554432    ' 00000010000000000000000000000000
  129.    m_l2Power(26) = 67108864    ' 00000100000000000000000000000000
  130.    m_l2Power(27) = 134217728   ' 00001000000000000000000000000000
  131.    m_l2Power(28) = 268435456   ' 00010000000000000000000000000000
  132.    m_l2Power(29) = 536870912   ' 00100000000000000000000000000000
  133.    m_l2Power(30) = 1073741824  ' 01000000000000000000000000000000
  134. End Sub
  135.  
  136. '*******************************************************************************
  137. ' LShift (FUNCTION)
  138. '
  139. ' PARAMETERS:
  140. ' (In) - lValue     - Long    - The value to be shifted
  141. ' (In) - iShiftBits - Integer - The number of bits to shift the value by
  142. '
  143. ' RETURN VALUE:
  144. ' Long - The shifted long integer
  145. '
  146. ' DESCRIPTION:
  147. ' A left shift takes all the set binary bits and moves them left, in-filling
  148. ' with zeros in the vacated bits on the right. This function is equivalent to
  149. ' the << operator in Java and C++
  150. '*******************************************************************************
  151. Private Function LShift(ByVal lValue As Long, _
  152.                         ByVal iShiftBits As Integer) As Long
  153.                        
  154.     m_lOnBits(0) = 1            ' 00000000000000000000000000000001
  155.    m_lOnBits(1) = 3            ' 00000000000000000000000000000011
  156.    m_lOnBits(2) = 7            ' 00000000000000000000000000000111
  157.    m_lOnBits(3) = 15           ' 00000000000000000000000000001111
  158.    m_lOnBits(4) = 31           ' 00000000000000000000000000011111
  159.    m_lOnBits(5) = 63           ' 00000000000000000000000000111111
  160.    m_lOnBits(6) = 127          ' 00000000000000000000000001111111
  161.    m_lOnBits(7) = 255          ' 00000000000000000000000011111111
  162.    m_lOnBits(8) = 511          ' 00000000000000000000000111111111
  163.    m_lOnBits(9) = 1023         ' 00000000000000000000001111111111
  164.    m_lOnBits(10) = 2047        ' 00000000000000000000011111111111
  165.    m_lOnBits(11) = 4095        ' 00000000000000000000111111111111
  166.    m_lOnBits(12) = 8191        ' 00000000000000000001111111111111
  167.    m_lOnBits(13) = 16383       ' 00000000000000000011111111111111
  168.    m_lOnBits(14) = 32767       ' 00000000000000000111111111111111
  169.    m_lOnBits(15) = 65535       ' 00000000000000001111111111111111
  170.    m_lOnBits(16) = 131071      ' 00000000000000011111111111111111
  171.    m_lOnBits(17) = 262143      ' 00000000000000111111111111111111
  172.    m_lOnBits(18) = 524287      ' 00000000000001111111111111111111
  173.    m_lOnBits(19) = 1048575     ' 00000000000011111111111111111111
  174.    m_lOnBits(20) = 2097151     ' 00000000000111111111111111111111
  175.    m_lOnBits(21) = 4194303     ' 00000000001111111111111111111111
  176.    m_lOnBits(22) = 8388607     ' 00000000011111111111111111111111
  177.    m_lOnBits(23) = 16777215    ' 00000000111111111111111111111111
  178.    m_lOnBits(24) = 33554431    ' 00000001111111111111111111111111
  179.    m_lOnBits(25) = 67108863    ' 00000011111111111111111111111111
  180.    m_lOnBits(26) = 134217727   ' 00000111111111111111111111111111
  181.    m_lOnBits(27) = 268435455   ' 00001111111111111111111111111111
  182.    m_lOnBits(28) = 536870911   ' 00011111111111111111111111111111
  183.    m_lOnBits(29) = 1073741823  ' 00111111111111111111111111111111
  184.    m_lOnBits(30) = 2147483647  ' 01111111111111111111111111111111
  185.    
  186.     ' Could have done this with a loop calculating each value, but simply
  187.    ' assigning the values is quicker - POWERS OF 2
  188.    m_l2Power(0) = 1            ' 00000000000000000000000000000001
  189.    m_l2Power(1) = 2            ' 00000000000000000000000000000010
  190.    m_l2Power(2) = 4            ' 00000000000000000000000000000100
  191.    m_l2Power(3) = 8            ' 00000000000000000000000000001000
  192.    m_l2Power(4) = 16           ' 00000000000000000000000000010000
  193.    m_l2Power(5) = 32           ' 00000000000000000000000000100000
  194.    m_l2Power(6) = 64           ' 00000000000000000000000001000000
  195.    m_l2Power(7) = 128          ' 00000000000000000000000010000000
  196.    m_l2Power(8) = 256          ' 00000000000000000000000100000000
  197.    m_l2Power(9) = 512          ' 00000000000000000000001000000000
  198.    m_l2Power(10) = 1024        ' 00000000000000000000010000000000
  199.    m_l2Power(11) = 2048        ' 00000000000000000000100000000000
  200.    m_l2Power(12) = 4096        ' 00000000000000000001000000000000
  201.    m_l2Power(13) = 8192        ' 00000000000000000010000000000000
  202.    m_l2Power(14) = 16384       ' 00000000000000000100000000000000
  203.    m_l2Power(15) = 32768       ' 00000000000000001000000000000000
  204.    m_l2Power(16) = 65536       ' 00000000000000010000000000000000
  205.    m_l2Power(17) = 131072      ' 00000000000000100000000000000000
  206.    m_l2Power(18) = 262144      ' 00000000000001000000000000000000
  207.    m_l2Power(19) = 524288      ' 00000000000010000000000000000000
  208.    m_l2Power(20) = 1048576     ' 00000000000100000000000000000000
  209.    m_l2Power(21) = 2097152     ' 00000000001000000000000000000000
  210.    m_l2Power(22) = 4194304     ' 00000000010000000000000000000000
  211.    m_l2Power(23) = 8388608     ' 00000000100000000000000000000000
  212.    m_l2Power(24) = 16777216    ' 00000001000000000000000000000000
  213.    m_l2Power(25) = 33554432    ' 00000010000000000000000000000000
  214.    m_l2Power(26) = 67108864    ' 00000100000000000000000000000000
  215.    m_l2Power(27) = 134217728   ' 00001000000000000000000000000000
  216.    m_l2Power(28) = 268435456   ' 00010000000000000000000000000000
  217.    m_l2Power(29) = 536870912   ' 00100000000000000000000000000000
  218.    m_l2Power(30) = 1073741824  ' 01000000000000000000000000000000
  219.                        
  220.     ' NOTE: If you can guarantee that the Shift parameter will be in the
  221.    ' range 1 to 30 you can safely strip of this first nested if structure for
  222.    ' speed.
  223.    '
  224.    ' A shift of zero is no shift at all.
  225.    If iShiftBits = 0 Then
  226.         LShift = lValue
  227.         Exit Function
  228.        
  229.     ' A shift of 31 will result in the right most bit becoming the left most
  230.    ' bit and all other bits being cleared
  231.    ElseIf iShiftBits = 31 Then
  232.         If lValue And 1 Then
  233.             LShift = &H80000000
  234.         Else
  235.             LShift = 0
  236.         End If
  237.         Exit Function
  238.        
  239.     ' A shift of less than zero or more than 31 is undefined
  240.    ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  241.         Err.Raise 6
  242.     End If
  243.    
  244.     ' If the left most bit that remains will end up in the negative bit
  245.    ' position (&H80000000) we would end up with an overflow if we took the
  246.    ' standard route. We need to strip the left most bit and add it back
  247.    ' afterwards.
  248.    If (lValue And m_l2Power(31 - iShiftBits)) Then
  249.    
  250.         ' (Value And OnBits(31 - (Shift + 1))) chops off the left most bits that
  251.        ' we are shifting into, but also the left most bit we still want as this
  252.        ' is going to end up in the negative bit marker position (&H80000000).
  253.        ' After the multiplication/shift we Or the result with &H80000000 to
  254.        ' turn the negative bit on.
  255.        LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * _
  256.             m_l2Power(iShiftBits)) Or &H80000000
  257.    
  258.     Else
  259.    
  260.         ' (Value And OnBits(31-Shift)) chops off the left most bits that we are
  261.        ' shifting into so we do not get an overflow error when we do the
  262.        ' multiplication/shift
  263.        LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * _
  264.             m_l2Power(iShiftBits))
  265.        
  266.     End If
  267. End Function
  268.  
  269. '*******************************************************************************
  270. ' RShift (FUNCTION)
  271. '
  272. ' PARAMETERS:
  273. ' (In) - lValue     - Long    - The value to be shifted
  274. ' (In) - iShiftBits - Integer - The number of bits to shift the value by
  275. '
  276. ' RETURN VALUE:
  277. ' Long - The shifted long integer
  278. '
  279. ' DESCRIPTION:
  280. ' The right shift of an unsigned long integer involves shifting all the set bits
  281. ' to the right and in-filling on the left with zeros. This function is
  282. ' equivalent to the >>> operator in Java or the >> operator in C++ when used on
  283. ' an unsigned long.
  284. '*******************************************************************************
  285. Private Function RShift(ByVal lValue As Long, _
  286.                         ByVal iShiftBits As Integer) As Long
  287.    
  288.     m_lOnBits(0) = 1            ' 00000000000000000000000000000001
  289.    m_lOnBits(1) = 3            ' 00000000000000000000000000000011
  290.    m_lOnBits(2) = 7            ' 00000000000000000000000000000111
  291.    m_lOnBits(3) = 15           ' 00000000000000000000000000001111
  292.    m_lOnBits(4) = 31           ' 00000000000000000000000000011111
  293.    m_lOnBits(5) = 63           ' 00000000000000000000000000111111
  294.    m_lOnBits(6) = 127          ' 00000000000000000000000001111111
  295.    m_lOnBits(7) = 255          ' 00000000000000000000000011111111
  296.    m_lOnBits(8) = 511          ' 00000000000000000000000111111111
  297.    m_lOnBits(9) = 1023         ' 00000000000000000000001111111111
  298.    m_lOnBits(10) = 2047        ' 00000000000000000000011111111111
  299.    m_lOnBits(11) = 4095        ' 00000000000000000000111111111111
  300.    m_lOnBits(12) = 8191        ' 00000000000000000001111111111111
  301.    m_lOnBits(13) = 16383       ' 00000000000000000011111111111111
  302.    m_lOnBits(14) = 32767       ' 00000000000000000111111111111111
  303.    m_lOnBits(15) = 65535       ' 00000000000000001111111111111111
  304.    m_lOnBits(16) = 131071      ' 00000000000000011111111111111111
  305.    m_lOnBits(17) = 262143      ' 00000000000000111111111111111111
  306.    m_lOnBits(18) = 524287      ' 00000000000001111111111111111111
  307.    m_lOnBits(19) = 1048575     ' 00000000000011111111111111111111
  308.    m_lOnBits(20) = 2097151     ' 00000000000111111111111111111111
  309.    m_lOnBits(21) = 4194303     ' 00000000001111111111111111111111
  310.    m_lOnBits(22) = 8388607     ' 00000000011111111111111111111111
  311.    m_lOnBits(23) = 16777215    ' 00000000111111111111111111111111
  312.    m_lOnBits(24) = 33554431    ' 00000001111111111111111111111111
  313.    m_lOnBits(25) = 67108863    ' 00000011111111111111111111111111
  314.    m_lOnBits(26) = 134217727   ' 00000111111111111111111111111111
  315.    m_lOnBits(27) = 268435455   ' 00001111111111111111111111111111
  316.    m_lOnBits(28) = 536870911   ' 00011111111111111111111111111111
  317.    m_lOnBits(29) = 1073741823  ' 00111111111111111111111111111111
  318.    m_lOnBits(30) = 2147483647  ' 01111111111111111111111111111111
  319.    
  320.     ' Could have done this with a loop calculating each value, but simply
  321.    ' assigning the values is quicker - POWERS OF 2
  322.    m_l2Power(0) = 1            ' 00000000000000000000000000000001
  323.    m_l2Power(1) = 2            ' 00000000000000000000000000000010
  324.    m_l2Power(2) = 4            ' 00000000000000000000000000000100
  325.    m_l2Power(3) = 8            ' 00000000000000000000000000001000
  326.    m_l2Power(4) = 16           ' 00000000000000000000000000010000
  327.    m_l2Power(5) = 32           ' 00000000000000000000000000100000
  328.    m_l2Power(6) = 64           ' 00000000000000000000000001000000
  329.    m_l2Power(7) = 128          ' 00000000000000000000000010000000
  330.    m_l2Power(8) = 256          ' 00000000000000000000000100000000
  331.    m_l2Power(9) = 512          ' 00000000000000000000001000000000
  332.    m_l2Power(10) = 1024        ' 00000000000000000000010000000000
  333.    m_l2Power(11) = 2048        ' 00000000000000000000100000000000
  334.    m_l2Power(12) = 4096        ' 00000000000000000001000000000000
  335.    m_l2Power(13) = 8192        ' 00000000000000000010000000000000
  336.    m_l2Power(14) = 16384       ' 00000000000000000100000000000000
  337.    m_l2Power(15) = 32768       ' 00000000000000001000000000000000
  338.    m_l2Power(16) = 65536       ' 00000000000000010000000000000000
  339.    m_l2Power(17) = 131072      ' 00000000000000100000000000000000
  340.    m_l2Power(18) = 262144      ' 00000000000001000000000000000000
  341.    m_l2Power(19) = 524288      ' 00000000000010000000000000000000
  342.    m_l2Power(20) = 1048576     ' 00000000000100000000000000000000
  343.    m_l2Power(21) = 2097152     ' 00000000001000000000000000000000
  344.    m_l2Power(22) = 4194304     ' 00000000010000000000000000000000
  345.    m_l2Power(23) = 8388608     ' 00000000100000000000000000000000
  346.    m_l2Power(24) = 16777216    ' 00000001000000000000000000000000
  347.    m_l2Power(25) = 33554432    ' 00000010000000000000000000000000
  348.    m_l2Power(26) = 67108864    ' 00000100000000000000000000000000
  349.    m_l2Power(27) = 134217728   ' 00001000000000000000000000000000
  350.    m_l2Power(28) = 268435456   ' 00010000000000000000000000000000
  351.    m_l2Power(29) = 536870912   ' 00100000000000000000000000000000
  352.    m_l2Power(30) = 1073741824  ' 01000000000000000000000000000000
  353.    
  354.     ' NOTE: If you can guarantee that the Shift parameter will be in the
  355.    ' range 1 to 30 you can safely strip of this first nested if structure for
  356.    ' speed.
  357.    '
  358.    ' A shift of zero is no shift at all
  359.    If iShiftBits = 0 Then
  360.         RShift = lValue
  361.         Exit Function
  362.        
  363.     ' A shift of 31 will clear all bits and move the left most bit to the right
  364.    ' most bit position
  365.    ElseIf iShiftBits = 31 Then
  366.         If lValue And &H80000000 Then
  367.             RShift = 1
  368.         Else
  369.             RShift = 0
  370.         End If
  371.         Exit Function
  372.        
  373.     ' A shift of less than zero or more than 31 is undefined
  374.    ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  375.         Err.Raise 6
  376.     End If
  377.    
  378.     ' We do not care about the top most bit or the final bit, the top most bit
  379.    ' will be taken into account in the next stage, the final bit (whether it
  380.    ' is an odd number or not) is being shifted into, so we do not give a jot
  381.    ' about it
  382.    RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
  383.    
  384.     ' If the top most bit (&H80000000) was set we need to do things differently
  385.    ' as in a normal VB signed long integer the top most bit is used to indicate
  386.    ' the sign of the number, when it is set it is a negative number, so just
  387.    ' deviding by a factor of 2 as above would not work.
  388.    ' NOTE: (lValue And  &H80000000) is equivalent to (lValue < 0), you could
  389.    ' get a very marginal speed improvement by changing the test to (lValue < 0)
  390.    If (lValue And &H80000000) Then
  391.         ' We take the value computed so far, and then add the left most negative
  392.        ' bit after it has been shifted to the right the appropriate number of
  393.        ' places
  394.        RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
  395.     End If
  396. End Function
  397.  
  398. '*******************************************************************************
  399. ' RShiftSigned (FUNCTION)
  400. '
  401. ' PARAMETERS:
  402. ' (In) - lValue     - Long    -
  403. ' (In) - iShiftBits - Integer -
  404. '
  405. ' RETURN VALUE:
  406. ' Long -
  407. '
  408. ' DESCRIPTION:
  409. ' The right shift of a signed long integer involves shifting all the set bits to
  410. ' the right and in-filling on the left with the sign bit (0 if positive, 1 if
  411. ' negative. This function is equivalent to the >> operator in Java or the >>
  412. ' operator in C++ when used on a signed long integer. Not used in this class,
  413. ' but included for completeness.
  414. '*******************************************************************************
  415. Private Function RShiftSigned(ByVal lValue As Long, _
  416.                               ByVal iShiftBits As Integer) As Long
  417.     m_lOnBits(0) = 1            ' 00000000000000000000000000000001
  418.    m_lOnBits(1) = 3            ' 00000000000000000000000000000011
  419.    m_lOnBits(2) = 7            ' 00000000000000000000000000000111
  420.    m_lOnBits(3) = 15           ' 00000000000000000000000000001111
  421.    m_lOnBits(4) = 31           ' 00000000000000000000000000011111
  422.    m_lOnBits(5) = 63           ' 00000000000000000000000000111111
  423.    m_lOnBits(6) = 127          ' 00000000000000000000000001111111
  424.    m_lOnBits(7) = 255          ' 00000000000000000000000011111111
  425.    m_lOnBits(8) = 511          ' 00000000000000000000000111111111
  426.    m_lOnBits(9) = 1023         ' 00000000000000000000001111111111
  427.    m_lOnBits(10) = 2047        ' 00000000000000000000011111111111
  428.    m_lOnBits(11) = 4095        ' 00000000000000000000111111111111
  429.    m_lOnBits(12) = 8191        ' 00000000000000000001111111111111
  430.    m_lOnBits(13) = 16383       ' 00000000000000000011111111111111
  431.    m_lOnBits(14) = 32767       ' 00000000000000000111111111111111
  432.    m_lOnBits(15) = 65535       ' 00000000000000001111111111111111
  433.    m_lOnBits(16) = 131071      ' 00000000000000011111111111111111
  434.    m_lOnBits(17) = 262143      ' 00000000000000111111111111111111
  435.    m_lOnBits(18) = 524287      ' 00000000000001111111111111111111
  436.    m_lOnBits(19) = 1048575     ' 00000000000011111111111111111111
  437.    m_lOnBits(20) = 2097151     ' 00000000000111111111111111111111
  438.    m_lOnBits(21) = 4194303     ' 00000000001111111111111111111111
  439.    m_lOnBits(22) = 8388607     ' 00000000011111111111111111111111
  440.    m_lOnBits(23) = 16777215    ' 00000000111111111111111111111111
  441.    m_lOnBits(24) = 33554431    ' 00000001111111111111111111111111
  442.    m_lOnBits(25) = 67108863    ' 00000011111111111111111111111111
  443.    m_lOnBits(26) = 134217727   ' 00000111111111111111111111111111
  444.    m_lOnBits(27) = 268435455   ' 00001111111111111111111111111111
  445.    m_lOnBits(28) = 536870911   ' 00011111111111111111111111111111
  446.    m_lOnBits(29) = 1073741823  ' 00111111111111111111111111111111
  447.    m_lOnBits(30) = 2147483647  ' 01111111111111111111111111111111
  448.    
  449.     ' Could have done this with a loop calculating each value, but simply
  450.    ' assigning the values is quicker - POWERS OF 2
  451.    m_l2Power(0) = 1            ' 00000000000000000000000000000001
  452.    m_l2Power(1) = 2            ' 00000000000000000000000000000010
  453.    m_l2Power(2) = 4            ' 00000000000000000000000000000100
  454.    m_l2Power(3) = 8            ' 00000000000000000000000000001000
  455.    m_l2Power(4) = 16           ' 00000000000000000000000000010000
  456.    m_l2Power(5) = 32           ' 00000000000000000000000000100000
  457.    m_l2Power(6) = 64           ' 00000000000000000000000001000000
  458.    m_l2Power(7) = 128          ' 00000000000000000000000010000000
  459.    m_l2Power(8) = 256          ' 00000000000000000000000100000000
  460.    m_l2Power(9) = 512          ' 00000000000000000000001000000000
  461.    m_l2Power(10) = 1024        ' 00000000000000000000010000000000
  462.    m_l2Power(11) = 2048        ' 00000000000000000000100000000000
  463.    m_l2Power(12) = 4096        ' 00000000000000000001000000000000
  464.    m_l2Power(13) = 8192        ' 00000000000000000010000000000000
  465.    m_l2Power(14) = 16384       ' 00000000000000000100000000000000
  466.    m_l2Power(15) = 32768       ' 00000000000000001000000000000000
  467.    m_l2Power(16) = 65536       ' 00000000000000010000000000000000
  468.    m_l2Power(17) = 131072      ' 00000000000000100000000000000000
  469.    m_l2Power(18) = 262144      ' 00000000000001000000000000000000
  470.    m_l2Power(19) = 524288      ' 00000000000010000000000000000000
  471.    m_l2Power(20) = 1048576     ' 00000000000100000000000000000000
  472.    m_l2Power(21) = 2097152     ' 00000000001000000000000000000000
  473.    m_l2Power(22) = 4194304     ' 00000000010000000000000000000000
  474.    m_l2Power(23) = 8388608     ' 00000000100000000000000000000000
  475.    m_l2Power(24) = 16777216    ' 00000001000000000000000000000000
  476.    m_l2Power(25) = 33554432    ' 00000010000000000000000000000000
  477.    m_l2Power(26) = 67108864    ' 00000100000000000000000000000000
  478.    m_l2Power(27) = 134217728   ' 00001000000000000000000000000000
  479.    m_l2Power(28) = 268435456   ' 00010000000000000000000000000000
  480.    m_l2Power(29) = 536870912   ' 00100000000000000000000000000000
  481.    m_l2Power(30) = 1073741824  ' 01000000000000000000000000000000
  482.    ' NOTE: If you can guarantee that the Shift parameter will be in the
  483.    ' range 1 to 30 you can safely strip of this first nested if structure for
  484.    ' speed.
  485.    '
  486.    ' A shift of zero is no shift at all
  487.    If iShiftBits = 0 Then
  488.         RShiftSigned = lValue
  489.         Exit Function
  490.    
  491.     ' A shift of 31 will clear all bits if the left most bit was zero, and will
  492.    ' set all bits if the left most bit was 1 (a negative indicator)
  493.    ElseIf iShiftBits = 31 Then
  494.        
  495.         ' NOTE: (lValue And  &H80000000) is equivalent to (lValue < 0), you
  496.        ' could get a very marginal speed improvement by changing the test to
  497.        ' (lValue < 0)
  498.        If (lValue And &H80000000) Then
  499.             RShiftSigned = -1
  500.         Else
  501.             RShiftSigned = 0
  502.         End If
  503.         Exit Function
  504.    
  505.     ' A shift of less than zero or more than 31 is undefined
  506.    ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  507.         Err.Raise 6
  508.     End If
  509.    
  510.     ' We get the same result by dividing by the appropriate power of 2 and
  511.    ' rounding in the negative direction
  512.    RShiftSigned = Int(lValue / m_l2Power(iShiftBits))
  513. End Function
  514.  
  515. '*******************************************************************************
  516. ' RotateLeft (FUNCTION)
  517. '
  518. ' PARAMETERS:
  519. ' (In) - lValue     - Long    - Value to act on
  520. ' (In) - iShiftBits - Integer - Bits to move by
  521. '
  522. ' RETURN VALUE:
  523. ' Long - Result
  524. '
  525. ' DESCRIPTION:
  526. ' Rotates the bits in a long integer to the left, those bits falling off the
  527. ' left edge are put back on the right edge
  528. '*******************************************************************************
  529. Private Function RotateLeft(ByVal lValue As Long, _
  530.                             ByVal iShiftBits As Integer) As Long
  531.     RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
  532. End Function
  533.  
  534. '*******************************************************************************
  535. ' AddUnsigned (FUNCTION)
  536. '
  537. ' PARAMETERS:
  538. ' (In) - lX - Long - First value
  539. ' (In) - lY - Long - Second value
  540. '
  541. ' RETURN VALUE:
  542. ' Long - Result
  543. '
  544. ' DESCRIPTION:
  545. ' Adds two potentially large unsigned numbers without overflowing
  546. '*******************************************************************************
  547. Private Function AddUnsigned(ByVal lX As Long, _
  548.                              ByVal lY As Long) As Long
  549.     Dim lX4     As Long
  550.     Dim lY4     As Long
  551.     Dim lX8     As Long
  552.     Dim lY8     As Long
  553.     Dim lResult As Long
  554.  
  555.     lX8 = lX And &H80000000
  556.     lY8 = lY And &H80000000
  557.     lX4 = lX And &H40000000
  558.     lY4 = lY And &H40000000
  559.  
  560.     lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
  561.  
  562.     If lX4 And lY4 Then
  563.         lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
  564.     ElseIf lX4 Or lY4 Then
  565.         If lResult And &H40000000 Then
  566.             lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
  567.         Else
  568.             lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
  569.         End If
  570.     Else
  571.         lResult = lResult Xor lX8 Xor lY8
  572.     End If
  573.  
  574.     AddUnsigned = lResult
  575. End Function
  576.  
  577. '*******************************************************************************
  578. ' F (FUNCTION)
  579. '
  580. ' DESCRIPTION:
  581. ' MD5's F function
  582. '*******************************************************************************
  583. Private Function F(ByVal x As Long, _
  584.                    ByVal y As Long, _
  585.                    ByVal z As Long) As Long
  586.     F = (x And y) Or ((Not x) And z)
  587. End Function
  588.  
  589. '*******************************************************************************
  590. ' G (FUNCTION)
  591. '
  592. ' DESCRIPTION:
  593. ' MD5's G function
  594. '*******************************************************************************
  595. Private Function G(ByVal x As Long, _
  596.                    ByVal y As Long, _
  597.                    ByVal z As Long) As Long
  598.     G = (x And z) Or (y And (Not z))
  599. End Function
  600.  
  601. '*******************************************************************************
  602. ' H (FUNCTION)
  603. '
  604. ' DESCRIPTION:
  605. ' MD5's H function
  606. '*******************************************************************************
  607. Private Function H(ByVal x As Long, _
  608.                    ByVal y As Long, _
  609.                    ByVal z As Long) As Long
  610.     H = (x Xor y Xor z)
  611. End Function
  612.  
  613. '*******************************************************************************
  614. ' I (FUNCTION)
  615. '
  616. ' DESCRIPTION:
  617. ' MD5's I function
  618. '*******************************************************************************
  619. Private Function i(ByVal x As Long, _
  620.                    ByVal y As Long, _
  621.                    ByVal z As Long) As Long
  622.     i = (y Xor (x Or (Not z)))
  623. End Function
  624.  
  625. '*******************************************************************************
  626. ' FF (SUB)
  627. '
  628. ' DESCRIPTION:
  629. ' MD5's FF procedure
  630. '*******************************************************************************
  631. Private Sub FF(a As Long, _
  632.                ByVal b As Long, _
  633.                ByVal c As Long, _
  634.                ByVal d As Long, _
  635.                ByVal x As Long, _
  636.                ByVal s As Long, _
  637.                ByVal ac As Long)
  638.     a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac))
  639.     a = RotateLeft(a, s)
  640.     a = AddUnsigned(a, b)
  641. End Sub
  642.  
  643. '*******************************************************************************
  644. ' GG (SUB)
  645. '
  646. ' DESCRIPTION:
  647. ' MD5's GG procedure
  648. '*******************************************************************************
  649. Private Sub GG(a As Long, _
  650.                ByVal b As Long, _
  651.                ByVal c As Long, _
  652.                ByVal d As Long, _
  653.                ByVal x As Long, _
  654.                ByVal s As Long, _
  655.                ByVal ac As Long)
  656.     a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac))
  657.     a = RotateLeft(a, s)
  658.     a = AddUnsigned(a, b)
  659. End Sub
  660.  
  661. '*******************************************************************************
  662. ' HH (SUB)
  663. '
  664. ' DESCRIPTION:
  665. ' MD5's HH procedure
  666. '*******************************************************************************
  667. Private Sub HH(a As Long, _
  668.                ByVal b As Long, _
  669.                ByVal c As Long, _
  670.                ByVal d As Long, _
  671.                ByVal x As Long, _
  672.                ByVal s As Long, _
  673.                ByVal ac As Long)
  674.     a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac))
  675.     a = RotateLeft(a, s)
  676.     a = AddUnsigned(a, b)
  677. End Sub
  678.  
  679. '*******************************************************************************
  680. ' II (SUB)
  681. '
  682. ' DESCRIPTION:
  683. ' MD5's II procedure
  684. '*******************************************************************************
  685. Private Sub II(a As Long, _
  686.                ByVal b As Long, _
  687.                ByVal c As Long, _
  688.                ByVal d As Long, _
  689.                ByVal x As Long, _
  690.                ByVal s As Long, _
  691.                ByVal ac As Long)
  692.     a = AddUnsigned(a, AddUnsigned(AddUnsigned(i(b, c, d), x), ac))
  693.     a = RotateLeft(a, s)
  694.     a = AddUnsigned(a, b)
  695. End Sub
  696.  
  697. '*******************************************************************************
  698. ' ConvertToWordArray (FUNCTION)
  699. '
  700. ' PARAMETERS:
  701. ' (In/Out) - sMessage - String - String message
  702. '
  703. ' RETURN VALUE:
  704. ' Long() - Converted message as long array
  705. '
  706. ' DESCRIPTION:
  707. ' Takes the string message and puts it in a long array with padding according to
  708. ' the MD5 rules.
  709. '*******************************************************************************
  710. Private Function ConvertToWordArray(sMessage As String) As Long()
  711.     Dim lMessageLength  As Long
  712.     Dim lNumberOfWords  As Long
  713.     Dim lWordArray()    As Long
  714.     Dim lBytePosition   As Long
  715.     Dim lByteCount      As Long
  716.     Dim lWordCount      As Long
  717.    
  718.     Const MODULUS_BITS      As Long = 512
  719.     Const CONGRUENT_BITS    As Long = 448
  720.    
  721.     lMessageLength = Len(sMessage)
  722.    
  723.     ' Get padded number of words. Message needs to be congruent to 448 bits,
  724.    ' modulo 512 bits. If it is exactly congruent to 448 bits, modulo 512 bits
  725.    ' it must still have another 512 bits added. 512 bits = 64 bytes
  726.    ' (or 16 * 4 byte words), 448 bits = 56 bytes. This means lMessageSize must
  727.    ' be a multiple of 16 (i.e. 16 * 4 (bytes) * 8 (bits))
  728.    lNumberOfWords = (((lMessageLength + _
  729.         ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ _
  730.         (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * _
  731.         (MODULUS_BITS \ BITS_TO_A_WORD)
  732.     ReDim lWordArray(lNumberOfWords - 1)
  733.    
  734.     ' Combine each block of 4 bytes (ascii code of character) into one long
  735.    ' value and store in the message. The high-order (most significant) bit of
  736.    ' each byte is listed first. However, the low-order (least significant) byte
  737.    ' is given first in each word.
  738.    lBytePosition = 0
  739.     lByteCount = 0
  740.     Do Until lByteCount >= lMessageLength
  741.         ' Each word is 4 bytes
  742.        lWordCount = lByteCount \ BYTES_TO_A_WORD
  743.        
  744.         ' The bytes are put in the word from the right most edge
  745.        lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
  746.         lWordArray(lWordCount) = lWordArray(lWordCount) Or _
  747.             LShift(AscB(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
  748.         lByteCount = lByteCount + 1
  749.     Loop
  750.  
  751.     ' Terminate according to MD5 rules with a 1 bit, zeros and the length in
  752.    ' bits stored in the last two words
  753.    lWordCount = lByteCount \ BYTES_TO_A_WORD
  754.     lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
  755.  
  756.     ' Add a terminating 1 bit, all the rest of the bits to the end of the
  757.    ' word array will default to zero
  758.    lWordArray(lWordCount) = lWordArray(lWordCount) Or _
  759.         LShift(&H80, lBytePosition)
  760.  
  761.     ' We put the length of the message in bits into the last two words, to get
  762.    ' the length in bits we need to multiply by 8 (or left shift 3). This left
  763.    ' shifted value is put in the first word. Any bits shifted off the left edge
  764.    ' need to be put in the second word, we can work out which bits by shifting
  765.    ' right the length by 29 bits.
  766.    lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
  767.     lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
  768.    
  769.     ConvertToWordArray = lWordArray
  770. End Function
  771.  
  772. '*******************************************************************************
  773. ' WordToHex (FUNCTION)
  774. '
  775. ' PARAMETERS:
  776. ' (In) - lValue - Long - Long value to convert
  777. '
  778. ' RETURN VALUE:
  779. ' String - Hex value to return
  780. '
  781. ' DESCRIPTION:
  782. ' Takes a long integer and due to the bytes reverse order it extracts the
  783. ' individual bytes and converts them to hex appending them for an overall hex
  784. ' value
  785. '*******************************************************************************
  786. Private Function WordToHex(ByVal lValue As Long) As String
  787.     Dim lByte As Long
  788.     Dim lCount As Long
  789.    
  790.     For lCount = 0 To 3
  791.         lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And _
  792.             m_lOnBits(BITS_TO_A_BYTE - 1)
  793.         WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
  794.     Next
  795. End Function
  796.  
  797. '*******************************************************************************
  798. ' MD5 (FUNCTION)
  799. '
  800. ' PARAMETERS:
  801. ' (In/Out) - sMessage - String - String to be digested
  802. '
  803. ' RETURN VALUE:
  804. ' String - The MD5 digest
  805. '
  806. ' DESCRIPTION:
  807. ' This function takes a string message and generates an MD5 digest for it.
  808. ' sMessage can be up to the VB string length limit of 2^31 (approx. 2 billion)
  809. ' characters.
  810. '
  811. ' NOTE: Due to the way in which the string is processed the routine assumes a
  812. ' single byte character set. VB passes unicode (2-byte) character strings, the
  813. ' ConvertToWordArray function uses on the first byte for each character. This
  814. ' has been done this way for ease of use, to make the routine truely portable
  815. ' you could accept a byte array instead, it would then be up to the calling
  816. ' routine to make sure that the byte array is generated from their string in
  817. ' a manner consistent with the string type.
  818. '*******************************************************************************
  819. Public Function MD5(sMessage As String) As String
  820.     Dim x() As Long
  821.     Dim k   As Long
  822.     Dim AA  As Long
  823.     Dim BB  As Long
  824.     Dim CC  As Long
  825.     Dim DD  As Long
  826.     Dim a   As Long
  827.     Dim b   As Long
  828.     Dim c   As Long
  829.     Dim d   As Long
  830.    
  831.     Const S11 As Long = 7
  832.     Const S12 As Long = 12
  833.     Const S13 As Long = 17
  834.     Const S14 As Long = 22
  835.     Const S21 As Long = 5
  836.     Const S22 As Long = 9
  837.     Const S23 As Long = 14
  838.     Const S24 As Long = 20
  839.     Const S31 As Long = 4
  840.     Const S32 As Long = 11
  841.     Const S33 As Long = 16
  842.     Const S34 As Long = 23
  843.     Const S41 As Long = 6
  844.     Const S42 As Long = 10
  845.     Const S43 As Long = 15
  846.     Const S44 As Long = 21
  847.  
  848.     ' Steps 1 and 2.  Append padding bits and length and convert to words
  849.    x = ConvertToWordArray(sMessage)
  850.    
  851.     ' Step 3.  Initialise
  852.    a = &H67452301
  853.     b = &HEFCDAB89
  854.     c = &H98BADCFE
  855.     d = &H10325476
  856.  
  857.     ' Step 4.  Process the message in 16-word blocks
  858.    For k = 0 To UBound(x) Step 16
  859.         AA = a
  860.         BB = b
  861.         CC = c
  862.         DD = d
  863.    
  864.         ' The hex number on the end of each of the following procedure calls is
  865.        ' an element from the 64 element table constructed with
  866.        ' T(i) = Int(4294967296 * Abs(Sin(i))) where i is 1 to 64.
  867.        '
  868.        ' However, for speed we don't want to calculate the value every time.
  869.        FF a, b, c, d, x(k + 0), S11, &HD76AA478
  870.         FF d, a, b, c, x(k + 1), S12, &HE8C7B756
  871.         FF c, d, a, b, x(k + 2), S13, &H242070DB
  872.         FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
  873.         FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
  874.         FF d, a, b, c, x(k + 5), S12, &H4787C62A
  875.         FF c, d, a, b, x(k + 6), S13, &HA8304613
  876.         FF b, c, d, a, x(k + 7), S14, &HFD469501
  877.         FF a, b, c, d, x(k + 8), S11, &H698098D8
  878.         FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
  879.         FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
  880.         FF b, c, d, a, x(k + 11), S14, &H895CD7BE
  881.         FF a, b, c, d, x(k + 12), S11, &H6B901122
  882.         FF d, a, b, c, x(k + 13), S12, &HFD987193
  883.         FF c, d, a, b, x(k + 14), S13, &HA679438E
  884.         FF b, c, d, a, x(k + 15), S14, &H49B40821
  885.    
  886.         GG a, b, c, d, x(k + 1), S21, &HF61E2562
  887.         GG d, a, b, c, x(k + 6), S22, &HC040B340
  888.         GG c, d, a, b, x(k + 11), S23, &H265E5A51
  889.         GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA
  890.         GG a, b, c, d, x(k + 5), S21, &HD62F105D
  891.         GG d, a, b, c, x(k + 10), S22, &H2441453
  892.         GG c, d, a, b, x(k + 15), S23, &HD8A1E681
  893.         GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8
  894.         GG a, b, c, d, x(k + 9), S21, &H21E1CDE6
  895.         GG d, a, b, c, x(k + 14), S22, &HC33707D6
  896.         GG c, d, a, b, x(k + 3), S23, &HF4D50D87
  897.         GG b, c, d, a, x(k + 8), S24, &H455A14ED
  898.         GG a, b, c, d, x(k + 13), S21, &HA9E3E905
  899.         GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8
  900.         GG c, d, a, b, x(k + 7), S23, &H676F02D9
  901.         GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A
  902.            
  903.         HH a, b, c, d, x(k + 5), S31, &HFFFA3942
  904.         HH d, a, b, c, x(k + 8), S32, &H8771F681
  905.         HH c, d, a, b, x(k + 11), S33, &H6D9D6122
  906.         HH b, c, d, a, x(k + 14), S34, &HFDE5380C
  907.         HH a, b, c, d, x(k + 1), S31, &HA4BEEA44
  908.         HH d, a, b, c, x(k + 4), S32, &H4BDECFA9
  909.         HH c, d, a, b, x(k + 7), S33, &HF6BB4B60
  910.         HH b, c, d, a, x(k + 10), S34, &HBEBFBC70
  911.         HH a, b, c, d, x(k + 13), S31, &H289B7EC6
  912.         HH d, a, b, c, x(k + 0), S32, &HEAA127FA
  913.         HH c, d, a, b, x(k + 3), S33, &HD4EF3085
  914.         HH b, c, d, a, x(k + 6), S34, &H4881D05
  915.         HH a, b, c, d, x(k + 9), S31, &HD9D4D039
  916.         HH d, a, b, c, x(k + 12), S32, &HE6DB99E5
  917.         HH c, d, a, b, x(k + 15), S33, &H1FA27CF8
  918.         HH b, c, d, a, x(k + 2), S34, &HC4AC5665
  919.    
  920.         II a, b, c, d, x(k + 0), S41, &HF4292244
  921.         II d, a, b, c, x(k + 7), S42, &H432AFF97
  922.         II c, d, a, b, x(k + 14), S43, &HAB9423A7
  923.         II b, c, d, a, x(k + 5), S44, &HFC93A039
  924.         II a, b, c, d, x(k + 12), S41, &H655B59C3
  925.         II d, a, b, c, x(k + 3), S42, &H8F0CCC92
  926.         II c, d, a, b, x(k + 10), S43, &HFFEFF47D
  927.         II b, c, d, a, x(k + 1), S44, &H85845DD1
  928.         II a, b, c, d, x(k + 8), S41, &H6FA87E4F
  929.         II d, a, b, c, x(k + 15), S42, &HFE2CE6E0
  930.         II c, d, a, b, x(k + 6), S43, &HA3014314
  931.         II b, c, d, a, x(k + 13), S44, &H4E0811A1
  932.         II a, b, c, d, x(k + 4), S41, &HF7537E82
  933.         II d, a, b, c, x(k + 11), S42, &HBD3AF235
  934.         II c, d, a, b, x(k + 2), S43, &H2AD7D2BB
  935.         II b, c, d, a, x(k + 9), S44, &HEB86D391
  936.    
  937.         a = AddUnsigned(a, AA)
  938.         b = AddUnsigned(b, BB)
  939.         c = AddUnsigned(c, CC)
  940.         d = AddUnsigned(d, DD)
  941.     Next
  942.    
  943.     ' Step 5.  Output the 128 bit digest
  944.    MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
  945. End Function
  946.  
  947. Public Sub askmd5()
  948.     Dim ttt As String, ttt2 As String, i As Long
  949.     'ttt = InputBox("wtf")
  950.    MsgBox MD5("ÒÅÐì10-03-001-02Ñòîéêà, ïîëóñòîéêà, êàðêàñ ñòîéêè èëè øêàô, ìàññà, êã äî 300 (øêàô 47U)")
  951.     MsgBox MD5("ÒÅÐì10-03-001-02Ñòîéêà, ïîëóñòîéêà, êàðêàñ ñòîéêè èëè øêàô, ìàññà, êã äî 300 (Øêàô 47U)")
  952.    
  953.     ttt = "ÒÅÐì10-03-001-02Ñòîéêà, ïîëóñòîéêà, êàðêàñ ñòîéêè èëè øêàô, ìàññà, êã äî 300 (øêàô 47U)"
  954.     ttt2 = "ÒÅÐì10-03-001-02Ñòîéêà, ïîëóñòîéêà, êàðêàñ ñòîéêè èëè øêàô, ìàññà, êã äî 300 (Øêàô 47U)"
  955.    
  956.     For i = 1 To Len(ttt)
  957.         If Mid(ttt, i, 1) <> Mid(ttt2, i, 1) Then
  958.             MsgBox i & ": " & Mid(ttt, i, 1) & " " & Mid(ttt2, i, 1)
  959.         End If
  960.     Next i
  961. End Sub
  962.  
  963. Public Sub recalcmd5()
  964.     Dim tt As String
  965.     Dim tcell As Range
  966.     For Each tcell In Selection.Cells
  967.         tt = ActiveSheet.Cells(tcell.Row, 2).Value & ActiveSheet.Cells(tcell.Row, 3).Value
  968.         tt = UCase(tt)
  969.         tcell.Value = MD5(tt)
  970.     Next tcell
  971. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement