]> git.openstreetmap.org Git - rails.git/blob - vendor/assets/ohauth/ohauth.js
Update bootstrap code
[rails.git] / vendor / assets / ohauth / ohauth.js
1 (function(e){if("function"==typeof bootstrap)bootstrap("ohauth",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeOhauth=e}else"undefined"!=typeof window?window.ohauth=e():global.ohauth=e()})(function(){var define,ses,bootstrap,module,exports;
2 return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
3 'use strict';
4
5 var hashes = require('jshashes'),
6     xtend = require('xtend'),
7     sha1 = new hashes.SHA1();
8
9 var ohauth = {};
10
11 ohauth.qsString = function(obj) {
12     return Object.keys(obj).sort().map(function(key) {
13         return ohauth.percentEncode(key) + '=' +
14             ohauth.percentEncode(obj[key]);
15     }).join('&');
16 };
17
18 ohauth.stringQs = function(str) {
19     return str.split('&').filter(function (pair) {
20         return pair !== '';
21     }).reduce(function(obj, pair){
22         var parts = pair.split('=');
23         obj[decodeURIComponent(parts[0])] = (null === parts[1]) ?
24             '' : decodeURIComponent(parts[1]);
25         return obj;
26     }, {});
27 };
28
29 ohauth.rawxhr = function(method, url, data, headers, callback) {
30     var xhr = new XMLHttpRequest(),
31         twoHundred = /^20\d$/;
32     xhr.onreadystatechange = function() {
33         if (4 == xhr.readyState && 0 !== xhr.status) {
34             if (twoHundred.test(xhr.status)) callback(null, xhr);
35             else return callback(xhr, null);
36         }
37     };
38     xhr.onerror = function(e) { return callback(e, null); };
39     xhr.open(method, url, true);
40     for (var h in headers) xhr.setRequestHeader(h, headers[h]);
41     xhr.send(data);
42 };
43
44 ohauth.xhr = function(method, url, auth, data, options, callback) {
45     var headers = (options && options.header) || {
46         'Content-Type': 'application/x-www-form-urlencoded'
47     };
48     headers.Authorization = 'OAuth ' + ohauth.authHeader(auth);
49     ohauth.rawxhr(method, url, data, headers, callback);
50 };
51
52 ohauth.nonce = function() {
53     for (var o = ''; o.length < 6;) {
54         o += '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'[Math.floor(Math.random() * 61)];
55     }
56     return o;
57 };
58
59 ohauth.authHeader = function(obj) {
60     return Object.keys(obj).sort().map(function(key) {
61         return encodeURIComponent(key) + '="' + encodeURIComponent(obj[key]) + '"';
62     }).join(', ');
63 };
64
65 ohauth.timestamp = function() { return ~~((+new Date()) / 1000); };
66
67 ohauth.percentEncode = function(s) {
68     return encodeURIComponent(s)
69         .replace(/\!/g, '%21').replace(/\'/g, '%27')
70         .replace(/\*/g, '%2A').replace(/\(/g, '%28').replace(/\)/g, '%29');
71 };
72
73 ohauth.baseString = function(method, url, params) {
74     if (params.oauth_signature) delete params.oauth_signature;
75     return [
76         method,
77         ohauth.percentEncode(url),
78         ohauth.percentEncode(ohauth.qsString(params))].join('&');
79 };
80
81 ohauth.signature = function(oauth_secret, token_secret, baseString) {
82     return sha1.b64_hmac(
83         ohauth.percentEncode(oauth_secret) + '&' +
84         ohauth.percentEncode(token_secret),
85         baseString);
86 };
87
88 /**
89  * Takes an options object for configuration (consumer_key,
90  * consumer_secret, version, signature_method, token, token_secret)
91  * and returns a function that generates the Authorization header
92  * for given data.
93  *
94  * The returned function takes these parameters:
95  * - method: GET/POST/...
96  * - uri: full URI with protocol, port, path and query string
97  * - extra_params: any extra parameters (that are passed in the POST data),
98  *   can be an object or a from-urlencoded string.
99  *
100  * Returned function returns full OAuth header with "OAuth" string in it.
101  */
102
103 ohauth.headerGenerator = function(options) {
104     options = options || {};
105     var consumer_key = options.consumer_key || '',
106         consumer_secret = options.consumer_secret || '',
107         signature_method = options.signature_method || 'HMAC-SHA1',
108         version = options.version || '1.0',
109         token = options.token || '',
110         token_secret = options.token_secret || '';
111
112     return function(method, uri, extra_params) {
113         method = method.toUpperCase();
114         if (typeof extra_params === 'string' && extra_params.length > 0) {
115             extra_params = ohauth.stringQs(extra_params);
116         }
117
118         var uri_parts = uri.split('?', 2),
119         base_uri = uri_parts[0];
120
121         var query_params = uri_parts.length === 2 ?
122             ohauth.stringQs(uri_parts[1]) : {};
123
124         var oauth_params = {
125             oauth_consumer_key: consumer_key,
126             oauth_signature_method: signature_method,
127             oauth_version: version,
128             oauth_timestamp: ohauth.timestamp(),
129             oauth_nonce: ohauth.nonce()
130         };
131
132         if (token) oauth_params.oauth_token = token;
133
134         var all_params = xtend({}, oauth_params, query_params, extra_params),
135             base_str = ohauth.baseString(method, base_uri, all_params);
136
137         oauth_params.oauth_signature = ohauth.signature(consumer_secret, token_secret, base_str);
138
139         return 'OAuth ' + ohauth.authHeader(oauth_params);
140     };
141 };
142
143 module.exports = ohauth;
144
145 },{"jshashes":2,"xtend":3}],2:[function(require,module,exports){
146 (function(global){/**
147  * jsHashes - A fast and independent hashing library pure JavaScript implemented (ES5 compliant) for both server and client side
148  * 
149  * @class Hashes
150  * @author Tomas Aparicio <tomas@rijndael-project.com>
151  * @license New BSD (see LICENSE file)
152  * @version 1.0.3
153  *
154  * Algorithms specification:
155  *
156  * MD5 <http://www.ietf.org/rfc/rfc1321.txt>
157  * RIPEMD-160 <http://homes.esat.kuleuven.be/~bosselae/ripemd160.html>
158  * SHA1   <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
159  * SHA256 <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
160  * SHA512 <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
161  * HMAC <http://www.ietf.org/rfc/rfc2104.txt>
162  *
163  */
164 (function(){
165   var Hashes;
166   
167   // private helper methods
168   function utf8Encode(input) {
169     var  x, y, output = '', i = -1, l = input.length;
170     while ((i+=1) < l) {
171       /* Decode utf-16 surrogate pairs */
172       x = input.charCodeAt(i);
173       y = i + 1 < l ? input.charCodeAt(i + 1) : 0;
174       if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
175           x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
176           i += 1;
177       }
178       /* Encode output as utf-8 */
179       if (x <= 0x7F) {
180           output += String.fromCharCode(x);
181       } else if (x <= 0x7FF) {
182           output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
183                       0x80 | ( x & 0x3F));
184       } else if (x <= 0xFFFF) {
185           output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
186                       0x80 | ((x >>> 6 ) & 0x3F),
187                       0x80 | ( x & 0x3F));
188       } else if (x <= 0x1FFFFF) {
189           output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
190                       0x80 | ((x >>> 12) & 0x3F),
191                       0x80 | ((x >>> 6 ) & 0x3F),
192                       0x80 | ( x & 0x3F));
193       }
194     }
195     return output;
196   }
197   
198   function utf8Decode(str_data) {
199     var i, ac, c1, c2, c3, arr = [], l = str_data.length;
200     i = ac = c1 = c2 = c3 = 0;
201     str_data += '';
202
203     while (i < l) {
204         c1 = str_data.charCodeAt(i);
205         ac += 1;
206         if (c1 < 128) {
207             arr[ac] = String.fromCharCode(c1);
208             i+=1;
209         } else if (c1 > 191 && c1 < 224) {
210             c2 = str_data.charCodeAt(i + 1);
211             arr[ac] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
212             i += 2;
213         } else {
214             c2 = str_data.charCodeAt(i + 1);
215             c3 = str_data.charCodeAt(i + 2);
216             arr[ac] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
217             i += 3;
218         }
219     }
220     return arr.join('');
221   }
222
223   /**
224    * Add integers, wrapping at 2^32. This uses 16-bit operations internally
225    * to work around bugs in some JS interpreters.
226    */
227   function safe_add(x, y) {
228     var lsw = (x & 0xFFFF) + (y & 0xFFFF),
229         msw = (x >> 16) + (y >> 16) + (lsw >> 16);
230     return (msw << 16) | (lsw & 0xFFFF);
231   }
232
233   /**
234    * Bitwise rotate a 32-bit number to the left.
235    */
236   function bit_rol(num, cnt) {
237     return (num << cnt) | (num >>> (32 - cnt));
238   }
239
240   /**
241    * Convert a raw string to a hex string
242    */
243   function rstr2hex(input, hexcase) {
244     var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef',
245         output = '', x, i = 0, l = input.length;
246     for (; i < l; i+=1) {
247       x = input.charCodeAt(i);
248       output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt(x & 0x0F);
249     }
250     return output;
251   }
252
253   /**
254    * Encode a string as utf-16
255    */
256   function str2rstr_utf16le(input) {
257     var i, l = input.length, output = '';
258     for (i = 0; i < l; i+=1) {
259       output += String.fromCharCode( input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF);
260     }
261     return output;
262   }
263
264   function str2rstr_utf16be(input) {
265     var i, l = input.length, output = '';
266     for (i = 0; i < l; i+=1) {
267       output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF);
268     }
269     return output;
270   }
271
272   /**
273    * Convert an array of big-endian words to a string
274    */
275   function binb2rstr(input) {
276     var i, l = input.length * 32, output = '';
277     for (i = 0; i < l; i += 8) {
278         output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
279     }
280     return output;
281   }
282
283   /**
284    * Convert an array of little-endian words to a string
285    */
286   function binl2rstr(input) {
287     var i, l = input.length * 32, output = '';
288     for (i = 0;i < l; i += 8) {
289       output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
290     }
291     return output;
292   }
293
294   /**
295    * Convert a raw string to an array of little-endian words
296    * Characters >255 have their high-byte silently ignored.
297    */
298   function rstr2binl(input) {
299     var i, l = input.length * 8, output = Array(input.length >> 2), lo = output.length;
300     for (i = 0; i < lo; i+=1) {
301       output[i] = 0;
302     }
303     for (i = 0; i < l; i += 8) {
304       output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
305     }
306     return output;
307   }
308   
309   /**
310    * Convert a raw string to an array of big-endian words 
311    * Characters >255 have their high-byte silently ignored.
312    */
313    function rstr2binb(input) {
314       var i, l = input.length * 8, output = Array(input.length >> 2), lo = output.length;
315       for (i = 0; i < lo; i+=1) {
316             output[i] = 0;
317         }
318       for (i = 0; i < l; i += 8) {
319             output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
320         }
321       return output;
322    }
323
324   /**
325    * Convert a raw string to an arbitrary string encoding
326    */
327   function rstr2any(input, encoding) {
328     var divisor = encoding.length,
329         remainders = Array(),
330         i, q, x, ld, quotient, dividend, output, full_length;
331   
332     /* Convert to an array of 16-bit big-endian values, forming the dividend */
333     dividend = Array(Math.ceil(input.length / 2));
334     ld = dividend.length;
335     for (i = 0; i < ld; i+=1) {
336       dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
337     }
338   
339     /**
340      * Repeatedly perform a long division. The binary array forms the dividend,
341      * the length of the encoding is the divisor. Once computed, the quotient
342      * forms the dividend for the next step. We stop when the dividend is zerHashes.
343      * All remainders are stored for later use.
344      */
345     while(dividend.length > 0) {
346       quotient = Array();
347       x = 0;
348       for (i = 0; i < dividend.length; i+=1) {
349         x = (x << 16) + dividend[i];
350         q = Math.floor(x / divisor);
351         x -= q * divisor;
352         if (quotient.length > 0 || q > 0) {
353           quotient[quotient.length] = q;
354         }
355       }
356       remainders[remainders.length] = x;
357       dividend = quotient;
358     }
359   
360     /* Convert the remainders to the output string */
361     output = '';
362     for (i = remainders.length - 1; i >= 0; i--) {
363       output += encoding.charAt(remainders[i]);
364     }
365   
366     /* Append leading zero equivalents */
367     full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
368     for (i = output.length; i < full_length; i+=1) {
369       output = encoding[0] + output;
370     }
371     return output;
372   }
373
374   /**
375    * Convert a raw string to a base-64 string
376    */
377   function rstr2b64(input, b64pad) {
378     var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
379         output = '',
380         len = input.length, i, j, triplet;
381     b64pad= b64pad || '=';
382     for (i = 0; i < len; i += 3) {
383       triplet = (input.charCodeAt(i) << 16)
384             | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
385             | (i + 2 < len ? input.charCodeAt(i+2)      : 0);
386       for (j = 0; j < 4; j+=1) {
387         if (i * 8 + j * 6 > input.length * 8) { 
388           output += b64pad; 
389         } else { 
390           output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); 
391         }
392        }
393     }
394     return output;
395   }
396
397   Hashes = {
398   /**  
399    * @property {String} version
400    * @readonly
401    */
402   VERSION : '1.0.3',
403   /**
404    * @member Hashes
405    * @class Base64
406    * @constructor
407    */
408   Base64 : function () {
409     // private properties
410     var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
411         pad = '=', // default pad according with the RFC standard
412         url = false, // URL encoding support @todo
413         utf8 = true; // by default enable UTF-8 support encoding
414
415     // public method for encoding
416     this.encode = function (input) {
417       var i, j, triplet,
418           output = '', 
419           len = input.length;
420
421       pad = pad || '=';
422       input = (utf8) ? utf8Encode(input) : input;
423
424       for (i = 0; i < len; i += 3) {
425         triplet = (input.charCodeAt(i) << 16)
426               | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
427               | (i + 2 < len ? input.charCodeAt(i+2) : 0);
428         for (j = 0; j < 4; j+=1) {
429           if (i * 8 + j * 6 > len * 8) {
430               output += pad;
431           } else {
432               output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
433           }
434         }
435       }
436       return output;    
437     };
438
439     // public method for decoding
440     this.decode = function (input) {
441       // var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
442       var i, o1, o2, o3, h1, h2, h3, h4, bits, ac,
443         dec = '',
444         arr = [];
445       if (!input) { return input; }
446
447       i = ac = 0;
448       input = input.replace(new RegExp('\\'+pad,'gi'),''); // use '='
449       //input += '';
450
451       do { // unpack four hexets into three octets using index points in b64
452         h1 = tab.indexOf(input.charAt(i+=1));
453         h2 = tab.indexOf(input.charAt(i+=1));
454         h3 = tab.indexOf(input.charAt(i+=1));
455         h4 = tab.indexOf(input.charAt(i+=1));
456
457         bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
458
459         o1 = bits >> 16 & 0xff;
460         o2 = bits >> 8 & 0xff;
461         o3 = bits & 0xff;
462         ac += 1;
463
464         if (h3 === 64) {
465           arr[ac] = String.fromCharCode(o1);
466         } else if (h4 === 64) {
467           arr[ac] = String.fromCharCode(o1, o2);
468         } else {
469           arr[ac] = String.fromCharCode(o1, o2, o3);
470         }
471       } while (i < input.length);
472
473       dec = arr.join('');
474       dec = (utf8) ? utf8Decode(dec) : dec;
475
476       return dec;
477     };
478
479     // set custom pad string
480     this.setPad = function (str) {
481         pad = str || pad;
482         return this;
483     };
484     // set custom tab string characters
485     this.setTab = function (str) {
486         tab = str || tab;
487         return this;
488     };
489     this.setUTF8 = function (bool) {
490         if (typeof bool === 'boolean') {
491           utf8 = bool;
492         }
493         return this;
494     };
495   },
496
497   /**
498    * CRC-32 calculation
499    * @member Hashes
500    * @method CRC32
501    * @static
502    * @param {String} str Input String
503    * @return {String}
504    */
505   CRC32 : function (str) {
506     var crc = 0, x = 0, y = 0, table, i, iTop;
507     str = utf8Encode(str);
508         
509     table = [ 
510         '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 ',
511         '79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 ',
512         '84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F ',
513         '63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD ',
514         'A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC ',
515         '51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 ',
516         'B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 ',
517         '06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 ',
518         'E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 ',
519         '12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 ',
520         'D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 ',
521         '33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 ',
522         'CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 ',
523         '9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E ',
524         '7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D ',
525         '806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 ',
526         '60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA ',
527         'AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 ', 
528         '5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 ',
529         'B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 ',
530         '05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 ',
531         'F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA ',
532         '11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 ',
533         'D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F ',
534         '30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E ',
535         'C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D'
536     ].join('');
537
538     crc = crc ^ (-1);
539     for (i = 0, iTop = str.length; i < iTop; i+=1 ) {
540         y = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
541         x = '0x' + table.substr( y * 9, 8 );
542         crc = ( crc >>> 8 ) ^ x;
543     }
544     // always return a positive number (that's what >>> 0 does)
545     return (crc ^ (-1)) >>> 0;
546   },
547   /**
548    * @member Hashes
549    * @class MD5
550    * @constructor
551    * @param {Object} [config]
552    * 
553    * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
554    * Digest Algorithm, as defined in RFC 1321.
555    * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
556    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
557    * See <http://pajhome.org.uk/crypt/md5> for more infHashes.
558    */
559   MD5 : function (options) {  
560     /**
561      * Private config properties. You may need to tweak these to be compatible with
562      * the server-side, but the defaults work in most cases.
563      * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}
564      */
565     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase
566         b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
567         utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
568
569     // privileged (public) methods 
570     this.hex = function (s) { 
571       return rstr2hex(rstr(s, utf8), hexcase);
572     };
573     this.b64 = function (s) { 
574       return rstr2b64(rstr(s), b64pad);
575     };
576     this.any = function(s, e) { 
577       return rstr2any(rstr(s, utf8), e); 
578     };
579     this.hex_hmac = function (k, d) { 
580       return rstr2hex(rstr_hmac(k, d), hexcase); 
581     };
582     this.b64_hmac = function (k, d) { 
583       return rstr2b64(rstr_hmac(k,d), b64pad); 
584     };
585     this.any_hmac = function (k, d, e) { 
586       return rstr2any(rstr_hmac(k, d), e); 
587     };
588     /**
589      * Perform a simple self-test to see if the VM is working
590      * @return {String} Hexadecimal hash sample
591      */
592     this.vm_test = function () {
593       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
594     };
595     /** 
596      * Enable/disable uppercase hexadecimal returned string 
597      * @param {Boolean} 
598      * @return {Object} this
599      */ 
600     this.setUpperCase = function (a) {
601       if (typeof a === 'boolean' ) {
602         hexcase = a;
603       }
604       return this;
605     };
606     /** 
607      * Defines a base64 pad string 
608      * @param {String} Pad
609      * @return {Object} this
610      */ 
611     this.setPad = function (a) {
612       b64pad = a || b64pad;
613       return this;
614     };
615     /** 
616      * Defines a base64 pad string 
617      * @param {Boolean} 
618      * @return {Object} [this]
619      */ 
620     this.setUTF8 = function (a) {
621       if (typeof a === 'boolean') { 
622         utf8 = a;
623       }
624       return this;
625     };
626
627     // private methods
628
629     /**
630      * Calculate the MD5 of a raw string
631      */
632     function rstr(s) {
633       s = (utf8) ? utf8Encode(s): s;
634       return binl2rstr(binl(rstr2binl(s), s.length * 8));
635     }
636     
637     /**
638      * Calculate the HMAC-MD5, of a key and some data (raw strings)
639      */
640     function rstr_hmac(key, data) {
641       var bkey, ipad, opad, hash, i;
642
643       key = (utf8) ? utf8Encode(key) : key;
644       data = (utf8) ? utf8Encode(data) : data;
645       bkey = rstr2binl(key);
646       if (bkey.length > 16) { 
647         bkey = binl(bkey, key.length * 8); 
648       }
649
650       ipad = Array(16), opad = Array(16); 
651       for (i = 0; i < 16; i+=1) {
652           ipad[i] = bkey[i] ^ 0x36363636;
653           opad[i] = bkey[i] ^ 0x5C5C5C5C;
654       }
655       hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
656       return binl2rstr(binl(opad.concat(hash), 512 + 128));
657     }
658
659     /**
660      * Calculate the MD5 of an array of little-endian words, and a bit length.
661      */
662     function binl(x, len) {
663       var i, olda, oldb, oldc, oldd,
664           a =  1732584193,
665           b = -271733879,
666           c = -1732584194,
667           d =  271733878;
668         
669       /* append padding */
670       x[len >> 5] |= 0x80 << ((len) % 32);
671       x[(((len + 64) >>> 9) << 4) + 14] = len;
672
673       for (i = 0; i < x.length; i += 16) {
674         olda = a;
675         oldb = b;
676         oldc = c;
677         oldd = d;
678
679         a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
680         d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
681         c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
682         b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
683         a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
684         d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
685         c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
686         b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
687         a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
688         d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
689         c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
690         b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
691         a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
692         d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
693         c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
694         b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);
695
696         a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
697         d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
698         c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
699         b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
700         a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
701         d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
702         c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
703         b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
704         a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
705         d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
706         c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
707         b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
708         a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
709         d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
710         c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
711         b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
712
713         a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
714         d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
715         c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
716         b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
717         a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
718         d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
719         c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
720         b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
721         a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
722         d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
723         c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
724         b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
725         a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
726         d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
727         c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
728         b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
729
730         a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
731         d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
732         c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
733         b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
734         a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
735         d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
736         c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
737         b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
738         a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
739         d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
740         c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
741         b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
742         a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
743         d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
744         c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
745         b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
746
747         a = safe_add(a, olda);
748         b = safe_add(b, oldb);
749         c = safe_add(c, oldc);
750         d = safe_add(d, oldd);
751       }
752       return Array(a, b, c, d);
753     }
754
755     /**
756      * These functions implement the four basic operations the algorithm uses.
757      */
758     function md5_cmn(q, a, b, x, s, t) {
759       return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
760     }
761     function md5_ff(a, b, c, d, x, s, t) {
762       return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
763     }
764     function md5_gg(a, b, c, d, x, s, t) {
765       return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
766     }
767     function md5_hh(a, b, c, d, x, s, t) {
768       return md5_cmn(b ^ c ^ d, a, b, x, s, t);
769     }
770     function md5_ii(a, b, c, d, x, s, t) {
771       return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
772     }
773   },
774   /**
775    * @member Hashes
776    * @class Hashes.SHA1
777    * @param {Object} [config]
778    * @constructor
779    * 
780    * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined in FIPS 180-1
781    * Version 2.2 Copyright Paul Johnston 2000 - 2009.
782    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
783    * See http://pajhome.org.uk/crypt/md5 for details.
784    */
785   SHA1 : function (options) {
786    /**
787      * Private config properties. You may need to tweak these to be compatible with
788      * the server-side, but the defaults work in most cases.
789      * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}
790      */
791     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase
792         b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
793         utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
794
795     // public methods
796     this.hex = function (s) { 
797         return rstr2hex(rstr(s, utf8), hexcase); 
798     };
799     this.b64 = function (s) { 
800         return rstr2b64(rstr(s, utf8), b64pad);
801     };
802     this.any = function (s, e) { 
803         return rstr2any(rstr(s, utf8), e);
804     };
805     this.hex_hmac = function (k, d) {
806         return rstr2hex(rstr_hmac(k, d));
807     };
808     this.b64_hmac = function (k, d) { 
809         return rstr2b64(rstr_hmac(k, d), b64pad); 
810     };
811     this.any_hmac = function (k, d, e) { 
812         return rstr2any(rstr_hmac(k, d), e);
813     };
814     /**
815      * Perform a simple self-test to see if the VM is working
816      * @return {String} Hexadecimal hash sample
817      * @public
818      */
819     this.vm_test = function () {
820       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
821     };
822     /** 
823      * @description Enable/disable uppercase hexadecimal returned string 
824      * @param {boolean} 
825      * @return {Object} this
826      * @public
827      */ 
828     this.setUpperCase = function (a) {
829         if (typeof a === 'boolean') {
830         hexcase = a;
831       }
832         return this;
833     };
834     /** 
835      * @description Defines a base64 pad string 
836      * @param {string} Pad
837      * @return {Object} this
838      * @public
839      */ 
840     this.setPad = function (a) {
841       b64pad = a || b64pad;
842         return this;
843     };
844     /** 
845      * @description Defines a base64 pad string 
846      * @param {boolean} 
847      * @return {Object} this
848      * @public
849      */ 
850     this.setUTF8 = function (a) {
851         if (typeof a === 'boolean') {
852         utf8 = a;
853       }
854         return this;
855     };
856
857     // private methods
858
859     /**
860          * Calculate the SHA-512 of a raw string
861          */
862         function rstr(s) {
863       s = (utf8) ? utf8Encode(s) : s;
864       return binb2rstr(binb(rstr2binb(s), s.length * 8));
865         }
866
867     /**
868      * Calculate the HMAC-SHA1 of a key and some data (raw strings)
869      */
870     function rstr_hmac(key, data) {
871         var bkey, ipad, opad, i, hash;
872         key = (utf8) ? utf8Encode(key) : key;
873         data = (utf8) ? utf8Encode(data) : data;
874         bkey = rstr2binb(key);
875
876         if (bkey.length > 16) {
877         bkey = binb(bkey, key.length * 8);
878       }
879         ipad = Array(16), opad = Array(16);
880         for (i = 0; i < 16; i+=1) {
881                 ipad[i] = bkey[i] ^ 0x36363636;
882                 opad[i] = bkey[i] ^ 0x5C5C5C5C;
883         }
884         hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
885         return binb2rstr(binb(opad.concat(hash), 512 + 160));
886     }
887
888     /**
889      * Calculate the SHA-1 of an array of big-endian words, and a bit length
890      */
891     function binb(x, len) {
892       var i, j, t, olda, oldb, oldc, oldd, olde,
893           w = Array(80),
894           a =  1732584193,
895           b = -271733879,
896           c = -1732584194,
897           d =  271733878,
898           e = -1009589776;
899
900       /* append padding */
901       x[len >> 5] |= 0x80 << (24 - len % 32);
902       x[((len + 64 >> 9) << 4) + 15] = len;
903
904       for (i = 0; i < x.length; i += 16) {
905         olda = a,
906         oldb = b;
907         oldc = c;
908         oldd = d;
909         olde = e;
910       
911         for (j = 0; j < 80; j+=1)       {
912           if (j < 16) { 
913             w[j] = x[i + j]; 
914           } else { 
915             w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); 
916           }
917           t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
918                                            safe_add(safe_add(e, w[j]), sha1_kt(j)));
919           e = d;
920           d = c;
921           c = bit_rol(b, 30);
922           b = a;
923           a = t;
924         }
925
926         a = safe_add(a, olda);
927         b = safe_add(b, oldb);
928         c = safe_add(c, oldc);
929         d = safe_add(d, oldd);
930         e = safe_add(e, olde);
931       }
932       return Array(a, b, c, d, e);
933     }
934
935     /**
936      * Perform the appropriate triplet combination function for the current
937      * iteration
938      */
939     function sha1_ft(t, b, c, d) {
940       if (t < 20) { return (b & c) | ((~b) & d); }
941       if (t < 40) { return b ^ c ^ d; }
942       if (t < 60) { return (b & c) | (b & d) | (c & d); }
943       return b ^ c ^ d;
944     }
945
946     /**
947      * Determine the appropriate additive constant for the current iteration
948      */
949     function sha1_kt(t) {
950       return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
951                  (t < 60) ? -1894007588 : -899497514;
952     }
953   },
954   /**
955    * @class Hashes.SHA256
956    * @param {config}
957    * 
958    * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined in FIPS 180-2
959    * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
960    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
961    * See http://pajhome.org.uk/crypt/md5 for details.
962    * Also http://anmar.eu.org/projects/jssha2/
963    */
964   SHA256 : function (options) {
965     /**
966      * Private properties configuration variables. You may need to tweak these to be compatible with
967      * the server-side, but the defaults work in most cases.
968      * @see this.setUpperCase() method
969      * @see this.setPad() method
970      */
971     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase  */
972               b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', /* base-64 pad character. Default '=' for strict RFC compliance   */
973               utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
974               sha256_K;
975
976     /* privileged (public) methods */
977     this.hex = function (s) { 
978       return rstr2hex(rstr(s, utf8)); 
979     };
980     this.b64 = function (s) { 
981       return rstr2b64(rstr(s, utf8), b64pad);
982     };
983     this.any = function (s, e) { 
984       return rstr2any(rstr(s, utf8), e); 
985     };
986     this.hex_hmac = function (k, d) { 
987       return rstr2hex(rstr_hmac(k, d)); 
988     };
989     this.b64_hmac = function (k, d) { 
990       return rstr2b64(rstr_hmac(k, d), b64pad);
991     };
992     this.any_hmac = function (k, d, e) { 
993       return rstr2any(rstr_hmac(k, d), e); 
994     };
995     /**
996      * Perform a simple self-test to see if the VM is working
997      * @return {String} Hexadecimal hash sample
998      * @public
999      */
1000     this.vm_test = function () {
1001       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1002     };
1003     /** 
1004      * Enable/disable uppercase hexadecimal returned string 
1005      * @param {boolean} 
1006      * @return {Object} this
1007      * @public
1008      */ 
1009     this.setUpperCase = function (a) {
1010       if (typeof a === 'boolean') { 
1011         hexcase = a;
1012       }
1013       return this;
1014     };
1015     /** 
1016      * @description Defines a base64 pad string 
1017      * @param {string} Pad
1018      * @return {Object} this
1019      * @public
1020      */ 
1021     this.setPad = function (a) {
1022       b64pad = a || b64pad;
1023       return this;
1024     };
1025     /** 
1026      * Defines a base64 pad string 
1027      * @param {boolean} 
1028      * @return {Object} this
1029      * @public
1030      */ 
1031     this.setUTF8 = function (a) {
1032       if (typeof a === 'boolean') {
1033         utf8 = a;
1034       }
1035       return this;
1036     };
1037     
1038     // private methods
1039
1040     /**
1041      * Calculate the SHA-512 of a raw string
1042      */
1043     function rstr(s, utf8) {
1044       s = (utf8) ? utf8Encode(s) : s;
1045       return binb2rstr(binb(rstr2binb(s), s.length * 8));
1046     }
1047
1048     /**
1049      * Calculate the HMAC-sha256 of a key and some data (raw strings)
1050      */
1051     function rstr_hmac(key, data) {
1052       key = (utf8) ? utf8Encode(key) : key;
1053       data = (utf8) ? utf8Encode(data) : data;
1054       var hash, i = 0,
1055           bkey = rstr2binb(key), 
1056           ipad = Array(16), 
1057           opad = Array(16);
1058
1059       if (bkey.length > 16) { bkey = binb(bkey, key.length * 8); }
1060       
1061       for (; i < 16; i+=1) {
1062         ipad[i] = bkey[i] ^ 0x36363636;
1063         opad[i] = bkey[i] ^ 0x5C5C5C5C;
1064       }
1065       
1066       hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
1067       return binb2rstr(binb(opad.concat(hash), 512 + 256));
1068     }
1069     
1070     /*
1071      * Main sha256 function, with its support functions
1072      */
1073     function sha256_S (X, n) {return ( X >>> n ) | (X << (32 - n));}
1074     function sha256_R (X, n) {return ( X >>> n );}
1075     function sha256_Ch(x, y, z) {return ((x & y) ^ ((~x) & z));}
1076     function sha256_Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}
1077     function sha256_Sigma0256(x) {return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22));}
1078     function sha256_Sigma1256(x) {return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25));}
1079     function sha256_Gamma0256(x) {return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3));}
1080     function sha256_Gamma1256(x) {return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10));}
1081     function sha256_Sigma0512(x) {return (sha256_S(x, 28) ^ sha256_S(x, 34) ^ sha256_S(x, 39));}
1082     function sha256_Sigma1512(x) {return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41));}
1083     function sha256_Gamma0512(x) {return (sha256_S(x, 1)  ^ sha256_S(x, 8) ^ sha256_R(x, 7));}
1084     function sha256_Gamma1512(x) {return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6));}
1085     
1086     sha256_K = [
1087       1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993,
1088       -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,
1089       1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,
1090       264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986,
1091       -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,
1092       113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,
1093       1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885,
1094       -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,
1095       430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,
1096       1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872,
1097       -1866530822, -1538233109, -1090935817, -965641998
1098     ];
1099     
1100     function binb(m, l) {
1101       var HASH = [1779033703, -1150833019, 1013904242, -1521486534,
1102                  1359893119, -1694144372, 528734635, 1541459225];
1103       var W = new Array(64);
1104       var a, b, c, d, e, f, g, h;
1105       var i, j, T1, T2;
1106     
1107       /* append padding */
1108       m[l >> 5] |= 0x80 << (24 - l % 32);
1109       m[((l + 64 >> 9) << 4) + 15] = l;
1110     
1111       for (i = 0; i < m.length; i += 16)
1112       {
1113       a = HASH[0];
1114       b = HASH[1];
1115       c = HASH[2];
1116       d = HASH[3];
1117       e = HASH[4];
1118       f = HASH[5];
1119       g = HASH[6];
1120       h = HASH[7];
1121     
1122       for (j = 0; j < 64; j+=1)
1123       {
1124         if (j < 16) { 
1125           W[j] = m[j + i];
1126         } else { 
1127           W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),
1128                           sha256_Gamma0256(W[j - 15])), W[j - 16]);
1129         }
1130     
1131         T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),
1132                                   sha256_K[j]), W[j]);
1133         T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));
1134         h = g;
1135         g = f;
1136         f = e;
1137         e = safe_add(d, T1);
1138         d = c;
1139         c = b;
1140         b = a;
1141         a = safe_add(T1, T2);
1142       }
1143     
1144       HASH[0] = safe_add(a, HASH[0]);
1145       HASH[1] = safe_add(b, HASH[1]);
1146       HASH[2] = safe_add(c, HASH[2]);
1147       HASH[3] = safe_add(d, HASH[3]);
1148       HASH[4] = safe_add(e, HASH[4]);
1149       HASH[5] = safe_add(f, HASH[5]);
1150       HASH[6] = safe_add(g, HASH[6]);
1151       HASH[7] = safe_add(h, HASH[7]);
1152       }
1153       return HASH;
1154     }
1155
1156   },
1157
1158   /**
1159    * @class Hashes.SHA512
1160    * @param {config}
1161    * 
1162    * A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined in FIPS 180-2
1163    * Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.
1164    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
1165    * See http://pajhome.org.uk/crypt/md5 for details. 
1166    */
1167   SHA512 : function (options) {
1168     /**
1169      * Private properties configuration variables. You may need to tweak these to be compatible with
1170      * the server-side, but the defaults work in most cases.
1171      * @see this.setUpperCase() method
1172      * @see this.setPad() method
1173      */
1174     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false , /* hexadecimal output case format. false - lowercase; true - uppercase  */
1175         b64pad = (options && typeof options.pad === 'string') ? options.pda : '=',  /* base-64 pad character. Default '=' for strict RFC compliance   */
1176         utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
1177         sha512_k;
1178
1179     /* privileged (public) methods */
1180     this.hex = function (s) { 
1181       return rstr2hex(rstr(s)); 
1182     };
1183     this.b64 = function (s) { 
1184       return rstr2b64(rstr(s), b64pad);  
1185     };
1186     this.any = function (s, e) { 
1187       return rstr2any(rstr(s), e);
1188     };
1189     this.hex_hmac = function (k, d) {
1190       return rstr2hex(rstr_hmac(k, d));
1191     };
1192     this.b64_hmac = function (k, d) { 
1193       return rstr2b64(rstr_hmac(k, d), b64pad);
1194     };
1195     this.any_hmac = function (k, d, e) { 
1196       return rstr2any(rstr_hmac(k, d), e);
1197     };
1198     /**
1199      * Perform a simple self-test to see if the VM is working
1200      * @return {String} Hexadecimal hash sample
1201      * @public
1202      */
1203     this.vm_test = function () {
1204       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1205     };
1206     /** 
1207      * @description Enable/disable uppercase hexadecimal returned string 
1208      * @param {boolean} 
1209      * @return {Object} this
1210      * @public
1211      */ 
1212     this.setUpperCase = function (a) {
1213       if (typeof a === 'boolean') {
1214         hexcase = a;
1215       }
1216       return this;
1217     };
1218     /** 
1219      * @description Defines a base64 pad string 
1220      * @param {string} Pad
1221      * @return {Object} this
1222      * @public
1223      */ 
1224     this.setPad = function (a) {
1225       b64pad = a || b64pad;
1226       return this;
1227     };
1228     /** 
1229      * @description Defines a base64 pad string 
1230      * @param {boolean} 
1231      * @return {Object} this
1232      * @public
1233      */ 
1234     this.setUTF8 = function (a) {
1235       if (typeof a === 'boolean') {
1236         utf8 = a;
1237       }
1238       return this;
1239     };
1240
1241     /* private methods */
1242     
1243     /**
1244      * Calculate the SHA-512 of a raw string
1245      */
1246     function rstr(s) {
1247       s = (utf8) ? utf8Encode(s) : s;
1248       return binb2rstr(binb(rstr2binb(s), s.length * 8));
1249     }
1250     /*
1251      * Calculate the HMAC-SHA-512 of a key and some data (raw strings)
1252      */
1253     function rstr_hmac(key, data) {
1254       key = (utf8) ? utf8Encode(key) : key;
1255       data = (utf8) ? utf8Encode(data) : data;
1256       
1257       var hash, i = 0, 
1258           bkey = rstr2binb(key),
1259           ipad = Array(32), opad = Array(32);
1260
1261       if (bkey.length > 32) { bkey = binb(bkey, key.length * 8); }
1262       
1263       for (; i < 32; i+=1) {
1264         ipad[i] = bkey[i] ^ 0x36363636;
1265         opad[i] = bkey[i] ^ 0x5C5C5C5C;
1266       }
1267       
1268       hash = binb(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);
1269       return binb2rstr(binb(opad.concat(hash), 1024 + 512));
1270     }
1271             
1272     /**
1273      * Calculate the SHA-512 of an array of big-endian dwords, and a bit length
1274      */
1275     function binb(x, len) {
1276       var j, i, l,
1277           W = new Array(80),
1278           hash = new Array(16),
1279           //Initial hash values
1280           H = [
1281             new int64(0x6a09e667, -205731576),
1282             new int64(-1150833019, -2067093701),
1283             new int64(0x3c6ef372, -23791573),
1284             new int64(-1521486534, 0x5f1d36f1),
1285             new int64(0x510e527f, -1377402159),
1286             new int64(-1694144372, 0x2b3e6c1f),
1287             new int64(0x1f83d9ab, -79577749),
1288             new int64(0x5be0cd19, 0x137e2179)
1289           ],
1290           T1 = new int64(0, 0),
1291           T2 = new int64(0, 0),
1292           a = new int64(0,0),
1293           b = new int64(0,0),
1294           c = new int64(0,0),
1295           d = new int64(0,0),
1296           e = new int64(0,0),
1297           f = new int64(0,0),
1298           g = new int64(0,0),
1299           h = new int64(0,0),
1300           //Temporary variables not specified by the document
1301           s0 = new int64(0, 0),
1302           s1 = new int64(0, 0),
1303           Ch = new int64(0, 0),
1304           Maj = new int64(0, 0),
1305           r1 = new int64(0, 0),
1306           r2 = new int64(0, 0),
1307           r3 = new int64(0, 0);
1308
1309       if (sha512_k === undefined) {
1310           //SHA512 constants
1311           sha512_k = [
1312             new int64(0x428a2f98, -685199838), new int64(0x71374491, 0x23ef65cd),
1313             new int64(-1245643825, -330482897), new int64(-373957723, -2121671748),
1314             new int64(0x3956c25b, -213338824), new int64(0x59f111f1, -1241133031),
1315             new int64(-1841331548, -1357295717), new int64(-1424204075, -630357736),
1316             new int64(-670586216, -1560083902), new int64(0x12835b01, 0x45706fbe),
1317             new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, -704662302),
1318             new int64(0x72be5d74, -226784913), new int64(-2132889090, 0x3b1696b1),
1319             new int64(-1680079193, 0x25c71235), new int64(-1046744716, -815192428),
1320             new int64(-459576895, -1628353838), new int64(-272742522, 0x384f25e3),
1321             new int64(0xfc19dc6, -1953704523), new int64(0x240ca1cc, 0x77ac9c65),
1322             new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),
1323             new int64(0x5cb0a9dc, -1119749164), new int64(0x76f988da, -2096016459),
1324             new int64(-1740746414, -295247957), new int64(-1473132947, 0x2db43210),
1325             new int64(-1341970488, -1728372417), new int64(-1084653625, -1091629340),
1326             new int64(-958395405, 0x3da88fc2), new int64(-710438585, -1828018395),
1327             new int64(0x6ca6351, -536640913), new int64(0x14292967, 0xa0e6e70),
1328             new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),
1329             new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, -1651133473),
1330             new int64(0x650a7354, -1951439906), new int64(0x766a0abb, 0x3c77b2a8),
1331             new int64(-2117940946, 0x47edaee6), new int64(-1838011259, 0x1482353b),
1332             new int64(-1564481375, 0x4cf10364), new int64(-1474664885, -1136513023),
1333             new int64(-1035236496, -789014639), new int64(-949202525, 0x654be30),
1334             new int64(-778901479, -688958952), new int64(-694614492, 0x5565a910),
1335             new int64(-200395387, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),
1336             new int64(0x19a4c116, -1194143544), new int64(0x1e376c08, 0x5141ab53),
1337             new int64(0x2748774c, -544281703), new int64(0x34b0bcb5, -509917016),
1338             new int64(0x391c0cb3, -976659869), new int64(0x4ed8aa4a, -482243893),
1339             new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, -692930397),
1340             new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),
1341             new int64(-2067236844, -1578062990), new int64(-1933114872, 0x1a6439ec),
1342             new int64(-1866530822, 0x23631e28), new int64(-1538233109, -561857047),
1343             new int64(-1090935817, -1295615723), new int64(-965641998, -479046869),
1344             new int64(-903397682, -366583396), new int64(-779700025, 0x21c0c207),
1345             new int64(-354779690, -840897762), new int64(-176337025, -294727304),
1346             new int64(0x6f067aa, 0x72176fba), new int64(0xa637dc5, -1563912026),
1347             new int64(0x113f9804, -1090974290), new int64(0x1b710b35, 0x131c471b),
1348             new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),
1349             new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, -1676669620),
1350             new int64(0x4cc5d4be, -885112138), new int64(0x597f299c, -60457430),
1351             new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817)
1352           ];
1353       }
1354   
1355       for (i=0; i<80; i+=1) {
1356         W[i] = new int64(0, 0);
1357       }
1358     
1359       // append padding to the source string. The format is described in the FIPS.
1360       x[len >> 5] |= 0x80 << (24 - (len & 0x1f));
1361       x[((len + 128 >> 10)<< 5) + 31] = len;
1362       l = x.length;
1363       for (i = 0; i<l; i+=32) { //32 dwords is the block size
1364         int64copy(a, H[0]);
1365         int64copy(b, H[1]);
1366         int64copy(c, H[2]);
1367         int64copy(d, H[3]);
1368         int64copy(e, H[4]);
1369         int64copy(f, H[5]);
1370         int64copy(g, H[6]);
1371         int64copy(h, H[7]);
1372       
1373         for (j=0; j<16; j+=1) {
1374           W[j].h = x[i + 2*j];
1375           W[j].l = x[i + 2*j + 1];
1376         }
1377       
1378         for (j=16; j<80; j+=1) {
1379           //sigma1
1380           int64rrot(r1, W[j-2], 19);
1381           int64revrrot(r2, W[j-2], 29);
1382           int64shr(r3, W[j-2], 6);
1383           s1.l = r1.l ^ r2.l ^ r3.l;
1384           s1.h = r1.h ^ r2.h ^ r3.h;
1385           //sigma0
1386           int64rrot(r1, W[j-15], 1);
1387           int64rrot(r2, W[j-15], 8);
1388           int64shr(r3, W[j-15], 7);
1389           s0.l = r1.l ^ r2.l ^ r3.l;
1390           s0.h = r1.h ^ r2.h ^ r3.h;
1391       
1392           int64add4(W[j], s1, W[j-7], s0, W[j-16]);
1393         }
1394       
1395         for (j = 0; j < 80; j+=1) {
1396           //Ch
1397           Ch.l = (e.l & f.l) ^ (~e.l & g.l);
1398           Ch.h = (e.h & f.h) ^ (~e.h & g.h);
1399       
1400           //Sigma1
1401           int64rrot(r1, e, 14);
1402           int64rrot(r2, e, 18);
1403           int64revrrot(r3, e, 9);
1404           s1.l = r1.l ^ r2.l ^ r3.l;
1405           s1.h = r1.h ^ r2.h ^ r3.h;
1406       
1407           //Sigma0
1408           int64rrot(r1, a, 28);
1409           int64revrrot(r2, a, 2);
1410           int64revrrot(r3, a, 7);
1411           s0.l = r1.l ^ r2.l ^ r3.l;
1412           s0.h = r1.h ^ r2.h ^ r3.h;
1413       
1414           //Maj
1415           Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);
1416           Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);
1417       
1418           int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);
1419           int64add(T2, s0, Maj);
1420       
1421           int64copy(h, g);
1422           int64copy(g, f);
1423           int64copy(f, e);
1424           int64add(e, d, T1);
1425           int64copy(d, c);
1426           int64copy(c, b);
1427           int64copy(b, a);
1428           int64add(a, T1, T2);
1429         }
1430         int64add(H[0], H[0], a);
1431         int64add(H[1], H[1], b);
1432         int64add(H[2], H[2], c);
1433         int64add(H[3], H[3], d);
1434         int64add(H[4], H[4], e);
1435         int64add(H[5], H[5], f);
1436         int64add(H[6], H[6], g);
1437         int64add(H[7], H[7], h);
1438       }
1439     
1440       //represent the hash as an array of 32-bit dwords
1441       for (i=0; i<8; i+=1) {
1442         hash[2*i] = H[i].h;
1443         hash[2*i + 1] = H[i].l;
1444       }
1445       return hash;
1446     }
1447     
1448     //A constructor for 64-bit numbers
1449     function int64(h, l) {
1450       this.h = h;
1451       this.l = l;
1452       //this.toString = int64toString;
1453     }
1454     
1455     //Copies src into dst, assuming both are 64-bit numbers
1456     function int64copy(dst, src) {
1457       dst.h = src.h;
1458       dst.l = src.l;
1459     }
1460     
1461     //Right-rotates a 64-bit number by shift
1462     //Won't handle cases of shift>=32
1463     //The function revrrot() is for that
1464     function int64rrot(dst, x, shift) {
1465       dst.l = (x.l >>> shift) | (x.h << (32-shift));
1466       dst.h = (x.h >>> shift) | (x.l << (32-shift));
1467     }
1468     
1469     //Reverses the dwords of the source and then rotates right by shift.
1470     //This is equivalent to rotation by 32+shift
1471     function int64revrrot(dst, x, shift) {
1472       dst.l = (x.h >>> shift) | (x.l << (32-shift));
1473       dst.h = (x.l >>> shift) | (x.h << (32-shift));
1474     }
1475     
1476     //Bitwise-shifts right a 64-bit number by shift
1477     //Won't handle shift>=32, but it's never needed in SHA512
1478     function int64shr(dst, x, shift) {
1479       dst.l = (x.l >>> shift) | (x.h << (32-shift));
1480       dst.h = (x.h >>> shift);
1481     }
1482     
1483     //Adds two 64-bit numbers
1484     //Like the original implementation, does not rely on 32-bit operations
1485     function int64add(dst, x, y) {
1486        var w0 = (x.l & 0xffff) + (y.l & 0xffff);
1487        var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);
1488        var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);
1489        var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);
1490        dst.l = (w0 & 0xffff) | (w1 << 16);
1491        dst.h = (w2 & 0xffff) | (w3 << 16);
1492     }
1493     
1494     //Same, except with 4 addends. Works faster than adding them one by one.
1495     function int64add4(dst, a, b, c, d) {
1496        var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);
1497        var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (w0 >>> 16);
1498        var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (w1 >>> 16);
1499        var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (w2 >>> 16);
1500        dst.l = (w0 & 0xffff) | (w1 << 16);
1501        dst.h = (w2 & 0xffff) | (w3 << 16);
1502     }
1503     
1504     //Same, except with 5 addends
1505     function int64add5(dst, a, b, c, d, e) {
1506       var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff),
1507           w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (e.l >>> 16) + (w0 >>> 16),
1508           w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (e.h & 0xffff) + (w1 >>> 16),
1509           w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (e.h >>> 16) + (w2 >>> 16);
1510        dst.l = (w0 & 0xffff) | (w1 << 16);
1511        dst.h = (w2 & 0xffff) | (w3 << 16);
1512     }
1513   },
1514   /**
1515    * @class Hashes.RMD160
1516    * @constructor
1517    * @param {Object} [config]
1518    * 
1519    * A JavaScript implementation of the RIPEMD-160 Algorithm
1520    * Version 2.2 Copyright Jeremy Lin, Paul Johnston 2000 - 2009.
1521    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
1522    * See http://pajhome.org.uk/crypt/md5 for details.
1523    * Also http://www.ocf.berkeley.edu/~jjlin/jsotp/
1524    */
1525   RMD160 : function (options) {
1526     /**
1527      * Private properties configuration variables. You may need to tweak these to be compatible with
1528      * the server-side, but the defaults work in most cases.
1529      * @see this.setUpperCase() method
1530      * @see this.setPad() method
1531      */
1532     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false,   /* hexadecimal output case format. false - lowercase; true - uppercase  */
1533         b64pad = (options && typeof options.pad === 'string') ? options.pda : '=',  /* base-64 pad character. Default '=' for strict RFC compliance   */
1534         utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
1535         rmd160_r1 = [
1536            0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
1537            7,  4, 13,  1, 10,  6, 15,  3, 12,  0,  9,  5,  2, 14, 11,  8,
1538            3, 10, 14,  4,  9, 15,  8,  1,  2,  7,  0,  6, 13, 11,  5, 12,
1539            1,  9, 11, 10,  0,  8, 12,  4, 13,  3,  7, 15, 14,  5,  6,  2,
1540            4,  0,  5,  9,  7, 12,  2, 10, 14,  1,  3,  8, 11,  6, 15, 13
1541         ],
1542         rmd160_r2 = [
1543            5, 14,  7,  0,  9,  2, 11,  4, 13,  6, 15,  8,  1, 10,  3, 12,
1544            6, 11,  3,  7,  0, 13,  5, 10, 14, 15,  8, 12,  4,  9,  1,  2,
1545           15,  5,  1,  3,  7, 14,  6,  9, 11,  8, 12,  2, 10,  0,  4, 13,
1546            8,  6,  4,  1,  3, 11, 15,  0,  5, 12,  2, 13,  9,  7, 10, 14,
1547           12, 15, 10,  4,  1,  5,  8,  7,  6,  2, 13, 14,  0,  3,  9, 11
1548         ],
1549         rmd160_s1 = [
1550           11, 14, 15, 12,  5,  8,  7,  9, 11, 13, 14, 15,  6,  7,  9,  8,
1551            7,  6,  8, 13, 11,  9,  7, 15,  7, 12, 15,  9, 11,  7, 13, 12,
1552           11, 13,  6,  7, 14,  9, 13, 15, 14,  8, 13,  6,  5, 12,  7,  5,
1553           11, 12, 14, 15, 14, 15,  9,  8,  9, 14,  5,  6,  8,  6,  5, 12,
1554            9, 15,  5, 11,  6,  8, 13, 12,  5, 12, 13, 14, 11,  8,  5,  6
1555         ],
1556         rmd160_s2 = [
1557            8,  9,  9, 11, 13, 15, 15,  5,  7,  7,  8, 11, 14, 14, 12,  6,
1558            9, 13, 15,  7, 12,  8,  9, 11,  7,  7, 12,  7,  6, 15, 13, 11,
1559            9,  7, 15, 11,  8,  6,  6, 14, 12, 13,  5, 14, 13, 13,  7,  5,
1560           15,  5,  8, 11, 14, 14,  6, 14,  6,  9, 12,  9, 12,  5, 15,  8,
1561            8,  5, 12,  9, 12,  5, 14,  6,  8, 13,  6,  5, 15, 13, 11, 11
1562         ];
1563
1564     /* privileged (public) methods */
1565     this.hex = function (s) {
1566       return rstr2hex(rstr(s, utf8)); 
1567     };
1568     this.b64 = function (s) {
1569       return rstr2b64(rstr(s, utf8), b64pad);
1570     };
1571     this.any = function (s, e) { 
1572       return rstr2any(rstr(s, utf8), e);
1573     };
1574     this.hex_hmac = function (k, d) { 
1575       return rstr2hex(rstr_hmac(k, d));
1576     };
1577     this.b64_hmac = function (k, d) { 
1578       return rstr2b64(rstr_hmac(k, d), b64pad);
1579     };
1580     this.any_hmac = function (k, d, e) { 
1581       return rstr2any(rstr_hmac(k, d), e); 
1582     };
1583     /**
1584      * Perform a simple self-test to see if the VM is working
1585      * @return {String} Hexadecimal hash sample
1586      * @public
1587      */
1588     this.vm_test = function () {
1589       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1590     };
1591     /** 
1592      * @description Enable/disable uppercase hexadecimal returned string 
1593      * @param {boolean} 
1594      * @return {Object} this
1595      * @public
1596      */ 
1597     this.setUpperCase = function (a) {
1598       if (typeof a === 'boolean' ) { hexcase = a; }
1599       return this;
1600     };
1601     /** 
1602      * @description Defines a base64 pad string 
1603      * @param {string} Pad
1604      * @return {Object} this
1605      * @public
1606      */ 
1607     this.setPad = function (a) {
1608       if (typeof a !== 'undefined' ) { b64pad = a; }
1609       return this;
1610     };
1611     /** 
1612      * @description Defines a base64 pad string 
1613      * @param {boolean} 
1614      * @return {Object} this
1615      * @public
1616      */ 
1617     this.setUTF8 = function (a) {
1618       if (typeof a === 'boolean') { utf8 = a; }
1619       return this;
1620     };
1621
1622     /* private methods */
1623
1624     /**
1625      * Calculate the rmd160 of a raw string
1626      */
1627     function rstr(s) {
1628       s = (utf8) ? utf8Encode(s) : s;
1629       return binl2rstr(binl(rstr2binl(s), s.length * 8));
1630     }
1631
1632     /**
1633      * Calculate the HMAC-rmd160 of a key and some data (raw strings)
1634      */
1635     function rstr_hmac(key, data) {
1636       key = (utf8) ? utf8Encode(key) : key;
1637       data = (utf8) ? utf8Encode(data) : data;
1638       var i, hash,
1639           bkey = rstr2binl(key),
1640           ipad = Array(16), opad = Array(16);
1641
1642       if (bkey.length > 16) { 
1643         bkey = binl(bkey, key.length * 8); 
1644       }
1645       
1646       for (i = 0; i < 16; i+=1) {
1647         ipad[i] = bkey[i] ^ 0x36363636;
1648         opad[i] = bkey[i] ^ 0x5C5C5C5C;
1649       }
1650       hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
1651       return binl2rstr(binl(opad.concat(hash), 512 + 160));
1652     }
1653
1654     /**
1655      * Convert an array of little-endian words to a string
1656      */
1657     function binl2rstr(input) {
1658       var i, output = '', l = input.length * 32;
1659       for (i = 0; i < l; i += 8) {
1660         output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
1661       }
1662       return output;
1663     }
1664
1665     /**
1666      * Calculate the RIPE-MD160 of an array of little-endian words, and a bit length.
1667      */
1668     function binl(x, len) {
1669       var T, j, i, l,
1670           h0 = 0x67452301,
1671           h1 = 0xefcdab89,
1672           h2 = 0x98badcfe,
1673           h3 = 0x10325476,
1674           h4 = 0xc3d2e1f0,
1675           A1, B1, C1, D1, E1,
1676           A2, B2, C2, D2, E2;
1677
1678       /* append padding */
1679       x[len >> 5] |= 0x80 << (len % 32);
1680       x[(((len + 64) >>> 9) << 4) + 14] = len;
1681       l = x.length;
1682       
1683       for (i = 0; i < l; i+=16) {
1684         A1 = A2 = h0; B1 = B2 = h1; C1 = C2 = h2; D1 = D2 = h3; E1 = E2 = h4;
1685         for (j = 0; j <= 79; j+=1) {
1686           T = safe_add(A1, rmd160_f(j, B1, C1, D1));
1687           T = safe_add(T, x[i + rmd160_r1[j]]);
1688           T = safe_add(T, rmd160_K1(j));
1689           T = safe_add(bit_rol(T, rmd160_s1[j]), E1);
1690           A1 = E1; E1 = D1; D1 = bit_rol(C1, 10); C1 = B1; B1 = T;
1691           T = safe_add(A2, rmd160_f(79-j, B2, C2, D2));
1692           T = safe_add(T, x[i + rmd160_r2[j]]);
1693           T = safe_add(T, rmd160_K2(j));
1694           T = safe_add(bit_rol(T, rmd160_s2[j]), E2);
1695           A2 = E2; E2 = D2; D2 = bit_rol(C2, 10); C2 = B2; B2 = T;
1696         }
1697
1698         T = safe_add(h1, safe_add(C1, D2));
1699         h1 = safe_add(h2, safe_add(D1, E2));
1700         h2 = safe_add(h3, safe_add(E1, A2));
1701         h3 = safe_add(h4, safe_add(A1, B2));
1702         h4 = safe_add(h0, safe_add(B1, C2));
1703         h0 = T;
1704       }
1705       return [h0, h1, h2, h3, h4];
1706     }
1707
1708     // specific algorithm methods 
1709     function rmd160_f(j, x, y, z) {
1710       return ( 0 <= j && j <= 15) ? (x ^ y ^ z) :
1711          (16 <= j && j <= 31) ? (x & y) | (~x & z) :
1712          (32 <= j && j <= 47) ? (x | ~y) ^ z :
1713          (48 <= j && j <= 63) ? (x & z) | (y & ~z) :
1714          (64 <= j && j <= 79) ? x ^ (y | ~z) :
1715          'rmd160_f: j out of range';
1716     }
1717
1718     function rmd160_K1(j) {
1719       return ( 0 <= j && j <= 15) ? 0x00000000 :
1720          (16 <= j && j <= 31) ? 0x5a827999 :
1721          (32 <= j && j <= 47) ? 0x6ed9eba1 :
1722          (48 <= j && j <= 63) ? 0x8f1bbcdc :
1723          (64 <= j && j <= 79) ? 0xa953fd4e :
1724          'rmd160_K1: j out of range';
1725     }
1726
1727     function rmd160_K2(j){
1728       return ( 0 <= j && j <= 15) ? 0x50a28be6 :
1729          (16 <= j && j <= 31) ? 0x5c4dd124 :
1730          (32 <= j && j <= 47) ? 0x6d703ef3 :
1731          (48 <= j && j <= 63) ? 0x7a6d76e9 :
1732          (64 <= j && j <= 79) ? 0x00000000 :
1733          'rmd160_K2: j out of range';
1734     }
1735   }
1736 };
1737
1738   // exposes Hashes
1739   (function( window, undefined ) {
1740     var freeExports = false;
1741     if (typeof exports === 'object' ) {
1742       freeExports = exports;
1743       if (exports && typeof global === 'object' && global && global === global.global ) { window = global; }
1744     }
1745
1746     if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
1747       // define as an anonymous module, so, through path mapping, it can be aliased
1748       define(function () { return Hashes; });
1749     }
1750     else if ( freeExports ) {
1751       // in Node.js or RingoJS v0.8.0+
1752       if ( typeof module === 'object' && module && module.exports === freeExports ) {
1753         module.exports = Hashes;
1754       }
1755       // in Narwhal or RingoJS v0.7.0-
1756       else {
1757         freeExports.Hashes = Hashes;
1758       }
1759     }
1760     else {
1761       // in a browser or Rhino
1762       window.Hashes = Hashes;
1763     }
1764   }( this ));
1765 }()); // IIFE
1766 })(window)
1767 },{}],4:[function(require,module,exports){
1768 module.exports = hasKeys
1769
1770 function hasKeys(source) {
1771     return source !== null &&
1772         (typeof source === "object" ||
1773         typeof source === "function")
1774 }
1775
1776 },{}],3:[function(require,module,exports){
1777 var Keys = require("object-keys")
1778 var hasKeys = require("./has-keys")
1779
1780 module.exports = extend
1781
1782 function extend() {
1783     var target = {}
1784
1785     for (var i = 0; i < arguments.length; i++) {
1786         var source = arguments[i]
1787
1788         if (!hasKeys(source)) {
1789             continue
1790         }
1791
1792         var keys = Keys(source)
1793
1794         for (var j = 0; j < keys.length; j++) {
1795             var name = keys[j]
1796             target[name] = source[name]
1797         }
1798     }
1799
1800     return target
1801 }
1802
1803 },{"./has-keys":4,"object-keys":5}],5:[function(require,module,exports){
1804 module.exports = Object.keys || require('./shim');
1805
1806
1807 },{"./shim":6}],6:[function(require,module,exports){
1808 (function () {
1809         "use strict";
1810
1811         // modified from https://github.com/kriskowal/es5-shim
1812         var has = Object.prototype.hasOwnProperty,
1813                 is = require('is'),
1814                 forEach = require('foreach'),
1815                 hasDontEnumBug = !({'toString': null}).propertyIsEnumerable('toString'),
1816                 dontEnums = [
1817                         "toString",
1818                         "toLocaleString",
1819                         "valueOf",
1820                         "hasOwnProperty",
1821                         "isPrototypeOf",
1822                         "propertyIsEnumerable",
1823                         "constructor"
1824                 ],
1825                 keysShim;
1826
1827         keysShim = function keys(object) {
1828                 if (!is.object(object) && !is.array(object)) {
1829                         throw new TypeError("Object.keys called on a non-object");
1830                 }
1831
1832                 var name, theKeys = [];
1833                 for (name in object) {
1834                         if (has.call(object, name)) {
1835                                 theKeys.push(name);
1836                         }
1837                 }
1838
1839                 if (hasDontEnumBug) {
1840                         forEach(dontEnums, function (dontEnum) {
1841                                 if (has.call(object, dontEnum)) {
1842                                         theKeys.push(dontEnum);
1843                                 }
1844                         });
1845                 }
1846                 return theKeys;
1847         };
1848
1849         module.exports = keysShim;
1850 }());
1851
1852
1853 },{"is":7,"foreach":8}],7:[function(require,module,exports){
1854
1855 /**!
1856  * is
1857  * the definitive JavaScript type testing library
1858  * 
1859  * @copyright 2013 Enrico Marino
1860  * @license MIT
1861  */
1862
1863 var objProto = Object.prototype;
1864 var owns = objProto.hasOwnProperty;
1865 var toString = objProto.toString;
1866 var isActualNaN = function (value) {
1867   return value !== value;
1868 };
1869 var NON_HOST_TYPES = {
1870   "boolean": 1,
1871   "number": 1,
1872   "string": 1,
1873   "undefined": 1
1874 };
1875
1876 /**
1877  * Expose `is`
1878  */
1879
1880 var is = module.exports = {};
1881
1882 /**
1883  * Test general.
1884  */
1885
1886 /**
1887  * is.type
1888  * Test if `value` is a type of `type`.
1889  *
1890  * @param {Mixed} value value to test
1891  * @param {String} type type
1892  * @return {Boolean} true if `value` is a type of `type`, false otherwise
1893  * @api public
1894  */
1895
1896 is.a =
1897 is.type = function (value, type) {
1898   return typeof value === type;
1899 };
1900
1901 /**
1902  * is.defined
1903  * Test if `value` is defined.
1904  *
1905  * @param {Mixed} value value to test
1906  * @return {Boolean} true if 'value' is defined, false otherwise
1907  * @api public
1908  */
1909
1910 is.defined = function (value) {
1911   return value !== undefined;
1912 };
1913
1914 /**
1915  * is.empty
1916  * Test if `value` is empty.
1917  *
1918  * @param {Mixed} value value to test
1919  * @return {Boolean} true if `value` is empty, false otherwise
1920  * @api public
1921  */
1922
1923 is.empty = function (value) {
1924   var type = toString.call(value);
1925   var key;
1926
1927   if ('[object Array]' === type || '[object Arguments]' === type) {
1928     return value.length === 0;
1929   }
1930
1931   if ('[object Object]' === type) {
1932     for (key in value) if (owns.call(value, key)) return false;
1933     return true;
1934   }
1935
1936   if ('[object String]' === type) {
1937     return '' === value;
1938   }
1939
1940   return false;
1941 };
1942
1943 /**
1944  * is.equal
1945  * Test if `value` is equal to `other`.
1946  *
1947  * @param {Mixed} value value to test
1948  * @param {Mixed} other value to compare with
1949  * @return {Boolean} true if `value` is equal to `other`, false otherwise
1950  */
1951
1952 is.equal = function (value, other) {
1953   var type = toString.call(value)
1954   var key;
1955
1956   if (type !== toString.call(other)) {
1957     return false;
1958   }
1959
1960   if ('[object Object]' === type) {
1961     for (key in value) {
1962       if (!is.equal(value[key], other[key])) {
1963         return false;
1964       }
1965     }
1966     return true;
1967   }
1968
1969   if ('[object Array]' === type) {
1970     key = value.length;
1971     if (key !== other.length) {
1972       return false;
1973     }
1974     while (--key) {
1975       if (!is.equal(value[key], other[key])) {
1976         return false;
1977       }
1978     }
1979     return true;
1980   }
1981
1982   if ('[object Function]' === type) {
1983     return value.prototype === other.prototype;
1984   }
1985
1986   if ('[object Date]' === type) {
1987     return value.getTime() === other.getTime();
1988   }
1989
1990   return value === other;
1991 };
1992
1993 /**
1994  * is.hosted
1995  * Test if `value` is hosted by `host`.
1996  *
1997  * @param {Mixed} value to test
1998  * @param {Mixed} host host to test with
1999  * @return {Boolean} true if `value` is hosted by `host`, false otherwise
2000  * @api public
2001  */
2002
2003 is.hosted = function (value, host) {
2004   var type = typeof host[value];
2005   return type === 'object' ? !!host[value] : !NON_HOST_TYPES[type];
2006 };
2007
2008 /**
2009  * is.instance
2010  * Test if `value` is an instance of `constructor`.
2011  *
2012  * @param {Mixed} value value to test
2013  * @return {Boolean} true if `value` is an instance of `constructor`
2014  * @api public
2015  */
2016
2017 is.instance = is['instanceof'] = function (value, constructor) {
2018   return value instanceof constructor;
2019 };
2020
2021 /**
2022  * is.null
2023  * Test if `value` is null.
2024  *
2025  * @param {Mixed} value value to test
2026  * @return {Boolean} true if `value` is null, false otherwise
2027  * @api public
2028  */
2029
2030 is['null'] = function (value) {
2031   return value === null;
2032 };
2033
2034 /**
2035  * is.undefined
2036  * Test if `value` is undefined.
2037  *
2038  * @param {Mixed} value value to test
2039  * @return {Boolean} true if `value` is undefined, false otherwise
2040  * @api public
2041  */
2042
2043 is.undefined = function (value) {
2044   return value === undefined;
2045 };
2046
2047 /**
2048  * Test arguments.
2049  */
2050
2051 /**
2052  * is.arguments
2053  * Test if `value` is an arguments object.
2054  *
2055  * @param {Mixed} value value to test
2056  * @return {Boolean} true if `value` is an arguments object, false otherwise
2057  * @api public
2058  */
2059
2060 is.arguments = function (value) {
2061   var isStandardArguments = '[object Arguments]' === toString.call(value);
2062   var isOldArguments = !is.array(value) && is.arraylike(value) && is.object(value) && is.fn(value.callee);
2063   return isStandardArguments || isOldArguments;
2064 };
2065
2066 /**
2067  * Test array.
2068  */
2069
2070 /**
2071  * is.array
2072  * Test if 'value' is an array.
2073  *
2074  * @param {Mixed} value value to test
2075  * @return {Boolean} true if `value` is an array, false otherwise
2076  * @api public
2077  */
2078
2079 is.array = function (value) {
2080   return '[object Array]' === toString.call(value);
2081 };
2082
2083 /**
2084  * is.arguments.empty
2085  * Test if `value` is an empty arguments object.
2086  *
2087  * @param {Mixed} value value to test
2088  * @return {Boolean} true if `value` is an empty arguments object, false otherwise
2089  * @api public
2090  */
2091 is.arguments.empty = function (value) {
2092   return is.arguments(value) && value.length === 0;
2093 };
2094
2095 /**
2096  * is.array.empty
2097  * Test if `value` is an empty array.
2098  *
2099  * @param {Mixed} value value to test
2100  * @return {Boolean} true if `value` is an empty array, false otherwise
2101  * @api public
2102  */
2103 is.array.empty = function (value) {
2104   return is.array(value) && value.length === 0;
2105 };
2106
2107 /**
2108  * is.arraylike
2109  * Test if `value` is an arraylike object.
2110  *
2111  * @param {Mixed} value value to test
2112  * @return {Boolean} true if `value` is an arguments object, false otherwise
2113  * @api public
2114  */
2115
2116 is.arraylike = function (value) {
2117   return !!value && !is.boolean(value)
2118     && owns.call(value, 'length')
2119     && isFinite(value.length)
2120     && is.number(value.length)
2121     && value.length >= 0;
2122 };
2123
2124 /**
2125  * Test boolean.
2126  */
2127
2128 /**
2129  * is.boolean
2130  * Test if `value` is a boolean.
2131  *
2132  * @param {Mixed} value value to test
2133  * @return {Boolean} true if `value` is a boolean, false otherwise
2134  * @api public
2135  */
2136
2137 is.boolean = function (value) {
2138   return '[object Boolean]' === toString.call(value);
2139 };
2140
2141 /**
2142  * is.false
2143  * Test if `value` is false.
2144  *
2145  * @param {Mixed} value value to test
2146  * @return {Boolean} true if `value` is false, false otherwise
2147  * @api public
2148  */
2149
2150 is['false'] = function (value) {
2151   return is.boolean(value) && (value === false || value.valueOf() === false);
2152 };
2153
2154 /**
2155  * is.true
2156  * Test if `value` is true.
2157  *
2158  * @param {Mixed} value value to test
2159  * @return {Boolean} true if `value` is true, false otherwise
2160  * @api public
2161  */
2162
2163 is['true'] = function (value) {
2164   return is.boolean(value) && (value === true || value.valueOf() === true);
2165 };
2166
2167 /**
2168  * Test date.
2169  */
2170
2171 /**
2172  * is.date
2173  * Test if `value` is a date.
2174  *
2175  * @param {Mixed} value value to test
2176  * @return {Boolean} true if `value` is a date, false otherwise
2177  * @api public
2178  */
2179
2180 is.date = function (value) {
2181   return '[object Date]' === toString.call(value);
2182 };
2183
2184 /**
2185  * Test element.
2186  */
2187
2188 /**
2189  * is.element
2190  * Test if `value` is an html element.
2191  *
2192  * @param {Mixed} value value to test
2193  * @return {Boolean} true if `value` is an HTML Element, false otherwise
2194  * @api public
2195  */
2196
2197 is.element = function (value) {
2198   return value !== undefined
2199     && typeof HTMLElement !== 'undefined'
2200     && value instanceof HTMLElement
2201     && value.nodeType === 1;
2202 };
2203
2204 /**
2205  * Test error.
2206  */
2207
2208 /**
2209  * is.error
2210  * Test if `value` is an error object.
2211  *
2212  * @param {Mixed} value value to test
2213  * @return {Boolean} true if `value` is an error object, false otherwise
2214  * @api public
2215  */
2216
2217 is.error = function (value) {
2218   return '[object Error]' === toString.call(value);
2219 };
2220
2221 /**
2222  * Test function.
2223  */
2224
2225 /**
2226  * is.fn / is.function (deprecated)
2227  * Test if `value` is a function.
2228  *
2229  * @param {Mixed} value value to test
2230  * @return {Boolean} true if `value` is a function, false otherwise
2231  * @api public
2232  */
2233
2234 is.fn = is['function'] = function (value) {
2235   var isAlert = typeof window !== 'undefined' && value === window.alert;
2236   return isAlert || '[object Function]' === toString.call(value);
2237 };
2238
2239 /**
2240  * Test number.
2241  */
2242
2243 /**
2244  * is.number
2245  * Test if `value` is a number.
2246  *
2247  * @param {Mixed} value value to test
2248  * @return {Boolean} true if `value` is a number, false otherwise
2249  * @api public
2250  */
2251
2252 is.number = function (value) {
2253   return '[object Number]' === toString.call(value);
2254 };
2255
2256 /**
2257  * is.infinite
2258  * Test if `value` is positive or negative infinity.
2259  *
2260  * @param {Mixed} value value to test
2261  * @return {Boolean} true if `value` is positive or negative Infinity, false otherwise
2262  * @api public
2263  */
2264 is.infinite = function (value) {
2265   return value === Infinity || value === -Infinity;
2266 };
2267
2268 /**
2269  * is.decimal
2270  * Test if `value` is a decimal number.
2271  *
2272  * @param {Mixed} value value to test
2273  * @return {Boolean} true if `value` is a decimal number, false otherwise
2274  * @api public
2275  */
2276
2277 is.decimal = function (value) {
2278   return is.number(value) && !isActualNaN(value) && value % 1 !== 0;
2279 };
2280
2281 /**
2282  * is.divisibleBy
2283  * Test if `value` is divisible by `n`.
2284  *
2285  * @param {Number} value value to test
2286  * @param {Number} n dividend
2287  * @return {Boolean} true if `value` is divisible by `n`, false otherwise
2288  * @api public
2289  */
2290
2291 is.divisibleBy = function (value, n) {
2292   var isDividendInfinite = is.infinite(value);
2293   var isDivisorInfinite = is.infinite(n);
2294   var isNonZeroNumber = is.number(value) && !isActualNaN(value) && is.number(n) && !isActualNaN(n) && n !== 0;
2295   return isDividendInfinite || isDivisorInfinite || (isNonZeroNumber && value % n === 0);
2296 };
2297
2298 /**
2299  * is.int
2300  * Test if `value` is an integer.
2301  *
2302  * @param value to test
2303  * @return {Boolean} true if `value` is an integer, false otherwise
2304  * @api public
2305  */
2306
2307 is.int = function (value) {
2308   return is.number(value) && !isActualNaN(value) && value % 1 === 0;
2309 };
2310
2311 /**
2312  * is.maximum
2313  * Test if `value` is greater than 'others' values.
2314  *
2315  * @param {Number} value value to test
2316  * @param {Array} others values to compare with
2317  * @return {Boolean} true if `value` is greater than `others` values
2318  * @api public
2319  */
2320
2321 is.maximum = function (value, others) {
2322   if (isActualNaN(value)) {
2323     throw new TypeError('NaN is not a valid value');
2324   } else if (!is.arraylike(others)) {
2325     throw new TypeError('second argument must be array-like');
2326   }
2327   var len = others.length;
2328
2329   while (--len >= 0) {
2330     if (value < others[len]) {
2331       return false;
2332     }
2333   }
2334
2335   return true;
2336 };
2337
2338 /**
2339  * is.minimum
2340  * Test if `value` is less than `others` values.
2341  *
2342  * @param {Number} value value to test
2343  * @param {Array} others values to compare with
2344  * @return {Boolean} true if `value` is less than `others` values
2345  * @api public
2346  */
2347
2348 is.minimum = function (value, others) {
2349   if (isActualNaN(value)) {
2350     throw new TypeError('NaN is not a valid value');
2351   } else if (!is.arraylike(others)) {
2352     throw new TypeError('second argument must be array-like');
2353   }
2354   var len = others.length;
2355
2356   while (--len >= 0) {
2357     if (value > others[len]) {
2358       return false;
2359     }
2360   }
2361
2362   return true;
2363 };
2364
2365 /**
2366  * is.nan
2367  * Test if `value` is not a number.
2368  *
2369  * @param {Mixed} value value to test
2370  * @return {Boolean} true if `value` is not a number, false otherwise
2371  * @api public
2372  */
2373
2374 is.nan = function (value) {
2375   return !is.number(value) || value !== value;
2376 };
2377
2378 /**
2379  * is.even
2380  * Test if `value` is an even number.
2381  *
2382  * @param {Number} value value to test
2383  * @return {Boolean} true if `value` is an even number, false otherwise
2384  * @api public
2385  */
2386
2387 is.even = function (value) {
2388   return is.infinite(value) || (is.number(value) && value === value && value % 2 === 0);
2389 };
2390
2391 /**
2392  * is.odd
2393  * Test if `value` is an odd number.
2394  *
2395  * @param {Number} value value to test
2396  * @return {Boolean} true if `value` is an odd number, false otherwise
2397  * @api public
2398  */
2399
2400 is.odd = function (value) {
2401   return is.infinite(value) || (is.number(value) && value === value && value % 2 !== 0);
2402 };
2403
2404 /**
2405  * is.ge
2406  * Test if `value` is greater than or equal to `other`.
2407  *
2408  * @param {Number} value value to test
2409  * @param {Number} other value to compare with
2410  * @return {Boolean}
2411  * @api public
2412  */
2413
2414 is.ge = function (value, other) {
2415   if (isActualNaN(value) || isActualNaN(other)) {
2416     throw new TypeError('NaN is not a valid value');
2417   }
2418   return !is.infinite(value) && !is.infinite(other) && value >= other;
2419 };
2420
2421 /**
2422  * is.gt
2423  * Test if `value` is greater than `other`.
2424  *
2425  * @param {Number} value value to test
2426  * @param {Number} other value to compare with
2427  * @return {Boolean}
2428  * @api public
2429  */
2430
2431 is.gt = function (value, other) {
2432   if (isActualNaN(value) || isActualNaN(other)) {
2433     throw new TypeError('NaN is not a valid value');
2434   }
2435   return !is.infinite(value) && !is.infinite(other) && value > other;
2436 };
2437
2438 /**
2439  * is.le
2440  * Test if `value` is less than or equal to `other`.
2441  *
2442  * @param {Number} value value to test
2443  * @param {Number} other value to compare with
2444  * @return {Boolean} if 'value' is less than or equal to 'other'
2445  * @api public
2446  */
2447
2448 is.le = function (value, other) {
2449   if (isActualNaN(value) || isActualNaN(other)) {
2450     throw new TypeError('NaN is not a valid value');
2451   }
2452   return !is.infinite(value) && !is.infinite(other) && value <= other;
2453 };
2454
2455 /**
2456  * is.lt
2457  * Test if `value` is less than `other`.
2458  *
2459  * @param {Number} value value to test
2460  * @param {Number} other value to compare with
2461  * @return {Boolean} if `value` is less than `other`
2462  * @api public
2463  */
2464
2465 is.lt = function (value, other) {
2466   if (isActualNaN(value) || isActualNaN(other)) {
2467     throw new TypeError('NaN is not a valid value');
2468   }
2469   return !is.infinite(value) && !is.infinite(other) && value < other;
2470 };
2471
2472 /**
2473  * is.within
2474  * Test if `value` is within `start` and `finish`.
2475  *
2476  * @param {Number} value value to test
2477  * @param {Number} start lower bound
2478  * @param {Number} finish upper bound
2479  * @return {Boolean} true if 'value' is is within 'start' and 'finish'
2480  * @api public
2481  */
2482 is.within = function (value, start, finish) {
2483   if (isActualNaN(value) || isActualNaN(start) || isActualNaN(finish)) {
2484     throw new TypeError('NaN is not a valid value');
2485   } else if (!is.number(value) || !is.number(start) || !is.number(finish)) {
2486     throw new TypeError('all arguments must be numbers');
2487   }
2488   var isAnyInfinite = is.infinite(value) || is.infinite(start) || is.infinite(finish);
2489   return isAnyInfinite || (value >= start && value <= finish);
2490 };
2491
2492 /**
2493  * Test object.
2494  */
2495
2496 /**
2497  * is.object
2498  * Test if `value` is an object.
2499  *
2500  * @param {Mixed} value value to test
2501  * @return {Boolean} true if `value` is an object, false otherwise
2502  * @api public
2503  */
2504
2505 is.object = function (value) {
2506   return value && '[object Object]' === toString.call(value);
2507 };
2508
2509 /**
2510  * is.hash
2511  * Test if `value` is a hash - a plain object literal.
2512  *
2513  * @param {Mixed} value value to test
2514  * @return {Boolean} true if `value` is a hash, false otherwise
2515  * @api public
2516  */
2517
2518 is.hash = function (value) {
2519   return is.object(value) && value.constructor === Object && !value.nodeType && !value.setInterval;
2520 };
2521
2522 /**
2523  * Test regexp.
2524  */
2525
2526 /**
2527  * is.regexp
2528  * Test if `value` is a regular expression.
2529  *
2530  * @param {Mixed} value value to test
2531  * @return {Boolean} true if `value` is a regexp, false otherwise
2532  * @api public
2533  */
2534
2535 is.regexp = function (value) {
2536   return '[object RegExp]' === toString.call(value);
2537 };
2538
2539 /**
2540  * Test string.
2541  */
2542
2543 /**
2544  * is.string
2545  * Test if `value` is a string.
2546  *
2547  * @param {Mixed} value value to test
2548  * @return {Boolean} true if 'value' is a string, false otherwise
2549  * @api public
2550  */
2551
2552 is.string = function (value) {
2553   return '[object String]' === toString.call(value);
2554 };
2555
2556
2557 },{}],8:[function(require,module,exports){
2558
2559 var hasOwn = Object.prototype.hasOwnProperty;
2560
2561 module.exports = function forEach (obj, fn, ctx) {
2562     if (typeof fn !== 'function') {
2563         throw new TypeError('iterator must be a function');
2564     }
2565     var l = obj.length;
2566     if (l === +l) {
2567         for (var i = 0; i < l; i++) {
2568             fn.call(ctx, obj[i], i, obj);
2569         }
2570     } else {
2571         for (var k in obj) {
2572             if (hasOwn.call(obj, k)) {
2573                 fn.call(ctx, obj[k], k, obj);
2574             }
2575         }
2576     }
2577 };
2578
2579
2580 },{}]},{},[1])(1)
2581 });
2582 ;