MNEncrypt Library

AnthonyFuller

Active member
Aug 26, 2023
21
2
21
Hello all!

This is the first of the libraries/programs I will be releasing. This library can encrypt and decrypt strings (with a given key) from the MNEncrypt site (think hashed DHCP entries).

I ask you to please keep the credit in the constructor :).

Installation of the Library​

1. Copy the MNEncrypt code.
2. Put it on your Maxnet account.
3. Compile it mnscript compile MNEncrypt.msc MNEncrypt.
4. Use it in a program.

Usage​

1. Include MNEncrypt.mscx.
2. Initalise the library: MNEncrypt MNEncrypt = new MNEncrypt();
3. Use the Encrypt and Decrypt functions (see below).

Functions​

Functions are exposed through the MNEncrypt class. They all return StringResults.
MNEncrypt.Encrypt(string plaintext, string key);
MNEncrypt.Decrypt(string ciphertext, string key);

Example Usage​

C#:
using Console;
include "MNEncrypt.mscx";
MNEncrypt MNEncrypt = new MNEncrypt();

StringResult encrypted = MNEncrypt.Encrypt("Test", "Key");
StringResult decrypted = MNEncrypt.Decrypt("HwAKPw==", "Key");

// You should handle the results here.

Console.WriteLine(encrypted.GetString()); // Outputs "HwAKPw=="
Console.WriteLine(decrypted.GetString()); // Outputs "Test"

There is also another program attached called MNEncryptCLI, this shows how to use it in a full program.

Installation of MNEncryptCLI​

0. Ensure MNEncrypt.mscx is next to the .msc file.
1. Copy the the MNEncryptCLI code.
2. Put it on your Maxnet account.
3. Compile it mnscript compile MNEncryptCLI.msc MNEncryptCLI.
4. Run the program mnscript exec MNEncryptCLI.mscx.
5. Use it (see below).

Usage​

The commands require quotes around the arguments. They will output the result into the console.

mne "Test" "Key" - Encrypts Test with the key Key.
mnd "HwAKPw==" "Key" - Decrypts HwAKPw== with the key Key.

Testimonials​

you've just opened a new chapter in hacking relations
- Hydro

C#:
using Console;
using Encoding;
using String;
using System;
using Util;
using Bit;
class MNEncrypt {
    constructor() {
        // Please keep these credits in :)
        Console.WriteLine("MNEncrypt for MNScript, made by MNAnthony MNFuller.");
    }
    
    function<StringResult> Encrypt(string plaintext, string key) {
        // Ensure none of the parameters are null.
        if (Util.IsNull(plaintext)) { return new StringResult(false, "Plaintext is null!"); }
        if (Util.IsNull(key)) { return new StringResult(false, "Key is null!"); }
        
        // Convert the plaintext and key to their ASCII representations.
        number[] convertedText = String.Bytes(plaintext, 1, String.Length(plaintext));
        number[] convertedKey = String.Bytes(key, 1, String.Length(key));
        
        // Holds the output ASCII values.
        number[] ciphertext = new number[String.Length(plaintext)];
        
        // Now to actually convert plaintext into ciphertext.
        number p = 1; // [P]laintext index
        number k = 1; // [K]ey index
        number pLen = String.Length(plaintext); // [P]laintext [len]gth.
        number kLen = String.Length(key); // [K]ey [len]gth.
        while (p <= pLen) {
            // If we've gone over the key length, return to the start.
            if (k > kLen) { k = 1; }
            
            ciphertext[p] = Bit.Xor(convertedText[p], convertedKey[k]);
            
            p = p + 1;
            k = k + 1;
        }
        
        StringResult encoded = Encoding.Base64Encode(String.Chars(ciphertext);
        
        if (encoded.GetResult() == false) { return encoded; }
        
        return new StringResult(true, encoded.GetString());
    }
    
    function<StringResult> Decrypt(string ciphertext, string key) {
        // Ensure none of the parameters are null.
        if (Util.IsNull(ciphertext)) { return new StringResult(false, "Ciphertext is null!"); }
        if (Util.IsNull(key)) { return new StringResult(false, "Key is null!"); }
        
        // Decode the ciphertext
        StringResult decodedText = Encoding.Base64Decode(ciphertext);
        if (decodedText.GetResult() == false) { return decodedText; } else { ciphertext = decodedText.GetString(); }
        
        // Convert the plaintext and key to their ASCII representations.
        number[] convertedText = String.Bytes(ciphertext, 1, String.Length(ciphertext));
        number[] convertedKey = String.Bytes(key, 1, String.Length(key));
        
        // Holds the output ASCII values.
        number[] plaintext = new number[String.Length(ciphertext)];
        
        // Now to actually convert the ciphertext into plaintext.
        number c = 1; // [C]iphertext index
        number k = 1; // [K]ey index
        number cLen = String.Length(ciphertext); // [C]iphertext [len]gth.
        number kLen = String.Length(key); // [K]ey [len]gth.
        while (c <= cLen) {
            // If we've gone over the key length, reset it.
            if (k > kLen) { k = 1; }
            
            plaintext[c] = Bit.Xor(convertedText[c], convertedKey[k]);
            
            c = c + 1;
            k = k + 1;
        }
        
        return new StringResult(true, String.Chars(plaintext));
    }
}

C#:
using Event;
using String;
using Array;
using Console;
using Math;
// Include the library and initalise it.
include "MNEncrypt.mscx";
MNEncrypt MNEncrypt = new MNEncrypt(); // I'm really surprised this doesn't confuse the fuck out of the compiler.
// Quick and dirty StringArrResult.
class StringArrResult {
    bool _valid;
    string[] _res;
    
