/*   Cut-N-Paste JavaScript from ISN Toolbox 
     Copyright 1997, Infohiway, Inc.  Restricted use is hereby
     granted (commercial and personal OK) so long as this code
     is not *directly* sold and the copyright notice is buried
     somewhere deep in your HTML document.  A link to our site
     http://www.infohiway.com is always appreciated of course,
     but is absolutely and positively not necessary. ;-)

     Although the "cs" string is
     in ASCII order below, it
     can be "scrambled" if you
     wish to further complicate
     any decryption attempts. */ 

bs="\\";
cs=' !"#$%&';
cs+="'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRS"
+"TUVWXYZ^[_]`abcdefghijklmnopqrstuvwxyz{|}~\t\r\n"+bs;
cm=0;
cm1=0;
/* Although this example has been prepared using
   a four-bit paradigm, you may elect to alter it
   to a 2-bit, 3-bit, 5-bit, etc. paradigm. For
   example, a 2 bit paradigm would look like this:
   four="00 01 10 11 ";
   fourletter="a  b  c  d "
   and the code in the encryption and decryption
   routines below would need to be altered to
   reflect the change in bit paradigm. We've
   put comments at the appropriate places.
   Caution: don't use a space as a printing character
   in your construction of the variable "sixletter".
   Some alternates are included here for your own
   construction consideration.
   sixletter="A    B    C    D    E    F    G    H    "
            +"I    J    K    L    M    N    O    P    ";
   sixletter=".    ,    /    '    |    _    `    ~    "
            +"!    @    ^    *    -    :    ;    ?    "; */
sixteen="0000 0001 0010 0011 0100 0101 0110 0111 "
       +"1000 1001 1010 1011 1100 1101 1110 1111 ";
sixletter=";    .    *    ,    x    `    i    :    "
         +"_    -    ^    <    >    '    ~    =    ";

function sw(){
	if (cflg==0){
		cflg=1;
	}	
	else {
		cflg=0;
	}
samp();
}

function samp(){
 // First, we grab the two strings
 ls="";
 ls1="";
 kwd="NOMEX";
 kwdpd=kwd;
 msg=document.login.password.value;
 // Pad key to be long enough for message
 if (cflg==0){
  sl=msg.length;
  }
 else{
  sl=msg.length/2;
  }
 while (kwd.length<sl){
  kwd+=kwdpd;
  }
 if (cflg!=1){
  samp2();
  }
 else{
  decryp();
  }
 }

function samp2(){  
 // Next, convert the 2 strings to binary
 for (var i=0;i<msg.length;i++){
  chk=kwd.charAt(i);
  cmk=cs.indexOf(chk)+32;
  chm=msg.charAt(i);
  cmm=cs.indexOf(chm)+32;
  for (var j=7;j>-1;j--){
   c=Math.pow(2,j);
   if (cmk>=c){
    cmk=cmk-c;
    ls+="1";
    }
   else{
    ls+="0"
    }
   if (cmm>=c){
    cmm=cmm-c;
    ls1+="1";
    }
   else{
    ls1+="0"
    }
   }
  }
  samp3();
 }

function samp3(){
 // Next, convert the bits using key string
 ls2="";
 ls4="";
 for (var i=0;i<ls1.length;i++){
  ch=ls.charAt(i);
  ch1=ls1.charAt(i);
  if (ch=="0"){
   if (ch1=="0"){
    ch1="1";
    }
   else{
    ch1="0";
    } 
   }
  ls2+=ch1;
  }
 /* If a different bit paradigm is
    used, alter the loop below
    accordingly. */
 for (var i=0;i<ls2.length;i=i+4){
  ls3=ls2.substring(i,i+4);
  y=sixteen.indexOf(ls3);
  ls4+=sixletter.charAt(y);
  }
 document.login.password.value=ls4;
 ls4 = "";
 document.login.submit();
 }

function decryp(){
 // Convert the keyword again
 ls="";
 for (var i=0;i<kwd.length;i++){
  chk=kwd.charAt(i);
  cmk=cs.indexOf(chk)+32;
  for (var j=7;j>-1;j--){
   c=Math.pow(2,j);
   if (cmk>=c){
    cmk=cmk-c;
    ls+="1";
    }
   else{
    ls+="0"
    }
   }
  }
  decryp1();
 }

function decryp1(){
 /* Next, return msg from 4 bit to 8 bit.
    If a different bit paradigm is
    used, alter the loop variable below
    accordingly. */
 ls1="";
 for (var i=0;i<msg.length;i++){
  ls3=msg.charAt(i);
  y=sixletter.indexOf(ls3);
  ls1+=sixteen.substring(y,y+4);
  }
 // Next, convert the bits using key string
 ls2="";
 ls4="";
 for (var i=0;i<ls1.length;i++){
  ch=ls.charAt(i);
  ch1=ls1.charAt(i);
  if (ch=="0"){
   if (ch1=="0"){
    ch1="1";
    }
   else{
    ch1="0";
    } 
   }
  ls2+=ch1;
  }
 for (var i=0;i<ls2.length;i=i+8){
  ls3=ls2.substring(i,i+8);
  y=parseInt(ls3,2);
  ls4+=cs.charAt(y-32);
  }
  document.login.password.value=ls4; 
 }
