Files

15 lines
4.7 KiB
JavaScript

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/*! Based on http://www.webtoolkit.info/javascript_md5.html */class n{static hash(S){let t,s,c,a,C,e,r,F,o;S=n.utf8Encode(S);const x=n.convertToWordArray(S);for(e=1732584193,r=4023233417,F=2562383102,o=271733878,t=0;t<x.length;t+=16)s=e,c=r,a=F,C=o,e=n.FF(e,r,F,o,x[t],7,3614090360),o=n.FF(o,e,r,F,x[t+1],12,3905402710),F=n.FF(F,o,e,r,x[t+2],17,606105819),r=n.FF(r,F,o,e,x[t+3],22,3250441966),e=n.FF(e,r,F,o,x[t+4],7,4118548399),o=n.FF(o,e,r,F,x[t+5],12,1200080426),F=n.FF(F,o,e,r,x[t+6],17,2821735955),r=n.FF(r,F,o,e,x[t+7],22,4249261313),e=n.FF(e,r,F,o,x[t+8],7,1770035416),o=n.FF(o,e,r,F,x[t+9],12,2336552879),F=n.FF(F,o,e,r,x[t+10],17,4294925233),r=n.FF(r,F,o,e,x[t+11],22,2304563134),e=n.FF(e,r,F,o,x[t+12],7,1804603682),o=n.FF(o,e,r,F,x[t+13],12,4254626195),F=n.FF(F,o,e,r,x[t+14],17,2792965006),r=n.FF(r,F,o,e,x[t+15],22,1236535329),e=n.GG(e,r,F,o,x[t+1],5,4129170786),o=n.GG(o,e,r,F,x[t+6],9,3225465664),F=n.GG(F,o,e,r,x[t+11],14,643717713),r=n.GG(r,F,o,e,x[t],20,3921069994),e=n.GG(e,r,F,o,x[t+5],5,3593408605),o=n.GG(o,e,r,F,x[t+10],9,38016083),F=n.GG(F,o,e,r,x[t+15],14,3634488961),r=n.GG(r,F,o,e,x[t+4],20,3889429448),e=n.GG(e,r,F,o,x[t+9],5,568446438),o=n.GG(o,e,r,F,x[t+14],9,3275163606),F=n.GG(F,o,e,r,x[t+3],14,4107603335),r=n.GG(r,F,o,e,x[t+8],20,1163531501),e=n.GG(e,r,F,o,x[t+13],5,2850285829),o=n.GG(o,e,r,F,x[t+2],9,4243563512),F=n.GG(F,o,e,r,x[t+7],14,1735328473),r=n.GG(r,F,o,e,x[t+12],20,2368359562),e=n.HH(e,r,F,o,x[t+5],4,4294588738),o=n.HH(o,e,r,F,x[t+8],11,2272392833),F=n.HH(F,o,e,r,x[t+11],16,1839030562),r=n.HH(r,F,o,e,x[t+14],23,4259657740),e=n.HH(e,r,F,o,x[t+1],4,2763975236),o=n.HH(o,e,r,F,x[t+4],11,1272893353),F=n.HH(F,o,e,r,x[t+7],16,4139469664),r=n.HH(r,F,o,e,x[t+10],23,3200236656),e=n.HH(e,r,F,o,x[t+13],4,681279174),o=n.HH(o,e,r,F,x[t],11,3936430074),F=n.HH(F,o,e,r,x[t+3],16,3572445317),r=n.HH(r,F,o,e,x[t+6],23,76029189),e=n.HH(e,r,F,o,x[t+9],4,3654602809),o=n.HH(o,e,r,F,x[t+12],11,3873151461),F=n.HH(F,o,e,r,x[t+15],16,530742520),r=n.HH(r,F,o,e,x[t+2],23,3299628645),e=n.II(e,r,F,o,x[t],6,4096336452),o=n.II(o,e,r,F,x[t+7],10,1126891415),F=n.II(F,o,e,r,x[t+14],15,2878612391),r=n.II(r,F,o,e,x[t+5],21,4237533241),e=n.II(e,r,F,o,x[t+12],6,1700485571),o=n.II(o,e,r,F,x[t+3],10,2399980690),F=n.II(F,o,e,r,x[t+10],15,4293915773),r=n.II(r,F,o,e,x[t+1],21,2240044497),e=n.II(e,r,F,o,x[t+8],6,1873313359),o=n.II(o,e,r,F,x[t+15],10,4264355552),F=n.II(F,o,e,r,x[t+6],15,2734768916),r=n.II(r,F,o,e,x[t+13],21,1309151649),e=n.II(e,r,F,o,x[t+4],6,4149444226),o=n.II(o,e,r,F,x[t+11],10,3174756917),F=n.II(F,o,e,r,x[t+2],15,718787259),r=n.II(r,F,o,e,x[t+9],21,3951481745),e=n.addUnsigned(e,s),r=n.addUnsigned(r,c),F=n.addUnsigned(F,a),o=n.addUnsigned(o,C);return(n.wordToHex(e)+n.wordToHex(r)+n.wordToHex(F)+n.wordToHex(o)).toLowerCase()}static rotateLeft(S,t){return S<<t|S>>>32-t}static addUnsigned(S,t){const s=S&2147483648,c=t&2147483648,a=S&1073741824,C=t&1073741824,e=(S&1073741823)+(t&1073741823);return a&C?e^2147483648^s^c:a|C?e&1073741824?e^3221225472^s^c:e^1073741824^s^c:e^s^c}static F(S,t,s){return S&t|~S&s}static G(S,t,s){return S&s|t&~s}static H(S,t,s){return S^t^s}static I(S,t,s){return t^(S|~s)}static FF(S,t,s,c,a,C,e){return S=n.addUnsigned(S,n.addUnsigned(n.addUnsigned(n.F(t,s,c),a),e)),n.addUnsigned(n.rotateLeft(S,C),t)}static GG(S,t,s,c,a,C,e){return S=n.addUnsigned(S,n.addUnsigned(n.addUnsigned(n.G(t,s,c),a),e)),n.addUnsigned(n.rotateLeft(S,C),t)}static HH(S,t,s,c,a,C,e){return S=n.addUnsigned(S,n.addUnsigned(n.addUnsigned(n.H(t,s,c),a),e)),n.addUnsigned(n.rotateLeft(S,C),t)}static II(S,t,s,c,a,C,e){return S=n.addUnsigned(S,n.addUnsigned(n.addUnsigned(n.I(t,s,c),a),e)),n.addUnsigned(n.rotateLeft(S,C),t)}static convertToWordArray(S){let t;const s=S.length,c=s+8,C=((c-c%64)/64+1)*16,e=Array(C-1);let r=0,F=0;for(;F<s;)t=(F-F%4)/4,r=F%4*8,e[t]=e[t]|S.charCodeAt(F)<<r,F++;return t=(F-F%4)/4,r=F%4*8,e[t]=e[t]|128<<r,e[C-2]=s<<3,e[C-1]=s>>>29,e}static wordToHex(S){let t="",s="",c,a;for(a=0;a<=3;a++)c=S>>>a*8&255,s="0"+c.toString(16),t=t+s.substr(s.length-2,2);return t}static utf8Encode(S){S=S.replace(/\r\n/g,`
`);let t="";for(let s=0;s<S.length;s++){const c=S.charCodeAt(s);c<128?t+=String.fromCharCode(c):c>127&&c<2048?(t+=String.fromCharCode(c>>6|192),t+=String.fromCharCode(c&63|128)):(t+=String.fromCharCode(c>>12|224),t+=String.fromCharCode(c>>6&63|128),t+=String.fromCharCode(c&63|128))}return t}}export{n as default};