// Class prototype // --------------- function vBase() { //Define functions this.login = _vBase_login; this.header = _vBase_header; this.key = _vBase_key; this.generate_key = _vBase_generate_key; this.encode = _vBase_encode; this.decode = _vBase_decode; this.sha1 = _vBase_sha1; //Define hidden variables var tempKey1 = 0; //header var tempKey2 = 0; //password var loggedOn = 0; function _vBase_login(key) { //Here you will set the new login key. (You can set this only ones) if(!loggedOn) { tempKey2 = key; loggedOn = 1; } } function _vBase_header(key) { //Here you will set the header key (key 1) for the encryption. Once this has been set, you can use encode/decode tempKey1 = key; } //This is a function so that you can set a 16 BASE to a 256 BASE key function _vBase_key(key, length) { var key_string = ""; // Genereer key in 256 bit vorm for(var i = 0, keylength = key.length; i < keylength; i = i + 2) { key_string += String.fromCharCode(eval("0x" + key.substr(i, 2))); } while (key_string.length < length) { key_string += key_string; } key_string = key_string.substr(0, length); return key_string; } function _vBase_generate_key() { var code = ""; var number = Math.round(Math.random() * 9) + 33; for (var x = 0; x < number; x++) { code += String.fromCharCode(Math.round(Math.random() * 93) + 33); } return vOS.vBase.sha1(code); } //This is a function so that you can encode the input given to our vBase64 encryption function _vBase_encode(input) { if (!input || !tempKey1 || !tempKey2) { return; } var binary = ""; var output = ""; var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*-"; var temp, text, key3 = 0, i; var key1_string = _vBase_key(tempKey1, input.length); var key2_string = _vBase_key(tempKey2, input.length); // Zet de binaire waarden van de input string achter elkaar in een rij for (var i = 0, inputlength = input.length; i < inputlength; i++) { // Zet de ASCII codes in een variabel text = input.charCodeAt(i) < 256 ? input.charCodeAt(i) : 1; key1 = key1_string.charCodeAt(i); key2 = key2_string.charCodeAt(i); // Output het temp = (((text ^ key3) ^ key2) ^ key1).toString(2); // Vul de lengte van de binaire waarde zo nodig aan if (temp.length < 8) { temp = ("00000000" + temp).substr(("00000000" + temp).length - 8, 8); } // Een key gegenereerd aan de hand van de input tekst, om herhaling van // de keys te voorkomen. key3 = text; binary += temp; } // Voeg nullen toe indien mogelijk om te zorgen dat alle tekens gecodeerd kunnen worden while (binary.length % 6 > 0) { binary += "0"; } // Hak de binaire string in stukjes van 6 bits, maak van die zes bits een decimaal // getal en gebruik daarna chars.substr() om het bijbehorende teken te outputten for (var i = 0, binarylength = binary.length; i < binarylength; i = i + 6) { temp = binary.substr(i, 6); output += chars.substr(parseInt(temp, 2), 1); } return output; } //This is a function so that you can decode the input given to our vBase64 encryption function _vBase_decode(input) { if (!input || !tempKey1 || !tempKey2) { return; } var binary = ""; var output = ""; var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*-"; var temp, key3 = 0, text, i , k; var key1_string = _vBase_key(tempKey1, Math.round(input.length * 0.75)); var key2_string = _vBase_key(tempKey2, Math.round(input.length * 0.75)); // Zoek de plek op van de tekens en zet de binaire waarde ervan in binary for (var i = 0, inputlength = input.length; i < inputlength; i++) { temp = chars.indexOf(input.charAt(i)).toString(2); if (temp.length < 6) { temp = ("00000" + temp).substr(("00000" + temp).length - 6, 6); } binary += temp; } // Haal de nullen die met het coderen mogelijk zijn toegevoegd eraf binary = binary.substr(0, binary.length - binary.length % 8); // Hak de binaire string in stukjes van 8 bits en maak er weer een ASCII // teken van for (var i = 0, binarylength = binary.length; i < binarylength; i = i + 8) { k = i / 8; // Zet de ASCII codes in een variabel text = parseInt(binary.substr(i, 8), 2); key1 = key1_string.charCodeAt(k); key2 = key2_string.charCodeAt(k); // Een key gegenereerd aan de hand van de input tekst, om herhaling van // de keys te voorkomen. key3 = k != 0 ? output.charCodeAt(k - 1) : 0; // Output het output += String.fromCharCode(((text ^ key1) ^ key2) ^ key3); } return output; } function _vBase_sha1(msg) { var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]; msg += String.fromCharCode(0x80); var l = Math.ceil(msg.length/4) + 2; var N = Math.ceil(l/16); var M = new Array(N); for (var i=0; i>> 30) * 8; M[N-1][15] = ((msg.length-1)*8) & 0xffffffff; var H0 = 0x67452301; var H1 = 0xefcdab89; var H2 = 0x98badcfe; var H3 = 0x10325476; var H4 = 0xc3d2e1f0; var W = new Array(80); var a, b, c, d, e; for (var i=0; i>>(32-n)); } Number.prototype.toHexStr = function() { var s="", v; for (var i=7; i>=0; i--) { v = (this>>>(i*4)) & 0xf; s += v.toString(16); } return s; } } add_counter(10);