Lab 4 Cripto

el coso del cosito

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Lab 4 Cripto
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  el coso del cosito
// @author       Daniel Salas
// @match        *://cripto.tiiny.site/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js#sha512-E8QSvWZ0eCLGk4km3hxSsNmGWbLtSCSUcewDQPQWZF6pEU8GlT8a5fF32wOl1i8ftdMhssTrF/OhyGWwonTcXA==
// ==/UserScript==

//Parte 1
$(document).ready(function() {
    //filtra por Parrafo
    var divElements = $("div.Parrafo");
    var key = "";
    divElements.each(function() {
      divElements.each(function() {
        var paragraph = $(this).text().trim();
        var sentences = paragraph.split(".");
        for (var i = 0; i < sentences.length; i++) {
          var sentence = sentences[i].trim();
          if (sentence !== "") {
            //extrae y agrega los primeros chars
            var firstChar = sentence.charAt(0);
            key += firstChar;
          }
        }
      });
    });

    //imprime la key
    console.log("La llave es: " + key);

     //Parte 2

    //encontrar los elementos con clase "M#"
    var hiddenMessages = jQuery('[ class ^=M]').map( function(){return $( this ).attr("id");}).get();
    console.log("Los mensajes cifrados son: " + hiddenMessages.length)

    // Parte 3
    var decrypted = '';
    var encoded_key = CryptoJS.enc.Utf8.parse(key);

    for(var j = 0; j < hiddenMessages.length; j += 1){
        decrypted = CryptoJS.TripleDES.decrypt(hiddenMessages[j].toString(), encoded_key, {
            mode: CryptoJS.mode.ECB
    });
    console.log(hiddenMessages[j], decrypted.toString(CryptoJS.enc.Utf8))

    //agregar el texto a la pag
    var decryptedText = document.createElement('p');
    decryptedText.style.color = 'red';
    decryptedText.textContent = decrypted.toString(CryptoJS.enc.Utf8);
    var messageDiv = $('div.M'+[j+1]);
    messageDiv.append(decryptedText);
    }
});