summaryrefslogtreecommitdiff
path: root/http/3rdParty/yaMD5/test/lib/jbt-md5.js
blob: 4738877299a2a5d365ad3a4b0a0ecb26b38cb81f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// https://github.com/jbt/js-crypto
md5 = function(sixteen){

  var k = [],i=0;

  for(;i<64;){
    k[i] = 0|(Math.abs(Math.sin(++i)) * 4294967296);
  }

  function add(x, y){
    return (((x>>1)+(y>>1))<<1)+(x&1)+(y&1) ;
    //var msw = (x >> sixteen) + (y >> sixteen) + ((y=(x & ffff) + (y & ffff)) >> sixteen);
    //return (msw << sixteen) | (y & ffff);
  }

  var calcMD5 = function(str){
    var b,c,d,j,
        x = [],
        str2 = unescape(encodeURI(str)),
        a = str2.length,
        h = [b=1732584193,c=-271733879,~b,~c],
        i=0;

    for(;i<=a;) x[i >> 2] |= (str2.charCodeAt(i)||128) << 8*(i++ % 4);
    x[str=(a+8 >> 6)*sixteen+14] = a * 8;
    i = 0;

    for(; i < str; i += sixteen){
      a = h,j=0;
      for(;j<64;){
        a = [
          d = a[3],
          add(
            b = a[1] ,
            (d = add(
              add(
                a[0],
                [
                  b&(c=a[2]) | ~b&d,
                  d&b | ~d&c,
                  b^c^d,
                  c^(b|~d)
                ][a=j>>4]
              ),
              add(
                k[j],
                x[[
                  j,
                  5*j+1,
                  3*j+5,
                  7*j
                ][a]%sixteen+i]
              )
            )) << (a =[
              7, 12, 17, 22,
              5,  9, 14, 20,
              4, 11, sixteen, 23,
              6, 10, 15, 21
            ][4*a+j++%4]) | d >>> 32-a
          ),
          b,
          c
        ];
      }
      for(j=4;j;) h[--j] = add(h[j], a[j]);
    }

    str = '';
    for(;j<32;) str += ((h[j>>3] >> ((1^j++&7)*4)) & 15).toString(sixteen);

    return str;
  };
  return calcMD5;
}(16);