SRL Archive - Other Scripts

Base64, encoding and decoding!


mastaraymond

2008-07-17 20:10:54

Ehh… I made base64 encoding\decoding in scar..

Have phun! ^^.

program Base64;
const
str = 'test'; //Fill in the string.


const
Base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

function Base64Encode(str : string) : string;
var
ProcessStr : String;
L,Pads,i : integer;
begin;
l := Length(str);
ProcessStr := str;
if L < 3 then
begin;
Pads := 3 - L;
ProcessStr := ProcessStr + StringOfChar(#0,3 - L mod 3);
L := 3;
end;
if L mod 3 <> 0 then
begin;
Pads := Pads + (3 - L mod 3);
L := L + (3 - L mod 3);
ProcessStr := ProcessStr + StringOfChar(#0,3 - L mod 3);
end;
for i := 1 to L-2 do
begin;
result := result + Base64chars[ord(ProcessStr[i]) and $fc shr 2+1];
result := result + Base64chars[ord(ProcessStr[i]) and 3 shl 4 or ord(ProcessStr[i+1]) and $f0 shr 4+1];
result := result + Base64chars[ord(ProcessStr[i+1]) and $f shl 2 or ord(ProcessStr[i+2]) shr 6+1];
result := result + Base64chars[ord(ProcessStr[i+2]) and $3f+1];
i := i + 2;
end;
l := length(result);
if Pads > 0 then
for i := l downto (l-pads+1) do
Result[i] := '=';
end;
function CharPos( Charz : char) : integer;
begin;
Result := pos(charz,Base64Chars)-1;
end;
function Base64Decode(str : string) : string;
var
L,Pads,i : integer;
begin;
l := Length(str);
if (L<4) or ( l mod 4 <> 0 ) then
Exit;
for i := l downto 1 do
if str[i] = '=' then
Inc(Pads)
else
Break;
for i := 1 to L-3 do
begin;
Result := Result + chr( CharPos(str[i]) shl 2 or charPos(str[i+1]) shr 4);
Result := Result + chr( CharPos(str[i+1]) shl 4 or charPos(str[i+2]) shr 2);
Result := Result + chr( CharPos(str[i+2]) shl 6 or CharPos(str[i+3]) );
i := I + 3;
end;
SetLength(result,Length(result)-pads);
end;
var
Base64 : string;
begin
Base64 := Base64Encode(str);
Writeln('Encoded : ' + Base64);
Writeln('Decoded : ' + Base64decode(base64));
end.

bullzeye95

2008-07-17 20:11:37

Again, sexi =]
Nice job.

mixster

2008-07-18 02:24:13

I have only one word to say:
Antidisestablishmentarianism.
That and awesome job ;)

Wizzup?

2008-07-18 03:48:07

TG9sLiBOaWNlLi4uIFNvIHdoYXQgaXMgdGhlIHB1cnBvc2Ugb2YgdGhpcyBmdW5jdGlvbj8gR0VUIEJBQ0sgVE8gV09SSw==

PhantomCode

2008-07-18 04:08:15

lol @ Wizzup?

SSBraW5kYSBhZ3JlZS4uLiB3aGF0J3MgdGhlIHBvaW50IG9mIGEgYmFzZTY0IGVuY29kZXIgd2hl
biB5b3UgY2FuIGp1c3QgdXNlIExlZXRLZXk/IDop

Wizzup?

2008-07-18 05:01:33

WW91IGNhbiBhbHNvIGp1c3QgdHlwZSB1c2luZyB5b3VyIEtleWJvYXJkLiA6KQ==

PhantomCode

2008-07-18 05:03:29

From: Wizzup?
WW91IGNhbiBhbHNvIGp1c3QgdHlwZSB1c2luZyB5b3VyIEtleWJvYXJkLiA6KQ==


SSBrbm93ISBJdCdzIHNvIG11Y2ggZWFzaWVyLCBpc24ndCBpdD8gOkQ=

mastaraymond

2008-07-18 06:14:02

SSBkb24ndCBrbm93IHdoZXJlIHlvdSB0YWxraW5nIGFib3V0IDooLiBCYXNlNjQgaXMgdWJlciBsZWV0IGFuZCBvZnRlbiB1c2VkIGluIGFuIGUtbWFpbCArIHdlYiBlbnZpcm9ubWVudC4uLiBBbmQgSSBuZWVkIGl0IGZvciBlbmNyeXB0aW9uICYgZGVjcnlwdGlvbiBwcm9jZXNzZXMgXl4u

Smartzkid

2008-08-04 18:55:31

Km5vdGUgdG8gc2VsZiogRGVjb2RlIGFsbCBpbnRlcmNlcHRlZCBjb21tdW5pY2F0aW9ucyBmcm9tIG1hc3RhcmF5bW9uZCB3aXRoIGJhc2U2NA==

Shuttleu

2008-08-04 19:03:09

bG9sIG5vdyBpIHdvbmRlciB3aHkgZXZlcnlvbmUgaXMgdGFsa2luZyBpbiBiYXNlNjQuLi4/ :rolleyes:

