RSA Encryption Library v1.4 - Asymmetric Encryption Made Easy

ภเﻮђt๓คгє

Well-known Member
Dec 14, 2021
2
3
31
RSA Encryption Library

The RSA Encryption Library (REL) is a library that provides developers with a simple encryption method or as a robust way to make digital signatures.

Installing REL
  1. Copy REL from the spoiler below.
  2. Create a .mscx file (name and location is irrelevant).
  3. Open the file.
  4. Paste REL into the file and save.
24
{"compiler_version":1.0}
XQAAAQCHeQAAAAAAAAA9iIpHPJkiDSD3c5r2+YVSwSkYr3xI1qu/iwhH9I9KX6Vn
wSXx3y7oTPb24G/qoKHbj1VkzRMu3MnpRIb0du9DVF1PAxH2Vwv4He4+4vZZ6ki+
AgdLZ3D7SVll6tet4Zy+MbTnWXyi7dooN7uU5WlJ7e3ce7MR8kKswbY27+HKzcjY
+9yyfpj1Bnjz72/xQyBMU1soCgbDTEwAITk5k5DFv566h1GOhH2vAvVYtJlryo+Y
I9z3jygpryw7KN3qNUfKi3betoMcQEuiTbDz4jxlgMY74BJHs/4WeXPsO5J+FR2Q
yH5izOKR0yKqXiuGOgmN1eSpKjJclVN0XZYokVNv7/c0nZpGi4jwMmREVsiGL2PX
QapxbobJfJ6/IyKB7otzXYworFeEn3nsqEY+Eg/IjlQL0WlmZstsza5eDyFAzd2F
dQjGucrKR6Wd9KtGiKr+GTpUq6i2kqfloB5Y8QsYGwYjMXl4fE+lpGZpBmliDbYW
TDLKx7DQunk0CYq7USTYE6a2UT672ysJlLgq7uufUB2bziCX+8yjvwIyDI/mZf+T
c1mA4io9aRgGkG7ePVPta+VicOdyAIIP7q+2hbvgbIrkkXHXuPu7Wxo5cRKMcdN8
GvRs9FBwPcq50oWv7OpokKNuxf4sHgnnoAeKgugBe9PDUpvxgqDNPY3Bn9AEbJdo
b4go/2wJwtbsHpcDrCMheGFL5OhnEqo0HGN3ouzIwcyjMRYFR2Fbv4va7l/EUP0L
ph1mPiCOXjvvM7UJpG6S5k33LkGB7Oqne9roA3RDKU3gaw6DFhwZ5vYMnq2DyU4D
Rcyr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ZNzb1nHES7s5O76eX+iXPngesSrPV1EtGL2MJtYpLOqOKpS
UH2m3FocNEydAgMjBeOn5hpMki4VWc6oI5clYQmv8i90iHFT5yruP9DvioQLujls
76r/gwf1vFnuKX2iRia+v5sl0+KKIzsX4W9SjmIHqHc3vZ4kRpWI6sCcxyrK1YxM
D5LeIDNIld33EmnHk1lXNKPuM4MBScKPGoXvbNHW8MGuuyojzv8RLwYvFFGVtIOc
Jy3juklGQSMhuQR0Ws+5vmlcsXHzxUtSgQ9VIOsue2Ki5/ortTQPEOIEqWRw7yD+
ALF25yYMAMPevTQ9FkMi/1UNSGmczg2pXXb6wIT48eTEeAXxM4OebNFYXaZVA/qM
CyX2ueXN16J8jVL+AFrxHAh1x0hE32rzZBIxlZmF7Nqh+L44vaJw22J6dDo+eYB7
iAv1MgOSXUltdjhzXR/XUvOULPvNZVJtROm9UEsfOWBSfB7CqLJ1fU7eX8b21BUG
m7pUq/qtflZaOL0vW6RjSBbz65D7325co8TVsO/1PRJDQ3h8pboiYBUKRoGojWob
NJIawSdBHQTm6two4n6aRfKRDcyzlSeveSHdaaHNEgOrM1/Lx/c8WRSfk3zuTnh6
V0jYSfhbeBvAk9Zxu3rt4WWtW5pxHBL5gwNLCKCmNpohIPIEGb81hf7wVxcbz4bT
NmVizeVVep0uuJ+1LMgSgAhWWdT+Eu+/F6Hu1vhDM6dKaF4KahSpbQ313+RkbeU7
O6eoa7l0RQ2x7Spc7n6gBpbLQ4IgGVCM7y27auGmSUaNOz+vRvTIJ48PS6u+vLEy
UcPzjMO97zSImuA=

