Raised This Month: $90 Target: $400
 22% 

check base64 encode/decode


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ScriptCoderPro
Junior Member
Join Date: Mar 2009
Old 03-08-2009 , 18:55   check base64 encode/decode
Reply With Quote #1

I found base64 encode/decode in Delphi here: http://www.swissdelphicenter.ch/torr...de.php?id=1524 and translate it to Pawn. Please check it and help with this functions, I'm newbie in Pawn.

Code:
#include <amxmodx>

static const Codes64[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"

public Encode64(s[])
{
new i=0,a=0,x=0,b=0,Result
  for (i=1;i<strlen(s);i++) {
    x = str_to_num(s[i])
    b = b * 256 + x
    a = a + 8
    while (a >= 6) {
      a = a - 6
      x = b / (1 << a)
      b = b % (1 << a)
      Result += Codes64[x + 1]
   }
  }
  if (a > 0) {
    x = b << (6 - a);
    Result += Codes64[x + 1];
 }
 return Result;
}

public Decode64(s[])
{
  new i=0,a=0,x=0,b=0,Result,ch[1]
  for (i = 1; i< strlen(s);i++) {
      for (new index = 0; Codes64[index]; index++)
    if (s[i]==Codes64[index]) {
    x=index-1
    break
    }
    if (x >= 0) {
      b = b * 64 + x
      a = a + 6
      if (a >= 8) {
        a = a - 8
        x = b >> a
        b = b % (1 << a)
        x = x % 256
        Result += num_to_word(x,ch,1)
     }
    }
    else exit;
}
return Result;
}

Last edited by ScriptCoderPro; 03-09-2009 at 08:50.
ScriptCoderPro is offline
[ --<[email protected] ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 03-08-2009 , 19:09   Re: check base64 encode/decode
Reply With Quote #2

What's the problem?

Easiest way is to try it out.

Last edited by [ --<[email protected] ] Black Rose; 03-09-2009 at 14:48.
[ --<-@ ] Black Rose is offline
Send a message via MSN to [ --<-@ ] Black Rose Send a message via Skype™ to [ --<-@ ] Black Rose
ScriptCoderPro
Junior Member
Join Date: Mar 2009
Old 03-09-2009 , 08:50   Re: check base64 encode/decode
Reply With Quote #3

I updated my first post. Check it now.
ScriptCoderPro is offline
[ --<[email protected] ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 03-09-2009 , 14:48   Re: check base64 encode/decode
Reply With Quote #4

I used another C++ source. I don't know anything about delphi. I have no clue what it does. It works.

I hope you were looking for the function and not learning how to do it.
Attached Files
File Type: inc base64.inc (3.8 KB, 469 views)

Last edited by [ --<[email protected] ] Black Rose; 03-09-2009 at 16:11.
[ --<-@ ] Black Rose is offline
Send a message via MSN to [ --<-@ ] Black Rose Send a message via Skype™ to [ --<-@ ] Black Rose
ScriptCoderPro
Junior Member
Join Date: Mar 2009
Old 03-10-2009 , 16:14   Re: check base64 encode/decode
Reply With Quote #5

Very very big thx!!! Man (or woman ) it's excellently made work! For simple test it works. I will test it more and write if it's not work. Now I can realize crypto algorithm with xor and non standart symbols.
ScriptCoderPro is offline
ScriptCoderPro
Junior Member
Join Date: Mar 2009
Old 03-10-2009 , 18:00   Re: check base64 encode/decode
Reply With Quote #6

I have a question how I can emulate two delphi functions in Pawn?
1) Ord("A") - returns number of symbol - 65
2) Chr(65) - returns from number symbol - "A"
Thx!
ScriptCoderPro is offline
[ --<[email protected] ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 03-10-2009 , 18:14   Re: check base64 encode/decode
Reply With Quote #7

You don't have to. 'A' is equal to 65 in pawn.

so if you have a string like this:
string[3] = "ABC"

and use it like this:
server_print("%c/%d", string[0], string[0]);

it would print "A/65"

Last edited by [ --<[email protected] ] Black Rose; 03-10-2009 at 18:17.
[ --<-@ ] Black Rose is offline
Send a message via MSN to [ --<-@ ] Black Rose Send a message via Skype™ to [ --<-@ ] Black Rose
ScriptCoderPro
Junior Member
Join Date: Mar 2009
Old 03-11-2009 , 13:39   Re: check base64 encode/decode
Reply With Quote #8

thx
ScriptCoderPro is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-11-2009 , 14:27   Re: check base64 encode/decode
Reply With Quote #9

What is the purpose of a base64 string?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-11-2009 , 15:02   Re: check base64 encode/decode
Reply With Quote #10

Quote:
Originally Posted by Exolent[jNr] View Post
What is the purpose of a base64 string?
It's just like any form of encoding.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:12.


Powered by vBulletin®
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Theme made by Freecode