crypt.js 1.26 KB
"use strict";!function(){var u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n={rotl:function(r,t){return r<<t|r>>>32-t},rotr:function(r,t){return r<<32-t|r>>>t},endian:function(r){if(r.constructor==Number)return 16711935&n.rotl(r,8)|4278255360&n.rotl(r,24);for(var t=0;t<r.length;t++)r[t]=n.endian(r[t]);return r},randomBytes:function(r){for(var t=[];0<r;r--)t.push(Math.floor(256*Math.random()));return t},bytesToWords:function(r){for(var t=[],n=0,o=0;n<r.length;n++,o+=8)t[o>>>5]|=r[n]<<24-o%32;return t},wordsToBytes:function(r){for(var t=[],n=0;n<32*r.length;n+=8)t.push(r[n>>>5]>>>24-n%32&255);return t},bytesToHex:function(r){for(var t=[],n=0;n<r.length;n++)t.push((r[n]>>>4).toString(16)),t.push((15&r[n]).toString(16));return t.join("")},hexToBytes:function(r){for(var t=[],n=0;n<r.length;n+=2)t.push(parseInt(r.substr(n,2),16));return t},bytesToBase64:function(r){for(var t=[],n=0;n<r.length;n+=3)for(var o=r[n]<<16|r[n+1]<<8|r[n+2],e=0;e<4;e++)8*n+6*e<=8*r.length?t.push(u.charAt(o>>>6*(3-e)&63)):t.push("=");return t.join("")},base64ToBytes:function(r){r=r.replace(/[^A-Z0-9+\/]/gi,"");for(var t=[],n=0,o=0;n<r.length;o=++n%4)0!=o&&t.push((u.indexOf(r.charAt(n-1))&Math.pow(2,-2*o+8)-1)<<2*o|u.indexOf(r.charAt(n))>>>6-2*o);return t}};module.exports=n}();