[LON-CAPA-cvs] cvs: loncom /auth londes.js

www lon-capa-cvs@mail.lon-capa.org
Sat, 23 Mar 2002 10:34:48 -0000


www		Sat Mar 23 05:34:48 2002 EDT

  Modified files:              
    /loncom/auth	londes.js 
  Log:
  To deal with Internet Explorer bitwise operation bug, first put all
  AND and OR into a function. Not finished yet.
  
  
Index: loncom/auth/londes.js
diff -u loncom/auth/londes.js:1.2 loncom/auth/londes.js:1.3
--- loncom/auth/londes.js:1.2	Thu Nov 29 14:12:44 2001
+++ loncom/auth/londes.js	Sat Mar 23 05:34:48 2002
@@ -3,7 +3,7 @@
 // Encryption Routines according to Data Encryption Standard DES
 // Federal Information Processing Standards Publication 46-2 (1993 Dec 30)
 //
-// $Id: londes.js,v 1.2 2001/11/29 19:12:44 www Exp $
+// $Id: londes.js,v 1.3 2002/03/23 10:34:48 www Exp $
 //
 // Copyright Michigan State University Board of Trustees
 //
@@ -28,7 +28,7 @@
 // http://www.lon-capa.org/
 //
 // JavaScript Implementation by Gerd Kortemeyer
-// 1997,06/27/00,06/28 Gerd Kortemeyer
+// 1997,06/27/00,06/28,03/23/02 Gerd Kortemeyer
 
 // Global variables
 
@@ -68,6 +68,19 @@
 // Text variable
 var text="";
 
+
+// Function to AND with bit i
+
+function andbit(value,i) {
+   return value&bit[i];
+}
+
+// Function to OR with bit i
+
+function orbit(value,i) {
+   return value|bit[i];
+}
+
 // Initialize table arrays and perform self test
 
 function init() {
@@ -138,7 +151,7 @@
      var hchr="0123456789abcdef";
      for (var k=28; k>=0; k=k-4) {
          j=0;
-         for (var m=0; m<=3; m++) { if ((i&bit[k+m])!=0) { j=j|bit[m]; } }
+         for (var m=0; m<=3; m++) { if (andbit(i,k+m)!=0) { j=orbit(j,m); } }
          hstr+=hchr.substring(j,j+1);
      }   
      return(hstr);
@@ -147,7 +160,7 @@
 // Shift a 28-bit register one time
 
 function shift(sreg) {
-     var bit27=(sreg&bit[0])<<27;
+     var bit27=andbit(sreg,0)<<27;
      return (sreg>>1)|bit27;
 }
         
@@ -174,15 +187,15 @@
      for (var i=0; i<=27;i++) {
           bt=parseInt(celements.substring(i*2,i*2+2));
           if (bt<=32) {
-              if ((uextkey & bit[31-(bt-1)]) != 0) { c=c|bit[i]; }
+              if (andbit(uextkey,31-(bt-1)) != 0) { c=orbit(c,i); }
           } else {
-              if ((lextkey & bit[31-(bt-33)]) != 0) { c=c|bit[i]; }
+              if (andbit(lextkey,31-(bt-33)) != 0) { c=orbit(c,i); }
           }
           bt=parseInt(delements.substring(i*2,i*2+2));
           if (bt<=32) {
-              if ((uextkey & bit[31-(bt-1)]) != 0) { d=d|bit[i]; }
+              if (andbit(uextkey,31-(bt-1)) != 0) { d=orbit(d,i); }
           } else {
-              if ((lextkey & bit[31-(bt-33)]) != 0) { d=d|bit[i]; }
+              if (andbit(lextkey,31-(bt-33)) != 0) { d=orbit(d,i); }
           }
       }
 // Initialize the k vectors
@@ -198,8 +211,8 @@
           uk[i]=0;
           lk[i]=0;
           for (j=0; j<=23;j++) {            
-            if ((d&bit[ukarr[j]-29])!=0) { lk[i]=lk[i]|bit[23-j]; }
-            if ((c&bit[lkarr[j]-1])!=0) { uk[i]=uk[i]|bit[23-j]; }
+            if (andbit(d,ukarr[j]-29)!=0) { lk[i]=orbit(lk[i],23-j); }
+            if (andbit(c,lkarr[j]-1)!=0)  { uk[i]=orbit(uk[i],23-j); }
           }
       }
 }
