| View previous topic :: View next topic |
| Author |
Message |
Haxory' Grandmaster Cheater Supreme
Reputation: 92
Joined: 30 Jul 2007 Posts: 1900
|
Posted: Thu Jun 10, 2010 9:00 am Post subject: AS2 to PHP conversion. |
|
|
So I've just started working on a DF private server, and all the data that is sent, gets encrypted. Luckily for me, DF is not packed allowing me to see how they encrypt and decrypt their data. I x-lated the decryption myself, and most of the encryption but there is one specific line of code that I cant seem to figure out:
| Code: | | _loc4 = _loc4 + ((theText.charCodeAt(_loc1) + _loc2 + _loc3).toString(30) + _loc2.toString(30)); |
This is the whole AS2 function:
| Code: | _root.Encrypt2 = function (theText, strK)
{
var _loc4;
var _loc1;
var _loc2;
var _loc3;
var _loc5;
var _loc6;
_loc4 = new String();
_loc5 = theText.length;
_loc6 = strK.length;
for (var _loc1 = 0; _loc1 < _loc5; ++_loc1)
{
_loc2 = Math.floor(Math.random() * 66) + 33;
_loc3 = strK.charCodeAt(_loc1 % _loc6);
_loc4 = _loc4 + ((theText.charCodeAt(_loc1) + _loc2 + _loc3).toString(30) + _loc2.toString(30));
} // end of for
return (_loc4);
}; |
And those are my PHP functions:
| Code: | function encrypt2($text,$key){
$lenTxt = strlen($text);
$lenKey = strlen($key);
$loc4 = "";
for($x=0;$x<$lenTxt;$x++){
$loc2 = floor((rand(0,1000000)/1000000) * 66) + 33;
$loc3 = ord(substr($key,$x % $loc4,1));
$loc4 = $loc4 . (strval(ord(substr($text,$x,1)) + $loc2 + $loc3) . strval($loc2));
}
return($loc4);
}
function decrypt2($text,$key){
$lenTxt = strlen($text);
$lenKey = strlen($key);
$loc6 = "";
for($x=0;$x<$lenKey;$x=$x+4){
$loc5 = intval(substr($text, $x, 2), 30);
$loc4 = intval(substr($text,$x + 2, 2), 30);
$loc2 = ord(substr($key,($x / 4 % $lenKey)));
$inter = $loc5 - $loc4 - $loc2;
$loc6 = (string)$loc6 . (string)chr($inter);
}
return($loc6);
}
// Called like this: "print encrypt2("123","ZorbakOwnsYou");"
// Obviously...
|
My question is, could someone convert the following like of AS2 code into PHP code.
| Code: | | _loc4 = _loc4 + ((theText.charCodeAt(_loc1) + _loc2 + _loc3).toString(30) + _loc2.toString(30)); |
Thank you. _________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Last edited by Haxory' on Thu Jun 10, 2010 9:23 am; edited 1 time in total |
|
| Back to top |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Thu Jun 10, 2010 9:14 am Post subject: |
|
|
| I don't see what you're asking? |
|
| Back to top |
|
 |
Haxory' Grandmaster Cheater Supreme
Reputation: 92
Joined: 30 Jul 2007 Posts: 1900
|
Posted: Thu Jun 10, 2010 9:24 am Post subject: |
|
|
| CometJack wrote: | | I don't see what you're asking? |
Editted _________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel |
|
| Back to top |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Thu Jun 10, 2010 9:25 am Post subject: |
|
|
| Haxory' wrote: | | CometJack wrote: | | I don't see what you're asking? |
Editted |
You should ask this in the Flash or web section, I don't think many people here have much Flash experience so it'd be hard to convert. |
|
| Back to top |
|
 |
Haxory' Grandmaster Cheater Supreme
Reputation: 92
Joined: 30 Jul 2007 Posts: 1900
|
Posted: Thu Jun 10, 2010 9:27 am Post subject: |
|
|
| CometJack wrote: | | Haxory' wrote: | | CometJack wrote: | | I don't see what you're asking? |
Editted |
You should ask this in the Flash or web section, I don't think many people here have much Flash experience so it'd be hard to convert. |
I can do quite some AS2 and PHP. I'm just puzzled. Besides, the functions used are nearly all available in Javascript, something people round here can code in. _________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel |
|
| Back to top |
|
 |
Cheat Engine User Something epic
Reputation: 60
Joined: 22 Jun 2007 Posts: 2071
|
Posted: Wed Jun 23, 2010 8:53 am Post subject: |
|
|
| The string is an array of chars, so in PHP you can get the 'charAt(_loc1)' like 'theText[_loc1]'. PHP is weak typed, so integers can easily be used as string. They work the same. |
|
| Back to top |
|
 |
megajosh2 Expert Cheater
Reputation: -1
Joined: 15 Mar 2007 Posts: 151
|
Posted: Tue Jul 06, 2010 10:04 pm Post subject: |
|
|
I think...
| Code: |
loc4 = _loc4 + ((theText.charCodeAt(_loc1) + _loc2 + _loc3).toString(30) + _loc2.toString(30));
|
becomes...
| Code: |
$loc4 = $_loc4 + (base_convert(ord($theText[$_loc1]) + $_loc2 + $_loc3, 10, 30) + base_convert($_loc2, 10, 30));
|
ord returns the ASCII (or ANSI; I can't remember which PHP uses, which could ultimately be a problem) code for a single character, and base_convert($num, $orig, $new) converts number $num (a string for some reason) from base $orig to base $new. The latter equates to num.toString(new), with the original base implicit since the method is being used on an actual number object and not just a string. |
|
| Back to top |
|
 |
|