From 846b2f5000ee7aacbae2eb018cdf9737cc3de6ae Mon Sep 17 00:00:00 2001 From: Themadpunter <106832853+familycomicsstudios@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:46:27 -0500 Subject: [PATCH 1/3] Create rsa.js --- extensions/Themadpunter/rsa.js | 83 ++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 extensions/Themadpunter/rsa.js diff --git a/extensions/Themadpunter/rsa.js b/extensions/Themadpunter/rsa.js new file mode 100644 index 0000000000..0cd8a2dad0 --- /dev/null +++ b/extensions/Themadpunter/rsa.js @@ -0,0 +1,83 @@ +(function(Scratch) { + 'use strict'; + + // Load the JSEncrypt library from a CDN + const script = document.createElement('script'); + script.src = 'https://cdn.jsdelivr.net/npm/jsencrypt/bin/jsencrypt.min.js'; + document.head.appendChild(script); + + class RSAExtension { + getInfo() { + return { + id: 'themadpunter_rsa', + name: 'TurboRSA', + color1: '#FF0000', // Primary color (red) + color2: '#CC0000', // Secondary color (darker red) + blocks: [ + { + opcode: 'generateKeys', + blockType: Scratch.BlockType.REPORTER, + text: 'Generate RSA keys', + arguments: {} + }, + { + opcode: 'encrypt', + blockType: Scratch.BlockType.REPORTER, + text: 'Encrypt [TEXT] with public key [KEY]', + arguments: { + TEXT: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'Hello, world!' + }, + KEY: { + type: Scratch.ArgumentType.STRING, + defaultValue: '' + } + } + }, + { + opcode: 'decrypt', + blockType: Scratch.BlockType.REPORTER, + text: 'Decrypt [TEXT] with private key [KEY]', + arguments: { + TEXT: { + type: Scratch.ArgumentType.STRING, + defaultValue: '' + }, + KEY: { + type: Scratch.ArgumentType.STRING, + defaultValue: '' + } + } + } + ] + }; + } + + generateKeys() { + const crypt = new JSEncrypt({ default_key_size: 1024 }); + const publicKey = crypt.getPublicKeyB64(); + const privateKey = crypt.getPrivateKeyB64(); + return JSON.stringify({ publicKey, privateKey }); + } + + encrypt(args) { + const crypt = new JSEncrypt(); + crypt.setPublicKey(args.KEY); + const encrypted = crypt.encrypt(args.TEXT); + return encrypted ? encrypted : 'Encryption failed'; + } + + decrypt(args) { + const crypt = new JSEncrypt(); + crypt.setPrivateKey(args.KEY); + const decrypted = crypt.decrypt(args.TEXT); + return decrypted ? decrypted : 'Decryption failed'; + } + } + + // Wait for the script to load before registering the extension + script.onload = () => { + Scratch.extensions.register(new RSAExtension()); + }; +})(Scratch); From 7f251d597c5458e69286cbd712e4ec0efe870b0c Mon Sep 17 00:00:00 2001 From: Themadpunter <106832853+familycomicsstudios@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:48:09 -0500 Subject: [PATCH 2/3] Update rsa.js --- extensions/Themadpunter/rsa.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/Themadpunter/rsa.js b/extensions/Themadpunter/rsa.js index 0cd8a2dad0..d780056f9f 100644 --- a/extensions/Themadpunter/rsa.js +++ b/extensions/Themadpunter/rsa.js @@ -1,3 +1,8 @@ +// Name: RSA +// ID: themadpunter-rsa +// Description: Encrypt text and files using RSA, the world's best asymmetric encryption algorithm. +// License: MIT + (function(Scratch) { 'use strict'; From dd0eb0f592f1efb1b91657d269e890854f435b99 Mon Sep 17 00:00:00 2001 From: Themadpunter <106832853+familycomicsstudios@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:49:49 -0500 Subject: [PATCH 3/3] Update rsa.js --- extensions/Themadpunter/rsa.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/Themadpunter/rsa.js b/extensions/Themadpunter/rsa.js index d780056f9f..4bc1aed94e 100644 --- a/extensions/Themadpunter/rsa.js +++ b/extensions/Themadpunter/rsa.js @@ -1,6 +1,7 @@ // Name: RSA // ID: themadpunter-rsa -// Description: Encrypt text and files using RSA, the world's best asymmetric encryption algorithm. +// Description: Encrypt text and files using RSA, the world's best asymmetric encryption algorithm. +// By: Themadpunter // License: MIT (function(Scratch) {