root / trunk / web / dojo / dojox / encoding / digests / _base.js
History | View | Annotate | Download (1.44 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.encoding.digests._base"]){ |
||
9 | dojo._hasResource["dojox.encoding.digests._base"]=true; |
||
10 | dojo.provide("dojox.encoding.digests._base");
|
||
11 | (function(){
|
||
12 | var d=dojox.encoding.digests;
|
||
13 | d.outputTypes={Base64:0,Hex:1,String:2,Raw:3}; |
||
14 | d.addWords=function(a,b){ |
||
15 | var l=(a&65535)+(b&65535); |
||
16 | var m=(a>>16)+(b>>16)+(l>>16); |
||
17 | return (m<<16)|(l&65535); |
||
18 | }; |
||
19 | var _1=8; |
||
20 | var _2=(1<<_1)-1; |
||
21 | d.stringToWord=function(s){ |
||
22 | var wa=[];
|
||
23 | for(var i=0,l=s.length*_1;i<l;i+=_1){ |
||
24 | wa[i>>5]|=(s.charCodeAt(i/_1)&_2)<<(i%32); |
||
25 | } |
||
26 | return wa;
|
||
27 | }; |
||
28 | d.wordToString=function(wa){ |
||
29 | var s=[];
|
||
30 | for(var i=0,l=wa.length*32;i<l;i+=_1){ |
||
31 | s.push(String.fromCharCode((wa[i>>5]>>>(i%32))&_2)); |
||
32 | } |
||
33 | return s.join(""); |
||
34 | }; |
||
35 | d.wordToHex=function(wa){ |
||
36 | var h="0123456789abcdef",s=[]; |
||
37 | for(var i=0,l=wa.length*4;i<l;i++){ |
||
38 | s.push(h.charAt((wa[i>>2]>>((i%4)*8+4))&15)+h.charAt((wa[i>>2]>>((i%4)*8))&15)); |
||
39 | } |
||
40 | return s.join(""); |
||
41 | }; |
||
42 | d.wordToBase64=function(wa){ |
||
43 | var p="=",_3="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=[]; |
||
44 | for(var i=0,l=wa.length*4;i<l;i+=3){ |
||
45 | var t=(((wa[i>>2]>>8*(i%4))&255)<<16)|(((wa[i+1>>2]>>8*((i+1)%4))&255)<<8)|((wa[i+2>>2]>>8*((i+2)%4))&255); |
||
46 | for(var j=0;j<4;j++){ |
||
47 | if(i*8+j*6>wa.length*32){ |
||
48 | s.push(p); |
||
49 | }else{
|
||
50 | s.push(_3.charAt((t>>6*(3-j))&63)); |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | return s.join(""); |
||
55 | }; |
||
56 | })(); |
||
57 | } |