Usage

To use REL, you need to follow 2 simple steps:
  1. Make sure to "include REL.mscx".
  2. Add "RSALib RSA = new RSALib()" in your code.

Table of Functions

.mod(number, number)Performs modulo of two numbers.
.PowerMod(number, number, number)Gives (a^b modulo c).
.Factorize(number)Find a factor of a given number.
.GCD(number, number)Finds the greatest common denominator of two numbers.
.IsPrime(number)Returns bool.
.factor(number)Returns array of found factors for given number.
.KeyGen(number, number)Generates an RSA key based on input range, low and high.
.old_encrypt/old_decrypt(number, number, number)Method to encrypt/decrypt single number. Requires, number - Private/Public Key - Exponent.
.encrypt(number[], number, number)Method to encrypt array of numbers. Requires, Array - Public Key - Exponent.
.decrypt(number[], number, number)Method to decrypt array of numbers. Requires, Array - Private Key - Exponent.

Example Program:
Code:
using System;
using Console;
using Array;
using Application;
using Util;
using String;
using File;
include "RSALib.mscx";

RSALib RSA = new RSALib();

bool run = true;

// Used for converting ASCII to numbers.
string[] asciiTable = [
        "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
        "[", "\\", "]", "^", "_", "`","-","!",
        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];

string[] options = ["1 > Gen Keys","2 > Encrypt","3 > Decrypt","4 > Exit"];
function showopt(){
    Console.WriteLine("Please Enter an Option:");
    number i = 1;
    while(i <= Array.Length(options)){
        Console.WriteLine(options[i]);
        i = i + 1;
    }
}

function genkey(number upper){
    number[] keys = RSA.KeyGen(1,upper;
    number i = 1;
    while(i<=3){
        Console.WriteLine(keys[i]);
        i = i + 1;
    }
}

Application.RequestAdminPrivilege();
while(run){
    showopt();
    string choice = Console.ReadLine();

    if(choice == "1"){
        Console.WriteLine("Enter Upper Range: ");
        number upper = Util.ToNumber(Console.ReadLine());
        genkey(upper);
    }
   
    if(choice == "2"){
        Console.WriteLine("Enter Text:");
        string text = Console.ReadLine();
        string[] textar = new string[String.Length(text)];
        number[] numar = new number[String.Length(text)];
        number i = 1;
        // Converts ASCII to numbers based on previous table
        while(i<=String.Length(text)){
            textar[i] = String.CharAt(text,i);
            numar[i] = Array.IndexOf(asciiTable,textar[i]);
            numar[i] = numar[i];
            i = i + 1;
        }
        Console.WriteLine("");
        Console.WriteLine("Enter Public Key:");
        number public = Util.ToNumber(Console.ReadLine());
       
        Console.WriteLine("");
        Console.WriteLine("Enter Exponent:");
        number exponent = Util.ToNumber(Console.ReadLine());
       
        Console.WriteLine("");
        number[] enc = RSA.encrypt(numar,public,exponent);
        i = 1;
        number y = i + 7;
        string str = "";
        while(i<=Array.Length(enc)){
            y = i -7;
            if(i==1){
                str = Util.ToString(enc[i]);
            }
            else{
                str = str..","..enc[i];
            }
            i = i + 1;
        }
        Console.WriteLine(str);
    }
   
    if(choice == "3"){
        Console.WriteLine("Enter Code:");
        string text = Console.ReadLine();
        Console.WriteLine(text);
        string[] textar = String.Split(text,",");
        number[] numar = new number[Array.Length(textar)];
        number i = 1;
        while(i<=Array.Length(textar)){
            numar[i] = Util.ToNumber(textar[i]);
            i = i + 1;
        }
       
       
        Console.WriteLine("");
        Console.WriteLine("Enter Private Key:");
        number private = Util.ToNumber(Console.ReadLine());
        Console.WriteLine(private);
       
        Console.WriteLine("");
        Console.WriteLine("Enter Exponent:");
        number exponent = Util.ToNumber(Console.ReadLine());
        Console.WriteLine(exponent);
       
        Console.WriteLine("");
        number[] dec = RSA.decrypt(numar,private,exponent);
        i = 1;
        string str = "";
        while(i<=Array.Length(dec)){
            number num = dec[i];
            Console.WriteLine(num);
            str = str..asciiTable[num];
            i = i + 1;
        }
        Console.WriteLine(str);
    }
   
    if(choice == "4"){
        Application.Exit();
    }
}


If you have any questions or bug reports then feel free to join our Discord server below, happy coding!