Permalink
Browse files

1506-character bmw implementation :D

  • Loading branch information...
1 parent bdf6761 commit 6dcfda6dc8be33226098565a33fbb3efd306dab2 Chris Drost committed May 22, 2010
Showing with 3 additions and 4 deletions.
  1. +2 −3 bmw.js
  2. +1 −1 bmw.min.js
View
@@ -76,8 +76,7 @@ var bmw = (function () {
return (n < 16) ? x >>> n : x << (n - 16);
};
// There are also some erratic expansion constants, which are defined here:
- ec_s = "+-+++,+-++-,++-++,+-++-,+--++,+-+-+,-+--+,--+--,+-+--,++-+-,+---+,---++,++--+,+++++,+-+--,---++"
- .split(",");
+ ec_s = [29, 13, 27, 13, 25, 21, 18, 4, 5, 11, 17, 24, 19, 31, 5, 24];
ec_n = [5, 7, 10, 13, 14];
ec2_rot = [0, 3, 7, 13, 16, 19, 23, 27];
@@ -93,7 +92,7 @@ var bmw = (function () {
for (j = 0; j < 5; j += 1) {
k = (i + ec_n[j]) % 16;
b = H[k] ^ m[k];
- a += ec_s[i].charAt(j) === "+" ? b : -b;
+ a += (ec_s[i] >> j) % 2 ? b : -b;
}
Q[i] = H[(i + 1) % 16] + s(a, i % 5);
}
View
@@ -1 +1 @@
-bmw=(function(){var e,f,u,g,h,l,o,p,q,r,t,v,w,s,y;r=function(n){return("00"+n.toString(16)).slice(-2)};t=function(n){return r(n&255)+r(n>>>8)+r(n>>>16)+r(n>>>24)};e=[];f=[];g=[];for(u=0;u<16;u+=1){f[u]=0xaaaaaaa0+u;e[u]=0x40414243+u*0x04040404;g[u]=(u+16)*0x5555555}w=function(x,n){return(x<<n)+(x>>>(32-n))};h=[19,23,25,29,4,8,12,15,3,2,1,2,1,1,2,2];s=function(x,n){return(n<4)?w(x,h[n])^w(x,h[n+4])^(x<<h[n+8])^(x>>>h[n+12]):x^(x>>>n-3)};l=[21,7,5,1,3,22,4,11,24,6,22,20,3,4,7,2,5,24,21,21,16,6,22,18];y=function(x,n){n=l[n];return(n<16)?x>>>n:x<<(n-16)};o="+-+++,+-++-,++-++,+-++-,+--++,+-+-+,-+--+,--+--,+-+--,++-+-,+---+,---++,++--+,+++++,+-+--,---++".split(",");p=[5,7,10,13,14];q=[0,3,7,13,16,19,23,27];v=function(m,H){var c,d,i,j,k,a,b,Q;Q=[];for(i=0;i<16;i+=1){a=0;for(j=0;j<5;j+=1){k=(i+p[j])%16;b=H[k]^m[k];a+=o[i].charAt(j)==="+"?b:-b}Q[i]=H[(i+1)%16]+s(a,i%5)}for(i=0;i<16;i+=1){a=(i+3)%16;b=(i+10)%16;Q[i+16]=H[(i+7)%16]^(g[i]+w(m[i],1+i)+w(m[a],1+a)-w(m[b],1+b));for(k=1;k<17;k+=1){a=Q[i+k-1];Q[i+16]+=(i<2)?s(a,k%4):(k>14)?s(a,k-11):(k%2)?a:w(a,q[k/2])}}c=d=0;for(i=16;i<24;i+=1){c^=Q[i];d^=Q[i+8]}d^=c;for(i=0;i<16;i+=1){H[i]=(i<8)?(c^Q[i]^Q[i+24])+(m[i]^y(d,i)^y(Q[i+16],i+16)):(d^m[i]^Q[i+16])+(Q[i]^y(c,i)^Q[16+(i-1)%8])+w(H[(i-4)%8],i+1)}return H};return function(a){var b,i,c,H;b=16*a.length;a+="\u0080";while(a.length%32!==28){a+="\u0000"}c=[];for(i=0;i<a.length;i+=2){c.push(a.charCodeAt(i)+65536*a.charCodeAt(i+1))}c.push(b);c.push(0);H=e.slice(0);for(i=0;i<c.length;i+=16){v(c.slice(i,i+16),H)}return v(H,f.slice(0)).slice(8,16).map(t).join("")}}());
+bmw=(function(){var e,f,u,g,h,l,o,p,q,r,t,v,w,s,y;r=function(n){return("00"+n.toString(16)).slice(-2)};t=function(n){return r(n&255)+r(n>>>8)+r(n>>>16)+r(n>>>24)};e=[];f=[];g=[];for(u=0;u<16;u+=1){f[u]=0xaaaaaaa0+u;e[u]=0x40414243+u*0x04040404;g[u]=(u+16)*0x5555555}w=function(x,n){return(x<<n)+(x>>>(32-n))};h=[19,23,25,29,4,8,12,15,3,2,1,2,1,1,2,2];s=function(x,n){return(n<4)?w(x,h[n])^w(x,h[n+4])^(x<<h[n+8])^(x>>>h[n+12]):x^(x>>>n-3)};l=[21,7,5,1,3,22,4,11,24,6,22,20,3,4,7,2,5,24,21,21,16,6,22,18];y=function(x,n){n=l[n];return(n<16)?x>>>n:x<<(n-16)};o=[29,13,27,13,25,21,18,4,5,11,17,24,19,31,5,24];p=[5,7,10,13,14];q=[0,3,7,13,16,19,23,27];v=function(m,H){var c,d,i,j,k,a,b,Q;Q=[];for(i=0;i<16;i+=1){a=0;for(j=0;j<5;j+=1){k=(i+p[j])%16;b=H[k]^m[k];a+=(o[i]>>j)%2?b:-b}Q[i]=H[(i+1)%16]+s(a,i%5)}for(i=0;i<16;i+=1){a=(i+3)%16;b=(i+10)%16;Q[i+16]=H[(i+7)%16]^(g[i]+w(m[i],1+i)+w(m[a],1+a)-w(m[b],1+b));for(k=1;k<17;k+=1){a=Q[i+k-1];Q[i+16]+=(i<2)?s(a,k%4):(k>14)?s(a,k-11):(k%2)?a:w(a,q[k/2])}}c=d=0;for(i=16;i<24;i+=1){c^=Q[i];d^=Q[i+8]}d^=c;for(i=0;i<16;i+=1){H[i]=(i<8)?(c^Q[i]^Q[i+24])+(m[i]^y(d,i)^y(Q[i+16],i+16)):(d^m[i]^Q[i+16])+(Q[i]^y(c,i)^Q[16+(i-1)%8])+w(H[(i-4)%8],i+1)}return H};return function(a){var b,i,c,H;b=16*a.length;a+="\u0080";while(a.length%32!==28){a+="\u0000"}c=[];for(i=0;i<a.length;i+=2){c.push(a.charCodeAt(i)+65536*a.charCodeAt(i+1))}c.push(b);c.push(0);H=e.slice(0);for(i=0;i<c.length;i+=16){v(c.slice(i,i+16),H)}return v(H,f.slice(0)).slice(8,16).map(t).join("")}}());

0 comments on commit 6dcfda6

Please sign in to comment.