<commit_before>var dictionary = {};
var map = {};
var encryptionkey = {};
var password = {};
var initVector = {};
var dictionaryNames = ["adjectives", "adverbs", "nouns", "verbs", "pronouns", "prepo"];

function processText(encrypt, force) {

    var nodeError = document.getElementById("error");
    nodeError.innerHTML = "";

    if(Object.keys(dictionary).length != dictionaryNames.length) {
        nodeError.innerHTML = "Internal error : missing dictionaries";
        return;
    }
    if(document.getElementById("textAera").value == "") {
        nodeError.innerHTML = "No message to encrypt/decrypt.";
        return;
    }
    if(document.getElementById("pwd").value == "") {
        nodeError.innerHTML = "Need a password !";
        return;
    }
    if(document.getElementById("pwd").value.length < 9) {
        nodeError.innerHTML = "Password too short, minimum 9 characters.";
        return;
    }

    var text = document.getElementById("textAera").value;
    text = text.replace(/(?:\r\n|\r|\n)/g, ' ');

    var iv = "";
    if(encrypt) iv = generateIv(text.split(" ").length);
    else {
        iv = text.split(".")[0];
        text = text.replace(iv + ".", "");
    }

    var array = text.split(" ");

    var result = true;

    /* Check if words isn't in dictionary */
    if(!force) {
        for(var i = 0; i < array.length; i++) {

            var word = removePonctuation(array[i]);
            if(!getDicoName(word)) {
                result = false;

                nodeError.innerHTML = nodeError.innerHTML + word + " ";
                /* underline word */
            }

        }
    }

    if(result) {

        document.getElementById("textAera").value = "";
        if(encrypt) document.getElementById("textAera").value += iv + " ";

        var positionWord = 0;

        for(var i = 0; i < array.length; i++) {

            if(array[i] == "") continue;

            if(isPunctuation(array[i])) {
                document.getElementById("textAera").value += array[i] + " ";
                continue;
            }

            var punctuationBegining = "";
            var punctuationEnd = "";

            if(isPunctuation(array[i].charAt(0))) punctuationBegining = array[i].charAt(0);
            if(isPunctuation(array[i].charAt(array[i].length - 1))) punctuationEnd = array[i].charAt(array[i].length - 1);

            array[i] = removePonctuation(array[i]);

            var dicoName = getDicoName(array[i].toLowerCase());
            var word = "";
            if(dicoName) {
                word = changeWord(array[i], dicoName, encrypt, iv, positionWord);
                positionWord++;
            }
            else word = array[i].toLowerCase();

            document.getElementById("textAera").value += punctuationBegining + word + punctuationEnd + " ";

        }

    }
    else {
        nodeError.innerHTML = "These words are not in the dictionary: " + nodeError.innerHTML + ".";
        nodeError.innerHTML += "<br />They will not be encrypted, do you want to proceed anyway ?"
        $(".boutongroup").hide();
        $(".boutongroupsure").show();
    }

}

function getDicoName(word) {

    for (var key in dictionary) {
        if(dictionary[key]["lookup"][word]) return key;
    } 

    return null;

}

