Blockland Forums > Modification Help
Password Protected Web Connections
<< < (2/2)
Kalphiter:
\r\n not \n
Destiny/Zack0Wack0:
Base64 code courtesy of Truce:

--- Code: ---function convertBase(%val,%atype,%btype)
{
%vlen = strLen(%val);
%alen = strLen(%atype);
%blen = strLen(%btype);

for(%i = 0; %i < %vlen; %i++)
%sum += striPos(%atype,getSubStr(%val,%i,1)) * mPow(%alen,%vlen - %i - 1);

while(1)
{
%rem = %sum % %blen;
%new = getSubStr(%btype,%rem,1) @ %new;
%sum = mFloor(%sum / %blen);

if(!%sum)
break;
}

return %new;
}
function base64Encode(%str)
{
%base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
%asciimap  = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN" @
            "OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

%len = strLen(%str);

for(%i = 0; %i < %len; %i++)
{
%chr   = getSubStr(%str,%i,1);
%ascii = strPos(%asciimap,%chr) + 32;
%bin   = convertBase(%ascii,"0123456789","01");

while(strLen(%bin) < 8)
%bin = "0" @ %bin;

%all = %all @ %bin;
}

%len = strLen(%all);

for(%i = 0; %i < %len; %i += 6)
{
%pack = getSubStr(%all,%i,6);

while(strLen(%pack) < 6)
%pack = %pack @ "0";

%dec = convertBase(%pack,"01","0123456789");
%new = %new @ getSubStr(%base64map,%dec,1);
}

while(strLen(%new) % 4 > 0)
%new = %new @ "=";

return %new;
}
function base64Decode(%str)
{
%base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
%asciimap  = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN" @
            "OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

while(getSubStr(%str,strLen(%str) - 1,1) $= "=")
%str = getSubStr(%str,0,strLen(%str) - 1);

%len = strLen(%str);

for(%i = 0; %i < %len; %i++)
{
%chr = getSubStr(%str,%i,1);
%pos = strPos(%base64map,%chr);
%bin = convertBase(%pos,"0123456789","01");

while(strLen(%bin) < 6)
%bin = "0" @ %bin;

%all = %all @ %bin;
}

while(strLen(%all) % 8 > 0)
%all = getSubStr(%all,0,strLen(%all) - 1);

%len = strLen(%all);

for(%i = 0; %i < %len; %i += 8)
{
%bin = getSubStr(%all,%i,8);
%dec = convertBase(%bin,"01","0123456789") - 32;
%chr = getSubStr(%asciiMap,%dec,1);

%new = %new @ %chr;
}

return %new;
}

--- End code ---
Example TCP code:

--- Code: ---new TCPObject(test);

$domain = "psp-networks.com";
$user = "some_username";
$pass = "some_password";
$headers = "GET /testing HTTP/1.1\r\n" @
                     "Host: " @ $domain @ "\r\n" @
                     "Authorization: Basic " @ base64Encode($user @ ":" @ $pass) @ "\r\n\r\n";

test.connect(%domain @ ":80");

function test::onConnected(%this) {
test.send($headers);
}
function test::onLine(%this, %line) {
echo(%line);
}

--- End code ---
(not tested, should work fine though)
Port:

--- Quote from: Destiny/Zack0Wack0 on April 12, 2012, 12:52:38 AM ---
--- Code: ---new TCPObject(test);

$domain = "psp-networks.com";                                  // Global variables.
$user = "some_username";
$pass = "some_password";
$headers = "GET /testing HTTP/1.1\r\n" @
                     "Host: " @ %domain @ "\r\n" @             // Local variables?
                     "Authorization: Basic " @ base64Encode(%user @ ":" @ %pass) @ "\r\n\r\n";

test.connect(%domain @ ":80");

function test::onConnected(%this) {
test.send($headers);
}
function test::onLine(%this, %line) {
echo(%line);
}

--- End code ---

--- End quote ---

Uh, what?
Fluff-is-back:
http://forum.blockland.us/index.php?topic=134895.0
Destiny/Zack0Wack0:

--- Quote from: Port on April 12, 2012, 02:14:43 AM ---Uh, what?

--- End quote ---
fixed
Navigation
Message Index
Previous page

Go to full version