'use strict';
var passwordCharacters={
  charset:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!$;-?&@#%",
  lowerset:"abcdefghijklmnopqrstuvwxyz",
  upperset:"ABCDEFGHJKLMNOPQRSTUVWXYZ",
  numberset:"0123456789",
  specialcharset:"!$;-?&@#%"
}
var passwordCharactersGeneration={
  charset:"abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789!$;-?&@#%",
  lowerset:"abcdefghijkmnpqrstuvwxyz",
  upperset:"ABCDEFGHJKLMNPQRSTUVWXYZ",
  numberset:"123456789",
  specialcharset:"!$;-?&@#%"
}
function checkPassword(pwd){
  if(pwd.length<8){
    return false;
  }
  var success=true;
  var foundLowerSet=false;
  var foundUpperSet=false;
  var foundNumberSet=false;
  var foundSpecialCharSet=false;
  for(var i=0;i<pwd.length;i++){
    if(passwordCharacters.charset.indexOf(pwd[i])<0){
      success=false;
      break;
    }
    if(!foundLowerSet&&passwordCharacters.lowerset.indexOf(pwd[i])>=0){
      foundLowerSet=true;
    }
    if(!foundUpperSet&&passwordCharacters.upperset.indexOf(pwd[i])>=0){
      foundUpperSet=true;
    }
    if(!foundNumberSet&&passwordCharacters.numberset.indexOf(pwd[i])>=0){
      foundNumberSet=true;
    }
    if(!foundSpecialCharSet&&passwordCharacters.specialcharset.indexOf(pwd[i])>=0){
      foundSpecialCharSet=true;
    }
  }
  return success&&foundLowerSet&&foundUpperSet&&foundNumberSet&&foundSpecialCharSet;
}
function stringToByteArray(str) {
    var array = new (window.Uint8Array !== void 0 ? Uint8Array : Array)(str.length);
    var i;
    var il;

    for (i = 0, il = str.length; i < il; ++i) {
        array[i] = str.charCodeAt(i) & 0xff;
    }

    return array;
}
function Utf8ArrayToStr(array) {
    var out, i, len, c;
    var char2, char3;

    out = "";
    len = array.length;
    i = 0;
    while(i < len) {
    c = array[i++];
    switch(c >> 4)
    { 
      case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
        // 0xxxxxxx
        out += String.fromCharCode(c);
        break;
      case 12: case 13:
        // 110x xxxx   10xx xxxx
        char2 = array[i++];
        out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
        break;
      case 14:
        // 1110 xxxx  10xx xxxx  10xx xxxx
        char2 = array[i++];
        char3 = array[i++];
        out += String.fromCharCode(((c & 0x0F) << 12) |
                       ((char2 & 0x3F) << 6) |
                       ((char3 & 0x3F) << 0));
        break;
    }
    }

    return out;
}