function generateIv(size) {

    var nbWords = Math.floor((Math.random() * (0.20 * size)) + 1);

    var iv = "";
    var size = 0;

    while(size < nbWords) {
        for (var key in dictionary) {
            if (dictionary.hasOwnProperty(key)) {
                var ts = Math.round((new Date()).getTime()); 
                var p = (Math.floor((Math.random() * dictionary[key]["position"].length) + 1) * ts) %  dictionary[key]["position"].length;
<commit_msg>Case sensitive fixed<commit_after>var dictionary = {};
var map = {};
var encryptionkey = {};
var password = {};
var initVector = {};
var dictionaryNames = ["adjectives", "adverbs", "nouns", "verbs", "pronouns", "prepo"];

function processText(encrypt, force) {

    var nodeError = document.getElementById("error");
    nodeError.innerHTML = "";

    if(Object.keys(dictionary).length != dictionaryNames.length) {
        nodeError.innerHTML = "Internal error : missing dictionaries";
        return;
    }
    if(document.getElementById("textAera").value == "") {
        nodeError.innerHTML = "No message to encrypt/decrypt.";
        return;
    }
    if(document.getElementById("pwd").value == "") {
        nodeError.innerHTML = "Need a password !";
        return;
    }
    if(document.getElementById("pwd").value.length < 9) {
        nodeError.innerHTML = "Password too short, minimum 9 characters.";
        return;
    }

    var text = document.getElementById("textAera").value;
    text = text.replace(/(?:\r\n|\r|\n)/g, ' ');

    var iv = "";
    if(encrypt) iv = generateIv(text.split(" ").length);
    else {
        iv = text.split(".")[0];
        text = text.replace(iv + ".", "");
    }

    var array = text.split(" ");

    var result = true;

    /* Check if words isn't in dictionary */
    if(!force) {
        for(var i = 0; i < array.length; i++) {

            var word = removePonctuation(array[i]);
            if(!getDicoName(word)) {
                result = false;

                nodeError.innerHTML = nodeError.innerHTML + word + " ";
                /* underline word */
            }

        }
    }

    if(result) {

        document.getElementById("textAera").value = "";
        if(encrypt) document.getElementById("textAera").value += iv + " ";

        var positionWord = 0;

        for(var i = 0; i < array.length; i++) {

            if(array[i] == "") continue;

            if(isPunctuation(array[i])) {
                document.getElementById("textAera").value += array[i] + " ";
                continue;
            }

            var punctuationBegining = "";
            var punctuationEnd = "";

            if(isPunctuation(array[i].charAt(0))) punctuationBegining = array[i].charAt(0);
            if(isPunctuation(array[i].charAt(array[i].length - 1))) punctuationEnd = array[i].charAt(array[i].length - 1);

            var wordCase = getCase(array[i]);
            array[i] = removePonctuation(array[i]);

            var dicoName = getDicoName(array[i].toLowerCase());
            var word = "";
            if(dicoName) {
                word = changeWord(array[i], dicoName, encrypt, iv, positionWord);
                positionWord++;
            }
            else word = array[i].toLowerCase();

            document.getElementById("textAera").value += punctuationBegining + setCase(word, wordCase) + punctuationEnd + " ";

        }

    }
    else {
        nodeError.innerHTML = "These words are not in the dictionary: " + nodeError.innerHTML + ".";
        nodeError.innerHTML += "<br />They will not be encrypted, do you want to proceed anyway ?"
        $(".boutongroup").hide();
        $(".boutongroupsure").show();
    }

}

String.prototype.replaceAt=function(index, character) {
    return this.substr(0, index) + character + this.substr(index+character.length);
}

function getCase(word) {

    var wordCase = [];

    for(var i = 0; i < word.length; i++) {
        var character = word[i];
        if (character == character.toUpperCase()) {
            wordCase[i] = true;
        }
        else {
            wordCase[i] = false;
        }
    }

    return wordCase;
}

function setCase(word, wordCase) {

    for(var i = 0; i < word.length && i < wordCase.length; i++) {

        if(wordCase[i]) {
            word = word.replaceAt(i, word[i].toUpperCase());
        }
        else {
            word = word.replaceAt(i, word[i].toLowerCase());
        }

    }

    return word;

}

function getDicoName(word) {

    for (var key in dictionary) {
        if(dictionary[key]["lookup"][word]) return key;
    } 

    return null;

}

function generateIv(size) {

    var nbWords = Math.floor((Math.random() * (0.20 * size)) + 1);

    var iv = "";
    var size = 0;

    while(size < nbWords) {
        for (var key in dictionary) {
            if (dictionary.hasOwnProperty(key)) {
                var ts = Math.round((new Date()).getTime()); 
                var p = (Math.floor((Math.random() * dictionary[key]["position"].length) + 1) * ts) %  dictionary[key]["position"].length;

{'fraction_non_alphanumeric': 0.15732368896925858, 'fraction_numerical': 0.004219409282700422, 'mean_word_length': 2.189542483660131, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1393058', 'n_tokens_mistral': 2541, 'n_tokens_neox': 2433, 'n_words': 509}