function entropy(password) {
    let chars = [
        "abcdefghijklmnopqrstuvwxyz",
        "ABCDFEGHIJKLMNOPQRSTUVWXYZ",
        "0123456789",
        " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~§", // OWASP special chars
        "áàâéèêíìîóòôúùûç"
    ];

    used = new Set();
    for(c in password) {
        for(k in chars) {
            if(chars[k].includes(password[c])) {
                used.add(chars[k]);
            }
        }
    }
    return Math.log(Math.pow(Array.from(used).join("").length, password.length)) / Math.log(2);
}

function update_entropy(ev) {
    let i = document.querySelector(".entropy").previousElementSibling;
    let p = document.querySelector(".entropy");
    let e = entropy(i.value);

    p.classList.remove('low');
    p.classList.remove('medium');
    p.classList.remove('high');

    if(e < 60) {
        p.classList.add('low');
    } else if(e < 100) {
        p.classList.add('medium');
    } else {
        p.classList.add('high');
    }

    p.value = e;
}

document.querySelector(".entropy").previousElementSibling.addEventListener('input', update_entropy);
document.querySelector(".entropy").style.display = "block";