~shut

noidea

2008-08-04 19:52:56

Im not trying to ruin the fun or anything but what language are you fauking speaking lol. If I new the name I could look a key on googe?

noidea

Shuttleu

2008-08-04 19:57:21

From: noidea
Im not trying to ruin the fun or anything but what language are you fauking speaking lol. If I new the name I could look a key on googe?

noidea

aXRzIGJhc2U2NCBkdWgh :p
aXQgc2F5cyBpdCBpbiB0aGUgdGl0bGU=

~shut

BobboHobbo

2008-08-05 04:22:33

Muahahhaha:
KkhpbnQqIGkgZG9udCB0aGluayBhbnlvbmUgY2FuIGhlYXIgbWUgOlAgSSB0aGluayBNYXN0YVJheW1vbmQgaXMgZy1nLWctZ2F5ICpXaW5rKipXaW5rKg==

Shuttleu

2008-08-05 04:44:48

From: BobboHobbo
Muahahhaha:

dW1tIHBlb3BsZSBjYW4gaGVhciB5b3UgaGVoZS4uLiBhbmQgdW1tLi4uIHVtbS4uLiBCb2Jib0hv
YmJvIGlzIGdheQ==
:D

~shut

EDIT:
01101101 01100001 01100010 01100101 01111001 00100000 01110111 01100101 00100000 01110011 01101000 01101111 01110101 01101100 01100100 00100000 01100010 01110010 01101001 01100111 01101000 01110100 01100101 01101110 00100000 01110100 01101000 01101001 01110011 00100000 01110100 01101000 01110010 01100101 01100001 01100100 00100000 01110101 01110000 00100000 01100001 00100000 01100010 01101001 01110100 00100000 01110101 01110011 01101001 01101110 01100111 00100000 01100010 01101001 01101110 01100001 01110010 01111001 

6f 72 20 6d 61 62 65 79 20 65 76 65 6e 20 48 45 58 

--- .-.   .-- .   -.-. --- ..- .-.. -..   .--- ..- ... -   ..- ... .   -- --- .-. ... .   -.-. --- -.. . 
:D

Laur€ns

2008-08-08 07:09:40

Hello, I'm

TGF1cmVuc3NpZTA=
:rolleyes:

Now go make a MD5 decoder ;)

Shuttleu

2008-08-08 07:43:05

i changed it a bit :D

program Base64;
const
str = 'dGVzdA=='; //Fill in the string.
Encode = false; // Do you want to encode the text?

const
Base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

function Base64Encode(str : string) : string;
var
ProcessStr : String;
L,Pads,i : integer;
begin;
l := Length(str);
ProcessStr := str;
if L < 3 then
begin;
Pads := 3 - L;
ProcessStr := ProcessStr + StringOfChar(#0,3 - L mod 3);
L := 3;
end;
if L mod 3 <> 0 then
begin;
Pads := Pads + (3 - L mod 3);
L := L + (3 - L mod 3);
ProcessStr := ProcessStr + StringOfChar(#0,3 - L mod 3);
end;
for i := 1 to L-2 do
begin;
result := result + Base64chars[ord(ProcessStr[i]) and $fc shr 2+1];
result := result + Base64chars[ord(ProcessStr[i]) and 3 shl 4 or ord(ProcessStr[i+1]) and $f0 shr 4+1];
result := result + Base64chars[ord(ProcessStr[i+1]) and $f shl 2 or ord(ProcessStr[i+2]) shr 6+1];
result := result + Base64chars[ord(ProcessStr[i+2]) and $3f+1];
i := i + 2;
end;
l := length(result);
if Pads > 0 then
for i := l downto (l-pads+1) do
Result[i] := '=';
end;
function CharPos( Charz : char) : integer;
begin;
Result := pos(charz,Base64Chars)-1;
end;
function Base64Decode(str : string) : string;
var
L,Pads,i : integer;
begin;
l := Length(str);
if (L<4) or ( l mod 4 <> 0 ) then
Exit;
for i := l downto 1 do
if str[i] = '=' then
Inc(Pads)
else
Break;
for i := 1 to L-3 do
begin;
Result := Result + chr( CharPos(str[i]) shl 2 or charPos(str[i+1]) shr 4);
Result := Result + chr( CharPos(str[i+1]) shl 4 or charPos(str[i+2]) shr 2);
Result := Result + chr( CharPos(str[i+2]) shl 6 or CharPos(str[i+3]) );
i := I + 3;
end;
SetLength(result,Length(result)-pads);
end;
var
Base64 : string;
begin
if encode then
Base64 := Base64encode(str)
else
Base64 := Base64decode(str);
Writeln('Input : ' + str);
Writeln('Output : ' + Base64);
end.
now its easier to decode it

~shut

WhoCares357

2008-08-08 14:36:28

What does shl and shr stand for? Never seen anything like it :/.

mastaraymond

2008-08-09 01:35:08

There are a few tuts about SHL and SRL. Don't have time to explain :p.


@Laurens. I've got a md5 bruteforcer if that is what you want xD