Results 1 to 18 of 18

Thread: Base64, encoding and decoding!

  1. #1
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default Base64, encoding and decoding!

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

    Have phun! ^^.
    SCAR Code:
    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.
    Verrekte Koekwous

  2. #2
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Again, sexi =]
    Nice job.

  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I have only one word to say:
    Antidisestablishmentarianism.
    That and awesome job
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  4. #4
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Code:
    TG9sLiBOaWNlLi4uIFNvIHdoYXQgaXMgdGhlIHB1cnBvc2Ugb2YgdGhpcyBmdW5jdGlvbj8gR0VUIEJBQ0sgVE8gV09SSw==



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  5. #5
    Join Date
    May 2008
    Location
    Australia
    Posts
    152
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    lol @ Wizzup?

    Code:
    SSBraW5kYSBhZ3JlZS4uLiB3aGF0J3MgdGhlIHBvaW50IG9mIGEgYmFzZTY0IGVuY29kZXIgd2hl
    biB5b3UgY2FuIGp1c3QgdXNlIExlZXRLZXk/IDop
    Freedom is the freedom to say two plus two equals four. If that is granted, all else follows.
    - George Orwell, Nineteen Eighty-Four

  6. #6
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Code:
    WW91IGNhbiBhbHNvIGp1c3QgdHlwZSB1c2luZyB5b3VyIEtleWJvYXJkLiA6KQ==



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  7. #7
    Join Date
    May 2008
    Location
    Australia
    Posts
    152
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    Code:
    WW91IGNhbiBhbHNvIGp1c3QgdHlwZSB1c2luZyB5b3VyIEtleWJvYXJkLiA6KQ==
    Code:
    SSBrbm93ISBJdCdzIHNvIG11Y2ggZWFzaWVyLCBpc24ndCBpdD8gOkQ=
    Freedom is the freedom to say two plus two equals four. If that is granted, all else follows.
    - George Orwell, Nineteen Eighty-Four

  8. #8
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Code:
    SSBkb24ndCBrbm93IHdoZXJlIHlvdSB0YWxraW5nIGFib3V0IDooLiBCYXNlNjQgaXMgdWJlciBsZWV0IGFuZCBvZnRlbiB1c2VkIGluIGFuIGUtbWFpbCArIHdlYiBlbnZpcm9ubWVudC4uLiBBbmQgSSBuZWVkIGl0IGZvciBlbmNyeXB0aW9uICYgZGVjcnlwdGlvbiBwcm9jZXNzZXMgXl4u
    Verrekte Koekwous

  9. #9
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Code:
    Km5vdGUgdG8gc2VsZiogRGVjb2RlIGFsbCBpbnRlcmNlcHRlZCBjb21tdW5pY2F0aW9ucyBmcm9tIG1hc3RhcmF5bW9uZCB3aXRoIGJhc2U2NA==
    Interested in C# and Electrical Engineering? This might interest you.

  10. #10
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  11. #11
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    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
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  12. #12
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  13. #13
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

    Default

    Muahahhaha:
    KkhpbnQqIGkgZG9udCB0aGluayBhbnlvbmUgY2FuIGhlYXIgbW UgOlAgSSB0aGluayBNYXN0YVJheW1vbmQgaXMgZy1nLWctZ2F5 ICpXaW5rKipXaW5rKg==

  14. #14
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by BobboHobbo View Post
    Muahahhaha:
    Code:
    dW1tIHBlb3BsZSBjYW4gaGVhciB5b3UgaGVoZS4uLiBhbmQgdW1tLi4uIHVtbS4uLiBCb2Jib0hv
    YmJvIGlzIGdheQ==


    ~shut

    EDIT:
    Code:
    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
    Code:
    6f 72 20 6d 61 62 65 79 20 65 76 65 6e 20 48 45 58
    Code:
    --- .-.   .-- .   -.-. --- ..- .-.. -..   .--- ..- ... -   ..- ... .   -- --- .-. ... .   -.-. --- -.. .

  15. #15
    Join Date
    Mar 2008
    Location
    The Netherlands
    Posts
    1,395
    Mentioned
    1 Post(s)
    Quoted
    1 Post(s)

    Default

    Hello, I'm

    Code:
    TGF1cmVuc3NpZTA=


    Now go make a MD5 decoder


  16. #16
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    i changed it a bit
    SCAR Code:
    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

  17. #17
    Join Date
    Dec 2006
    Location
    SC
    Posts
    692
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

  18. #18
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

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


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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •