a zip code crypto-currency system good for red ONLY

index.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 'use strict'
  2. var inherits = require('inherits')
  3. var HashBase = require('hash-base')
  4. var ARRAY16 = new Array(16)
  5. function MD5 () {
  6. HashBase.call(this, 64)
  7. // state
  8. this._a = 0x67452301
  9. this._b = 0xefcdab89
  10. this._c = 0x98badcfe
  11. this._d = 0x10325476
  12. }
  13. inherits(MD5, HashBase)
  14. MD5.prototype._update = function () {
  15. var M = ARRAY16
  16. for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4)
  17. var a = this._a
  18. var b = this._b
  19. var c = this._c
  20. var d = this._d
  21. a = fnF(a, b, c, d, M[0], 0xd76aa478, 7)
  22. d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12)
  23. c = fnF(c, d, a, b, M[2], 0x242070db, 17)
  24. b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22)
  25. a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7)
  26. d = fnF(d, a, b, c, M[5], 0x4787c62a, 12)
  27. c = fnF(c, d, a, b, M[6], 0xa8304613, 17)
  28. b = fnF(b, c, d, a, M[7], 0xfd469501, 22)
  29. a = fnF(a, b, c, d, M[8], 0x698098d8, 7)
  30. d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12)
  31. c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17)
  32. b = fnF(b, c, d, a, M[11], 0x895cd7be, 22)
  33. a = fnF(a, b, c, d, M[12], 0x6b901122, 7)
  34. d = fnF(d, a, b, c, M[13], 0xfd987193, 12)
  35. c = fnF(c, d, a, b, M[14], 0xa679438e, 17)
  36. b = fnF(b, c, d, a, M[15], 0x49b40821, 22)
  37. a = fnG(a, b, c, d, M[1], 0xf61e2562, 5)
  38. d = fnG(d, a, b, c, M[6], 0xc040b340, 9)
  39. c = fnG(c, d, a, b, M[11], 0x265e5a51, 14)
  40. b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20)
  41. a = fnG(a, b, c, d, M[5], 0xd62f105d, 5)
  42. d = fnG(d, a, b, c, M[10], 0x02441453, 9)
  43. c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14)
  44. b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20)
  45. a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5)
  46. d = fnG(d, a, b, c, M[14], 0xc33707d6, 9)
  47. c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14)
  48. b = fnG(b, c, d, a, M[8], 0x455a14ed, 20)
  49. a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5)
  50. d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9)
  51. c = fnG(c, d, a, b, M[7], 0x676f02d9, 14)
  52. b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20)
  53. a = fnH(a, b, c, d, M[5], 0xfffa3942, 4)
  54. d = fnH(d, a, b, c, M[8], 0x8771f681, 11)
  55. c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16)
  56. b = fnH(b, c, d, a, M[14], 0xfde5380c, 23)
  57. a = fnH(a, b, c, d, M[1], 0xa4beea44, 4)
  58. d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11)
  59. c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16)
  60. b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23)
  61. a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4)
  62. d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11)
  63. c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16)
  64. b = fnH(b, c, d, a, M[6], 0x04881d05, 23)
  65. a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4)
  66. d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11)
  67. c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16)
  68. b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23)
  69. a = fnI(a, b, c, d, M[0], 0xf4292244, 6)
  70. d = fnI(d, a, b, c, M[7], 0x432aff97, 10)
  71. c = fnI(c, d, a, b, M[14], 0xab9423a7, 15)
  72. b = fnI(b, c, d, a, M[5], 0xfc93a039, 21)
  73. a = fnI(a, b, c, d, M[12], 0x655b59c3, 6)
  74. d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10)
  75. c = fnI(c, d, a, b, M[10], 0xffeff47d, 15)
  76. b = fnI(b, c, d, a, M[1], 0x85845dd1, 21)
  77. a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6)
  78. d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10)
  79. c = fnI(c, d, a, b, M[6], 0xa3014314, 15)
  80. b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21)
  81. a = fnI(a, b, c, d, M[4], 0xf7537e82, 6)
  82. d = fnI(d, a, b, c, M[11], 0xbd3af235, 10)
  83. c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15)
  84. b = fnI(b, c, d, a, M[9], 0xeb86d391, 21)
  85. this._a = (this._a + a) | 0
  86. this._b = (this._b + b) | 0
  87. this._c = (this._c + c) | 0
  88. this._d = (this._d + d) | 0
  89. }
  90. MD5.prototype._digest = function () {
  91. // create padding and handle blocks
  92. this._block[this._blockOffset++] = 0x80
  93. if (this._blockOffset > 56) {
  94. this._block.fill(0, this._blockOffset, 64)
  95. this._update()
  96. this._blockOffset = 0
  97. }
  98. this._block.fill(0, this._blockOffset, 56)
  99. this._block.writeUInt32LE(this._length[0], 56)
  100. this._block.writeUInt32LE(this._length[1], 60)
  101. this._update()
  102. // produce result
  103. var buffer = new Buffer(16)
  104. buffer.writeInt32LE(this._a, 0)
  105. buffer.writeInt32LE(this._b, 4)
  106. buffer.writeInt32LE(this._c, 8)
  107. buffer.writeInt32LE(this._d, 12)
  108. return buffer
  109. }
  110. function rotl (x, n) {
  111. return (x << n) | (x >>> (32 - n))
  112. }
  113. function fnF (a, b, c, d, m, k, s) {
  114. return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + b) | 0
  115. }
  116. function fnG (a, b, c, d, m, k, s) {
  117. return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + b) | 0
  118. }
  119. function fnH (a, b, c, d, m, k, s) {
  120. return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + b) | 0
  121. }
  122. function fnI (a, b, c, d, m, k, s) {
  123. return (rotl((a + ((c ^ (b | (~d)))) + m + k) | 0, s) + b) | 0
  124. }
  125. module.exports = MD5