Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Beta  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
SWVersionTest = 
  (((navigator.appName == "Netscape") && 
  (parseInt(navigator.appVersion) >= 3 )) || 
  ((navigator.appName == "Microsoft Internet Explorer") && 
  (parseInt(navigator.appVersion) >= 4 ))); 


function MakeAlpha(IndexParam) { // rotate the alphabet
  alpha = Cipher.charAt(IndexParam);
  idxx   = Cipher.indexOf(alpha);
  Cipher = Cipher.substring(idxx, 26) + Cipher.substring(0, idxx);
  }
function onGo(Mode) {
  Text = document.forms[0].elements[0].value; // get data from screen
  KeyL = document.forms[0].elements[1].value;
  KeyL = KeyL.toUpperCase();
  Hold = Alpha.indexOf(KeyL); // convert key letter into a number
if (Hold == -1) // if it is not a letter ask user to use a letter
{
   alert("Enter a letter A to Z for the key");
}
  Text = Text.toUpperCase(); // convert input string to upper case
  Size = Text.length; // find out how long input string is
  CipherText = "";
  Cipher = Beta;
  idx = 0;  
  CipherAlpha = "";
  if (Mode == 3) // if Mode is 3 user wants to decrypt otherwise encrypt
  {
  Index = Hold;
  for(count = 0; count < Size; count++) { // go thru the input string one letter at a time
    alpha = Text.charAt(count);  // get letter to decrypt from input string
    idx   = Alpha.indexOf(alpha); // find out what letter of alphabet it is
    if (idx == -1)  // if it is not a letter don't encrypt or decrypt it
    {
      CipherAlpha = alpha; // just put non letter in results
    }
    else
    {
    idx = idx - Index; // compute position in cypher alphabet
    if (idx < 0)
    {
      idx = idx +26;
    }
    CipherAlpha = Cipher.charAt(idx); // get cypher letter from rotated alphabet
    Index =  Index + Alpha.indexOf(alpha); // find amount to rotate alphabet next for next character 
    Index = Index%26;
    }
    CipherText = CipherText + CipherAlpha; // add letter or non letter to results string
            }    
  }
  else // encrypt
{
  Index = Hold;
  for(count = 0; count < Size; count++) { // go thru the input string one letter at a time
    alpha = Text.charAt(count);  // get letter to encrypt from input string
    idx   = Alpha.indexOf(alpha); // find out what letter of alphabet it is
    if (idx == -1)  // if it is not a letter don't encrypt or decrypt it
    {
      CipherAlpha = alpha; // just put non letter in results
    }
    else
    {
    idx = idx + Index; // compute position in cypher alphabet
    idx = idx%26;
    CipherAlpha = Cipher.charAt(idx); // get cypher letter from rotated alphabet
    Index =  Index + Alpha.indexOf(CipherAlpha); // find amount to rotate alphabet next for next character 
    }
    CipherText = CipherText + CipherAlpha; // add letter or non letter to results string
            }
}    
  document.forms[0].elements[0].value = Text; // put everything back on the screen
  document.forms[0].elements[1].value = KeyL;
  document.forms[0].elements[5].value = CipherText;
  }