raismth.ns(function() { with (raismth.LIB) {
myDump("[RAISMTH] ttauth module initialization\n");

theApp.auth =
{
        encode1 : function (tokenstring){
                let ch = "";
                let encoded = "";
                let rnd = this.rand(1, 9);
                for(let i = 0; i < tokenstring.length; i++){
                        ch = tokenstring.substr(i, 1);
                        encoded += this.chr(this.ord(ch)^rnd);
                }
                encoded += ";" + rnd;
                return encoded;
        },

        encode2 : function (tokenstring, chiave){
                let encoded = "";
                let i = tokenstring.length - 1;
                let j = 0;
                while (i >= 0){
                        let ch1 = tokenstring.substr(i, 1);
                        if(j > chiave.length){
                                j = 0;
                        }
                        let ch2 = chiave.substr(j, 1);
                        let enc = this.chr(this.ord(ch1)^this.ord(ch2));
                        encoded = enc + encoded;
                        i--;
                        j++;
                }
                return encoded;
        },

        encode3 : function (tokenstring){
                let encoded = "";
                encoded = raismth.base64.encode(raismth.base64._utf8_decode(raismth.base64._utf8_encode(tokenstring)));
                return encoded;
        },

        rand : function (min, max) {
                let argc = arguments.length;
                if (argc === 0) {
                        min = 0;
                        max = 2147483647;
                } else if (argc === 1) {
                        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
                }
                return Math.floor(Math.random() * (max - min + 1)) + min;
        },

        chr : function (codePt) {
                if (codePt > 0xFFFF) {
                        codePt -= 0x10000;
                        return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
                } else {
                        return String.fromCharCode(codePt);

                }
        },

        ord : function (string) {
                let str = string + '';
                let code = str.charCodeAt(0);
                if (0xD800 <= code && code <= 0xDBFF) {
                        let hi = code;
                        if (str.length === 1) {
                                return code;
                        }
                        let low = str.charCodeAt(1);
                        if (!low) {
                                return code;
                        }
                        low = str.charCodeAt(1);
                        if (!low) {
                        }
                        return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
                }
                if (0xDC00 <= code && code <= 0xDFFF) {
                        return code;
                }
                return code;
        }

}

}});