@@ -213,14 +226,14 @@
      for (var i=0; i<=31;i++) {
           bt=riparr[i];
           if (bt<=32) {
-              if ((lblock & bit[bt-1]) != 0) { rv=rv|bit[i]; }
+              if (andbit(lblock,bt-1) != 0) { rv=orbit(rv,i); }
           } else {
-              if ((ublock & bit[bt-33]) != 0) { rv=rv|bit[i]; }
+              if (andbit(ublock,bt-33) != 0) { rv=orbit(rv,i); }
           }
           if (bt<=33) {
-              if ((lblock & bit[bt-2]) != 0) { lv=lv|bit[i]; }
+              if (andbit(lblock,bt-2) != 0) { lv=orbit(lv,i); }
           } else {
-              if ((ublock & bit[bt-34]) != 0) { lv=lv|bit[i]; }
+              if (andbit(ublock,bt-34) != 0) { lv=orbit(lv,i); }
           }     
      }
 }
@@ -233,11 +246,11 @@
      lblock=0;
      for (var i=0; i<=15;i++) {
           bt=liiparr[i];
-          if ((rv & bit[bt-1]) != 0) { lblock=lblock|bit[i*2]; }
-          if ((lv & bit[bt-1]) != 0) { lblock=lblock|bit[i*2+1]; }
+          if (andbit(rv,bt-1) != 0) { lblock=orbit(lblock,i*2); }
+          if (andbit(lv,bt-1) != 0) { lblock=orbit(lblock,i*2+1); }
           bt=uiiparr[i];
-          if ((rv & bit[bt-1]) != 0) { ublock=ublock|bit[i*2]; }
-          if ((lv & bit[bt-1]) != 0) { ublock=ublock|bit[i*2+1]; }
+          if (andbit(rv,bt-1) != 0) { ublock=orbit(ublock,i*2); }
+          if (andbit(lv,bt-1) != 0) { ublock=orbit(ublock,i*2+1); }
      }
 }
 
@@ -249,11 +262,11 @@
     lexpand=0;
     for (var i=0; i<=23; i++) {
        bt=etarr[i];
-       if (rv & bit[bt-1]) { lexpand=lexpand|bit[i]; } 
+       if (andbit(rv,bt-1)!=0) { lexpand=orbit(lexpand,i); } 
     }
     for (i=24; i<=47; i++) {
        bt=etarr[i];
-       if (rv & bit[bt-1]) { uexpand=uexpand|bit[i-24]; }
+       if (andbit(rv,bt-1)!=0) { uexpand=orbit(uexpand,i-24); }
     }
 }
 
@@ -263,7 +276,7 @@
     var prv=rv;
     rv=0;
     for (var i=0; i<=31; i++) {
-       if ((prv&bit[31-(pparr[i]-1)])!=0) { rv=rv|bit[31-i]; }
+       if (andbit(prv,31-(pparr[i]-1))!=0) { rv=orbit(rv,31-i); }
     }
 }
 
@@ -278,11 +291,11 @@
     for (var ki=42;ki>=24;ki=ki-6) {
        rv=rv<<4;
        var i=0;
-       if ((uadd&bit[ki-24])!=0) { i=i|bit[0]; }
-       if ((uadd&bit[ki-19])!=0) { i=i|bit[1]; }
+       if (andbit(uadd,ki-24)!=0) { i=orbit(i,0); }
+       if (andbit(uadd,ki-19)!=0) { i=orbit(i,1); }
        var j=0;
        for (var kj=0; kj<=3; kj++) {
-          if ((uadd&bit[ki-23+kj])!=0) { j=j|bit[kj]; }
+          if (andbit(uadd,ki-23+kj)!=0) { j=orbit(j,kj); }
        }
        rv=rv|sbarr[ks*64+i*16+j];
        ks++;
@@ -290,11 +303,11 @@
     for (var ki=18;ki>=0;ki=ki-6) {
        rv=rv<<4;
        var i=0;
-       if ((ladd&bit[ki]  )!=0) { i=i|bit[0]; }
-       if ((ladd&bit[ki+5])!=0) { i=i|bit[1]; }
+       if (andbit(ladd,ki)  !=0) { i=orbit(i,0); }
+       if (andbit(ladd,ki+5)!=0) { i=orbit(i,1); }
        var j=0;
        for (var kj=0; kj<=3; kj++) {
-          if ((ladd&bit[ki+1+kj])!=0) { j=j|bit[kj]; }
+          if (andbit(ladd,ki+1+kj)!=0) { j=orbit(j,kj); }
        }
        rv=rv|sbarr[ks*64+i*16+j];
        ks++;