function challenge_response(fm) {
  var challenge = fm.login_token.value;
  fm.response.value = obscure_string(fm.password.value, challenge);
  fm.password.value = "";
  return true;
}
function challenge_response3(fm) {
  var challenge = fm.login_token.value;
  if (fm.old_password) {
    fm.old_password_response.value = obscure_string(fm.old_password.value, challenge);
    fm.old_password.value = "";
  }
  fm.password_response.value = obscure_string(fm.password.value, challenge);
  fm.password.value = "";
  fm.password_confirm_response.value = obscure_string(fm.password_confirm.value, challenge);
  fm.password_confirm.value = "";
  return true;
}
function obscure_string(pwd, challenge) {
  var obscured = "";
  var i;
  for (i=0; i < pwd.length; i++) 
  {
    var c = pwd.charCodeAt(i);
    var j = ((i*2) % challenge.length);
    var k1 = challenge.charCodeAt(j);
    j = (j+1) % challenge.length;
    var k2 = challenge.charCodeAt(j);
    var c1 = (c >>> 8) & 0xff;
    var c2 = (c & 0xff);
    var x = ((c1 ^ k1) << 8) | (c2 ^ k2);
    var x16 = x.toString(16);
    while (x16.length < 4) {
      x16 = "0" + x16;
    }
    obscured += x16;
  }
  return obscured;
}

