var rands = [1234,7623,5109,31724,34786,9834,12343,23412,45,7865,2345,9087,28453,8711,532,8957]
var rnds = 1

function setKey(pswd,ro) {
  rnds = ro
  m = rands.length-1
  if (pswd.length <= rands.length ) {
    m = pswd.length-1
  }
  for(f=0;f<=m;f++) {
/*    document.write(pswd.charCodeAt(f)+" "); */
    rands[f] = ((rands[f] ^ pswd.charCodeAt(f)) + rands[rands[f] & 15]) & 65535
/*    document.write("rands["+f+"] = "+rands[f]+"\n") ;  */
  }
  for(f=0;f<rands.length;f++) {
/*    document.write("(rands[f]/16) & 15 = "+((rands[f]/16) & 15)) ;  */
    rands[f] = (rands[f] + rands[(rands[f]>>4) & 15]) & 65535 ;
/*    document.write("rands["+f+"] = "+rands[f]+"\n") ;  */
  }
}

function encode(inString) {
  if ( inString.length > 1 ) {
    for(rn=1;rn<=rnds;rn++) {
      outString = String.fromCharCode(inString.charCodeAt(0) ^ (rands[inString.charCodeAt(inString.length-1) & 15] & 255)) ;
      for(f=1;f<inString.length;f++) {
        outString = outString + String.fromCharCode(inString.charCodeAt(f) ^ (rands[outString.charCodeAt(f-1) & 15] & 255)) ;
      }
      outS = ""
      for(f=0;f<inString.length;f++) {
        outS = outS + String.fromCharCode(outString.charCodeAt(f) ^ (rands[rn & 15]>>8)) ;
      }
      inString = outS
    }
    outSbe = ""
    for(f=0;f<outS.length;f++) {
      outSbe = outSbe + String.fromCharCode((outS.charCodeAt(f)>>4)+65) + String.fromCharCode((outS.charCodeAt(f)&15)+65) ;
    }
    return outSbe
  }
}