    // If it is invalid (false), the Array will contain one thing (error string).
    constructor(bool valid, string[] res) {
        _valid = valid;
        _res = res;
    }
    
    function<bool> GetResult() { return _valid; }
    
    function<string[]> GetStringArr() { return _res; }
    
    function<string> GetError() { return _res[1]; }
}
// Get everything between quotes.
function<StringArrResult> getQuoted(string input) {
    string[] arr = String.Split(input, "\"");
    number len = Array.Length(arr);
    
    if (len % 2 != 1) { return new StringArrResult(false, ["Invalid quotes."]); }
    
    string[] out = new string[Math.Floor(len / 2)];
    
    number i = 2;
    while (i <= len) {
        out[i / 2] = arr[i];
        i = i + 2;
    }
    
    return new StringArrResult(true, out);
}
function ConsoleCommand(string message) {
    // Lets not waste CPU time or memory.
    if (String.StartsWith(message, "mne ") == false && String.StartsWith(message, "mnd ") == false) { return; }
    string command = String.Sub(message, 1, 4);
    message = String.Sub(message, 5, String.Length(message));
    
    StringArrResult quotesRes = getQuoted(message);
    
    if (quotesRes.GetResult() == false) {
        Console.WriteLine(quotesRes.GetError());
        return;
    }
    
    // 1 should be the text, 2 should be the key
    string[] quotes = quotesRes.GetStringArr();
    if (Array.Length(quotes) != 2) {
        Console.WriteLine("Invalid number of arguments.");
        return;
    }
    
    if (command == "mne ") {
        StringResult encrypted = MNEncrypt.Encrypt(quotes[1], quotes[2]);
        
        if (encrypted.GetResult() == false) {
            Console.WriteLine("MNEncrypt Error - \n\t" .. encrypted.GetString());
            return;
        }
        
        Console.WriteLine("Encrypted text: " .. encrypted.GetString());
    }
    if (command == "mnd ") {
        StringResult decrypted = MNEncrypt.Decrypt(quotes[1], quotes[2]);
        
        if (decrypted.GetResult() == false) {
            Console.WriteLine("MNEncrypt Error - \n\t" .. decrypted.GetString());
            return;
        }
        
        Console.WriteLine("Decrypted text: " .. decrypted.GetString());
    }
}
Event.AddListener("ConsoleCommand", "MNEncryptCLICommands", "ConsoleCommand");
while (true) {
    Event.Process();
}

If you have any questions or issues, let me know!