Lab 4 Cripto

el coso del cosito

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==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);
    }
});