Advertisement
unbanked

shaVBS

Apr 15th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Author Unknown by me
  2. Function SHA(ByVal sMessage)
  3.      Dim i, result(32), temp(8) As Double, fraccubeprimes, hashValues
  4.      Dim done512, index512, words(64) As Double, index32, mask(4)
  5.      Dim s0, s1, t1, t2, maj, ch, strLen
  6.  
  7.      mask(0) = 4294967296#
  8.      mask(1) = 16777216
  9.      mask(2) = 65536
  10.      mask(3) = 256
  11.  
  12.      hashValues = Array( _
  13.          1779033703, 3144134277#, 1013904242, 2773480762#, _
  14.          1359893119, 2600822924#, 528734635, 1541459225)
  15.  
  16.      fraccubeprimes = Array( _
  17.          1116352408, 1899447441, 3049323471#, 3921009573#, 961987163, 1508970993, 2453635748#, 2870763221#, _
  18.          3624381080#, 310598401, 607225278, 1426881987, 1925078388, 2162078206#, 2614888103#, 3248222580#, _
  19.          3835390401#, 4022224774#, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, _
  20.          2554220882#, 2821834349#, 2952996808#, 3210313671#, 3336571891#, 3584528711#, 113926993, 338241895, _
  21.          666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350#, 2456956037#, _
  22.          2730485921#, 2820302411#, 3259730800#, 3345764771#, 3516065817#, 3600352804#, 4094571909#, 275423344, _
  23.          430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, _
  24.          1955562222, 2024104815, 2227730452#, 2361852424#, 2428436474#, 2756734187#, 3204031479#, 3329325298#)
  25.  
  26.      sMessage = Nz(sMessage, "")
  27.      strLen = Len(sMessage) * 8
  28.      sMessage = sMessage & Chr(128)
  29.      done512 = False
  30.      index512 = 0
  31.  
  32. 31.     If (Len(sMessage) Mod 64) < 56 Then
  33. 32.         sMessage = sMessage & String(56 - (Len(sMessage) Mod 64), Chr(0))
  34. 33.     ElseIf (Len(sMessage) Mod 64) > 56 Then
  35. 34.         sMessage = sMessage & String(120 - (Len(sMessage) Mod 64), Chr(0))
  36. 35.     End If
  37. 36.     sMessage = sMessage & Chr(0) & Chr(0) & Chr(0) & Chr(0)
  38. 37.
  39. 38.     sMessage = sMessage & Chr(Int((strLen / mask(0) - Int(strLen / mask(0))) * 256))
  40. 39.     sMessage = sMessage & Chr(Int((strLen / mask(1) - Int(strLen / mask(1))) * 256))
  41. 40.     sMessage = sMessage & Chr(Int((strLen / mask(2) - Int(strLen / mask(2))) * 256))
  42. 41.     sMessage = sMessage & Chr(Int((strLen / mask(3) - Int(strLen / mask(3))) * 256))
  43. 42.
  44. 43.     Do Until done512
  45. 44.         For i = 0 To 15
  46. 45.             words(i) = Asc(Mid(sMessage, index512 * 64 + i * 4 + 1, 1)) * mask(1) + Asc(Mid(sMessage, index512 * 64 + i * 4 + 2, 1)) * mask(2) + Asc(Mid(sMessage, index512 * 64 + i * 4 + 3, 1)) * mask(3) + Asc(Mid(sMessage, index512 * 64 + i * 4 + 4, 1))
  47. 46.         Next
  48. 47.
  49. 48.         For i = 16 To 63
  50. 49.             s0 = largeXor(largeXor(rightRotate(words(i - 15), 7, 32), rightRotate(words(i - 15), 18, 32), 32), Int(words(i - 15) / 8), 32)
  51. 50.             s1 = largeXor(largeXor(rightRotate(words(i - 2), 17, 32), rightRotate(words(i - 2), 19, 32), 32), Int(words(i - 2) / 1024), 32)
  52. 51.             words(i) = Mod32Bit(words(i - 16) + s0 + words(i - 7) + s1)
  53. 52.         Next
  54. 53.
  55. 54.         For i = 0 To 7
  56. 55.             temp(i) = hashValues(i)
  57. 56.         Next
  58. 57.
  59. 58.         For i = 0 To 63
  60. 59.             s0 = largeXor(largeXor(rightRotate(temp(0), 2, 32), rightRotate(temp(0), 13, 32), 32), rightRotate(temp(0), 22, 32), 32)
  61. 60.             maj = largeXor(largeXor(largeAnd(temp(0), temp(1), 32), largeAnd(temp(0), temp(2), 32), 32), largeAnd(temp(1), temp(2), 32), 32)
  62. 61.             t2 = Mod32Bit(s0 + maj)
  63. 62.             s1 = largeXor(largeXor(rightRotate(temp(4), 6, 32), rightRotate(temp(4), 11, 32), 32), rightRotate(temp(4), 25, 32), 32)
  64. 63.             ch = largeXor(largeAnd(temp(4), temp(5), 32), largeAnd(largeNot(temp(4), 32), temp(6), 32), 32)
  65. 64.             t1 = Mod32Bit(temp(7) + s1 + ch + fraccubeprimes(i) + words(i))
  66. 65.
  67. 66.             temp(7) = temp(6)
  68. 67.             temp(6) = temp(5)
  69. 68.             temp(5) = temp(4)
  70. 69.             temp(4) = Mod32Bit(temp(3) + t1)
  71. 70.             temp(3) = temp(2)
  72. 71.             temp(2) = temp(1)
  73. 72.             temp(1) = temp(0)
  74. 73.             temp(0) = Mod32Bit(t1 + t2)
  75. 74.         Next
  76. 75.
  77. 76.         For i = 0 To 7
  78. 77.             hashValues(i) = Mod32Bit(hashValues(i) + temp(i))
  79. 78.         Next
  80. 79.
  81. 80.         If (index512 + 1) * 64 >= Len(sMessage) Then done512 = True
  82. 81.         index512 = index512 + 1
  83. 82.     Loop
  84. 83.
  85. 84.     For i = 0 To 31
  86. 85.         result(i) = Int((hashValues(i \ 4) / mask(i Mod 4) - Int(hashValues(i \ 4) / mask(i Mod 4))) * 256)
  87. 86.     Next
  88. 87.
  89. 88.     SHA = result
  90. 89. End Function
  91. 90.
  92. 91. Function Mod32Bit(value)
  93. 92.     Mod32Bit = Int((value / 4294967296# - Int(value / 4294967296#)) * 4294967296#)
  94. 93. End Function
  95. 94.
  96. 95. Function rightRotate(value, amount, totalBits)
  97. 96.     'To leftRotate, make amount = totalBits - amount
  98. 97.     Dim i
  99. 98.     rightRotate = 0
  100. 99.
  101. 100.     For i = 0 To (totalBits - 1)
  102. 101.         If i >= amount Then
  103. 102.             rightRotate = rightRotate + (Int((value / (2 ^ (i + 1)) - Int(value / (2 ^ (i + 1)))) * 2)) * 2 ^ (i - amount)
  104. 103.         Else
  105. 104.             rightRotate = rightRotate + (Int((value / (2 ^ (i + 1)) - Int(value / (2 ^ (i + 1)))) * 2)) * 2 ^ (totalBits - amount + i)
  106. 105.         End If
  107. 106.     Next
  108. 107. End Function
  109. 108.
  110. 109. Function largeXor(value, xorValue, totalBits)
  111. 110.     Dim i, a, b
  112. 111.     largeXor = 0
  113. 112.
  114. 113.     For i = 0 To (totalBits - 1)
  115. 114.         a = (Int((value / (2 ^ (i + 1)) - Int(value / (2 ^ (i + 1)))) * 2))
  116. 115.         b = (Int((xorValue / (2 ^ (i + 1)) - Int(xorValue / (2 ^ (i + 1)))) * 2))
  117. 116.         If a <> b Then
  118. 117.             largeXor = largeXor + 2 ^ i
  119. 118.         End If
  120. 119.     Next
  121. 120. End Function
  122. 121.
  123. 122. Function largeNot(value, totalBits)
  124. 123.     Dim i, a
  125. 124.     largeNot = 0
  126. 125.
  127. 126.     For i = 0 To (totalBits - 1)
  128. 127.         a = Int((value / (2 ^ (i + 1)) - Int(value / (2 ^ (i + 1)))) * 2)
  129. 128.         If a = 0 Then
  130. 129.             largeNot = largeNot + 2 ^ i
  131. 130.         End If
  132. 131.     Next
  133. 132. End Function
  134. 133.
  135. 134. Function largeAnd(value, andValue, totalBits)
  136. 135.     Dim i, a, b
  137. 136.     largeAnd = 0
  138. 137.
  139. 138.     For i = 0 To (totalBits - 1)
  140. 139.         a = Int((value / (2 ^ (i + 1)) - Int(value / (2 ^ (i + 1)))) * 2)
  141. 140.         b = (Int((andValue / (2 ^ (i + 1)) - Int(andValue / (2 ^ (i + 1)))) * 2))
  142. 141.         If a = 1 And b = 1 Then
  143. 142.             largeAnd = largeAnd + 2 ^ i
  144. 143.         End If
  145. 144.     Next
  146. 145. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement