Table of Contents

About

This is an implementation of the symmetric substitution ATBASH cypher in LSL.

Code

ATBASH.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 wasATBASH(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, 
            25 - llListFindList(
                a, 
                (list)llToLower(p)
            )
        );
        if(wasIsUpper(p)) q = llToUpper(q);
        input = llInsertString(input, i, q);
@continue;
    } while(--i > -1);
 
    return input;
}

Example

For example, calling:

llSay(0, wasATBASH("Tllw wzb!"));

will print out Good day!.