Table of Contents

About

This is an implementation of the symmetric substitution ROT-13 cypher in LSL.

Code

ROT13.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      //
///////////////////////////////////////////////////////////////////////////
integer wasIsUpper(string a) {
    if(a == "") return FALSE;
    integer x = llBase64ToInteger("AAAA" + 
        llStringToBase64(llGetSubString(a, 0, 0)));
    return x >= 65 && x <= 90;
}
 
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      //
///////////////////////////////////////////////////////////////////////////
integer wasIsAlpha(string a) {
    if(a == "") return FALSE;
    integer x = llBase64ToInteger("AAAA" + 
        llStringToBase64(llGetSubString(a, 0, 0)));
    return (x >= 65 && x <= 90) || (x >= 97 && x <= 122);
}
 
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3      //
///////////////////////////////////////////////////////////////////////////
string wasROT13(string input) {
    list a = 
        [ 
            "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" 
        ];
 
    integer i = llStringLength(input)-1;
    do {
        string p = llGetSubString(input, i, i);
        if(!wasIsAlpha(p)) jump continue;
        input = llDeleteSubString(input, i, i);
        string q = llList2String(
            a, 
            (
                llListFindList(
                    a, 
                    (list)llToLower(p)
                ) + 13
            ) % 26
        );
        if(wasIsUpper(p)) q = llToUpper(q);
        input = llInsertString(input, i, q);
@continue;
    } while(--i > -1);
 
    return input;
}

Example

For example, calling:

llSay(0, wasROT13("Tbbq qnl!"));

will print out Good day!.


fuss/lsl/cryptography/cyphers/rot13.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.