zjyong

zjyongde

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/31852/208667/zjyong.js

  1.  
  2. /* global define */
  3.  
  4. ;(function ($) {
  5. 'use strict'
  6.  
  7. /*
  8. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  9. * to work around bugs in some JS interpreters.
  10. */
  11. function safeAdd (x, y) {
  12. var lsw = (x & 0xFFFF) + (y & 0xFFFF)
  13. var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
  14. return (msw << 16) | (lsw & 0xFFFF)
  15. }
  16.  
  17. /*
  18. * Bitwise rotate a 32-bit number to the left.
  19. */
  20. function bitRotateLeft (num, cnt) {
  21. return (num << cnt) | (num >>> (32 - cnt))
  22. }
  23.  
  24. /*
  25. * These functions implement the four basic operations the algorithm uses.
  26. */
  27. function md5cmn (q, a, b, x, s, t) {
  28. return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b)
  29. }
  30. function md5ff (a, b, c, d, x, s, t) {
  31. return md5cmn((b & c) | ((~b) & d), a, b, x, s, t)
  32. }
  33. function md5gg (a, b, c, d, x, s, t) {
  34. return md5cmn((b & d) | (c & (~d)), a, b, x, s, t)
  35. }
  36. function md5hh (a, b, c, d, x, s, t) {
  37. return md5cmn(b ^ c ^ d, a, b, x, s, t)
  38. }
  39. function md5ii (a, b, c, d, x, s, t) {
  40. return md5cmn(c ^ (b | (~d)), a, b, x, s, t)
  41. }
  42.  
  43. /*
  44. * Calculate the MD5 of an array of little-endian words, and a bit length.
  45. */
  46. function binlMD5 (x, len) {
  47. /* append padding */
  48. x[len >> 5] |= 0x80 << (len % 32)
  49. x[(((len + 64) >>> 9) << 4) + 14] = len
  50.  
  51. var i
  52. var olda
  53. var oldb
  54. var oldc
  55. var oldd
  56. var a = 1732584193
  57. var b = -271733879
  58. var c = -1732584194
  59. var d = 271733878
  60.  
  61. for (i = 0; i < x.length; i += 16) {
  62. olda = a
  63. oldb = b
  64. oldc = c
  65. oldd = d
  66.  
  67. a = md5ff(a, b, c, d, x[i], 7, -680876936)
  68. d = md5ff(d, a, b, c, x[i + 1], 12, -389564586)
  69. c = md5ff(c, d, a, b, x[i + 2], 17, 606105819)
  70. b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330)
  71. a = md5ff(a, b, c, d, x[i + 4], 7, -176418897)
  72. d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426)
  73. c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341)
  74. b = md5ff(b, c, d, a, x[i + 7], 22, -45705983)
  75. a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416)
  76. d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417)
  77. c = md5ff(c, d, a, b, x[i + 10], 17, -42063)
  78. b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162)
  79. a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682)
  80. d = md5ff(d, a, b, c, x[i + 13], 12, -40341101)
  81. c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290)
  82. b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329)
  83.  
  84. a = md5gg(a, b, c, d, x[i + 1], 5, -165796510)
  85. d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632)
  86. c = md5gg(c, d, a, b, x[i + 11], 14, 643717713)
  87. b = md5gg(b, c, d, a, x[i], 20, -373897302)
  88. a = md5gg(a, b, c, d, x[i + 5], 5, -701558691)
  89. d = md5gg(d, a, b, c, x[i + 10], 9, 38016083)
  90. c = md5gg(c, d, a, b, x[i + 15], 14, -660478335)
  91. b = md5gg(b, c, d, a, x[i + 4], 20, -405537848)
  92. a = md5gg(a, b, c, d, x[i + 9], 5, 568446438)
  93. d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690)
  94. c = md5gg(c, d, a, b, x[i + 3], 14, -187363961)
  95. b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501)
  96. a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467)
  97. d = md5gg(d, a, b, c, x[i + 2], 9, -51403784)
  98. c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473)
  99. b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734)
  100.  
  101. a = md5hh(a, b, c, d, x[i + 5], 4, -378558)
  102. d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463)
  103. c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562)
  104. b = md5hh(b, c, d, a, x[i + 14], 23, -35309556)
  105. a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060)
  106. d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353)
  107. c = md5hh(c, d, a, b, x[i + 7], 16, -155497632)
  108. b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640)
  109. a = md5hh(a, b, c, d, x[i + 13], 4, 681279174)
  110. d = md5hh(d, a, b, c, x[i], 11, -358537222)
  111. c = md5hh(c, d, a, b, x[i + 3], 16, -722521979)
  112. b = md5hh(b, c, d, a, x[i + 6], 23, 76029189)
  113. a = md5hh(a, b, c, d, x[i + 9], 4, -640364487)
  114. d = md5hh(d, a, b, c, x[i + 12], 11, -421815835)
  115. c = md5hh(c, d, a, b, x[i + 15], 16, 530742520)
  116. b = md5hh(b, c, d, a, x[i + 2], 23, -995338651)
  117.  
  118. a = md5ii(a, b, c, d, x[i], 6, -198630844)
  119. d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415)
  120. c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905)
  121. b = md5ii(b, c, d, a, x[i + 5], 21, -57434055)
  122. a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571)
  123. d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606)
  124. c = md5ii(c, d, a, b, x[i + 10], 15, -1051523)
  125. b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799)
  126. a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359)
  127. d = md5ii(d, a, b, c, x[i + 15], 10, -30611744)
  128. c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380)
  129. b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649)
  130. a = md5ii(a, b, c, d, x[i + 4], 6, -145523070)
  131. d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379)
  132. c = md5ii(c, d, a, b, x[i + 2], 15, 718787259)
  133. b = md5ii(b, c, d, a, x[i + 9], 21, -343485551)
  134.  
  135. a = safeAdd(a, olda)
  136. b = safeAdd(b, oldb)
  137. c = safeAdd(c, oldc)
  138. d = safeAdd(d, oldd)
  139. }
  140. return [a, b, c, d]
  141. }
  142.  
  143. /*
  144. * Convert an array of little-endian words to a string
  145. */
  146. function binl2rstr (input) {
  147. var i
  148. var output = ''
  149. var length32 = input.length * 32
  150. for (i = 0; i < length32; i += 8) {
  151. output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF)
  152. }
  153. return output
  154. }
  155.  
  156. /*
  157. * Convert a raw string to an array of little-endian words
  158. * Characters >255 have their high-byte silently ignored.
  159. */
  160. function rstr2binl (input) {
  161. var i
  162. var output = []
  163. output[(input.length >> 2) - 1] = undefined
  164. for (i = 0; i < output.length; i += 1) {
  165. output[i] = 0
  166. }
  167. var length8 = input.length * 8
  168. for (i = 0; i < length8; i += 8) {
  169. output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32)
  170. }
  171. return output
  172. }
  173.  
  174. /*
  175. * Calculate the MD5 of a raw string
  176. */
  177. function rstrMD5 (s) {
  178. return binl2rstr(binlMD5(rstr2binl(s), s.length * 8))
  179. }
  180.  
  181. /*
  182. * Calculate the HMAC-MD5, of a key and some data (raw strings)
  183. */
  184. function rstrHMACMD5 (key, data) {
  185. var i
  186. var bkey = rstr2binl(key)
  187. var ipad = []
  188. var opad = []
  189. var hash
  190. ipad[15] = opad[15] = undefined
  191. if (bkey.length > 16) {
  192. bkey = binlMD5(bkey, key.length * 8)
  193. }
  194. for (i = 0; i < 16; i += 1) {
  195. ipad[i] = bkey[i] ^ 0x36363636
  196. opad[i] = bkey[i] ^ 0x5C5C5C5C
  197. }
  198. hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8)
  199. return binl2rstr(binlMD5(opad.concat(hash), 512 + 128))
  200. }
  201.  
  202. /*
  203. * Convert a raw string to a hex string
  204. */
  205. function rstr2hex (input) {
  206. var hexTab = '0123456789abcdef'
  207. var output = ''
  208. var x
  209. var i
  210. for (i = 0; i < input.length; i += 1) {
  211. x = input.charCodeAt(i)
  212. output += hexTab.charAt((x >>> 4) & 0x0F) +
  213. hexTab.charAt(x & 0x0F)
  214. }
  215. return output
  216. }
  217.  
  218. /*
  219. * Encode a string as utf-8
  220. */
  221. function str2rstrUTF8 (input) {
  222. return unescape(encodeURIComponent(input))
  223. }
  224.  
  225. /*
  226. * Take string arguments and return either raw or hex encoded strings
  227. */
  228. function rawMD5 (s) {
  229. return rstrMD5(str2rstrUTF8(s))
  230. }
  231. function hexMD5 (s) {
  232. return rstr2hex(rawMD5(s))
  233. }
  234. function rawHMACMD5 (k, d) {
  235. return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d))
  236. }
  237. function hexHMACMD5 (k, d) {
  238. return rstr2hex(rawHMACMD5(k, d))
  239. }
  240.  
  241. function crc64 (string, key, raw) {
  242. if (!key) {
  243. if (!raw) {
  244. return hexMD5(string)
  245. }
  246. return rawMD5(string)
  247. }
  248. if (!raw) {
  249. return hexHMACMD5(key, string)
  250. }
  251. return rawHMACMD5(key, string)
  252. }
  253.  
  254. if (typeof define === 'function' && define.amd) {
  255. define(function () {
  256. return crc64
  257. })
  258. } else if (typeof module === 'object' && module.exports) {
  259. module.exports = crc64
  260. } else {
  261. $.crc64 = crc64
  262. }
  263. }(this))