CyRius Posted September 13, 2009 Share Posted September 13, 2009 (edited) Hey, I have a question about Bit functions. I have this function: Func _BinaryToID($iNumber,$iCharUID) $iNumber = _BinaryToDec('0x' & $iNumber,1,8) $iNumber = BitXOR(BitOR(BitShift(BitAND($iNumber,0xFFFFE000),13),BitShift(BitAND($iNumber,0x1FFF),-19)),0x5F2D2463,$iCharUID) - 0x746F4AE6 Return $iNumber EndFunc In C#: uint Target = ((uint)Data[12] & 0xFF) | (((uint)Data[13] & 0xFF) << 8) | (((uint)Data[14] & 0xFF) << 16) | (((uint)Data[15] & 0xFF) << 24); //Target = 694CA544 Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ 23143648) - 0x746F4AE6; //Target = 0 _BinaryToID('44A54C69',23143648) returns 0. I want to know if this function can be reversed (_IDToBinary(0,23143648) would return '44A54C69') I have this function, but it isnt correct (returns '694BBBD2' instead '44A54C69') and I dont know how could I correct it: Func _IDToBinary($iNumber,$iCharUID) $iNumber = BitXOR(BitOR(BitShift(BitAND($iNumber,0xFFFFE000),-13),BitShift(BitAND($iNumber,0x1FFF),19)),0x5F2D2463,$iCharUID) + 0x746F4AE6 $iNumber = _DecToBinary($iNumber,8) Return $iNumber EndFunc Func _BinaryToDec($iPacket,$iFrom,$iCount) Local $iNewPacket = '' $iPacket = BinaryMid($iPacket,$iFrom,$iCount) For $iIndex = 1 To $iCount $iNewPacket &= Hex(BinaryMid($iPacket,$iCount - $iIndex + 1,1)) Next Return Dec($iNewPacket) EndFunc Func _DecToBinary($iPacket,$iCount) $iPacket = Hex(Binary($iPacket)) If $iCount > StringLen($iPacket) Then For $iIndex = 1 To $iCount - StringLen($iPacket) $iPacket &= '0' Next Else $iPacket = StringLeft($iPacket,$iCount) EndIf Return $iPacket EndFunc Can somebody help me? Greetz, CyRius Edited September 13, 2009 by CyRius [font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list] Link to comment Share on other sites More sharing options...
omikron48 Posted September 13, 2009 Share Posted September 13, 2009 I don't think you can recover data from a bit shift operation. Link to comment Share on other sites More sharing options...
CyRius Posted September 14, 2009 Author Share Posted September 14, 2009 (edited) I don't think you can recover data from a bit shift operation. BitShift(65536,12) = 16 BitShift(16,-12) = 65525 BitShift() can be reversed if you shift "back" (if you shift 12 right, then you must shift 12 left). But I think BitAND() can't be reversed. Any ideas? Edited September 14, 2009 by CyRius [font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list] Link to comment Share on other sites More sharing options...
omikron48 Posted September 14, 2009 Share Posted September 14, 2009 A right shift can't be recovered since you lose your lower order bits in the process. A left shift can be recovered provided that the initial value is low enough that the highest order value bit isn't lost in the process. A BitOR is hard to determine if all you're given is the result and one of the input. Link to comment Share on other sites More sharing options...
CyRius Posted September 14, 2009 Author Share Posted September 14, 2009 A right shift can't be recovered since you lose your lower order bits in the process. A left shift can be recovered provided that the initial value is low enough that the highest order value bit isn't lost in the process. A BitOR is hard to determine if all you're given is the result and one of the input.It must be reversable somehow because this is a client server comunication. I have the server's source code and there is the _BinaryToTD() function. I wasn't able to get the client's source code and I don't know how could I "generate" that value with the _IDToBinary() function.Somehow it must be reversable (I hope). [font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list] Link to comment Share on other sites More sharing options...
omikron48 Posted September 14, 2009 Share Posted September 14, 2009 00011011 >> 2 = 00000110 How do you expect to guess what the last two bits were given 00000110? In right shift, you lose the lower order bits and the sign bit gets padded up front. You can't reverse it. Link to comment Share on other sites More sharing options...
CyRius Posted September 14, 2009 Author Share Posted September 14, 2009 00011011 >> 2 = 00000110How do you expect to guess what the last two bits were given 00000110?In right shift, you lose the lower order bits and the sign bit gets padded up front. You can't reverse it.Okay, i see now. Thank you.But do you have any idea how can the client generate '44A54C69' from the number 0? I don't see any other way to calculate it. [font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list] Link to comment Share on other sites More sharing options...
jvanegmond Posted September 14, 2009 Share Posted September 14, 2009 Okay, i see now. Thank you. But do you have any idea how can the client generate '44A54C69' from the number 0? I don't see any other way to calculate it. Func _Generate($n) Return $n + 0x44A54C69 EndFunc It's not possible to do what you're trying to do. In the conversion there is data loss. github.com/jvanegmond Link to comment Share on other sites More sharing options...
wolf9228 Posted September 14, 2009 Share Posted September 14, 2009 Operators Compared in Different Languages http://msdn.microsoft.com/en-us/library/2hxce09y%28VS.71%29.aspx uint Target = ((uint)Data[12] & 0xFF) | (((uint)Data[13] & 0xFF) << 8) | (((uint)Data[14] & 0xFF) << 16) | (((uint)Data[15] & 0xFF) << 24); //Target = 694CA544 Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ 23143648) - 0x746F4AE6; //Target = 0 $Target = BitAND($Data[12] , 0xFF) + BitShift(BitAND($Data[13] , 0xFF) , 8) + _ BitShift(BitAND($Data[14] , 0xFF) , 16) + BitShift(BitAND($Data[15] , 0xFF) , 24) $Target = BitXOR(BitRotate(BitAND($Target , 0xffffe000) , 13) + BitShift(BitAND($Target , 0x1fff) , 19) _ ,0x5F2D2463 ,23143648) - 0x746F4AE6 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
CyRius Posted September 15, 2009 Author Share Posted September 15, 2009 (edited) @wolf9228 Your function doesn't work for me. _BinaryToTarget('44A54C69',23143648) returns -371411555 (should return 0). Edited September 15, 2009 by CyRius [font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list] Link to comment Share on other sites More sharing options...
jvanegmond Posted September 15, 2009 Share Posted September 15, 2009 (edited) The problem with code of wolf9228 is that it uses signed integers, instead of unsigned integers, and maybe the size of the variables is different too. Edited September 15, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
wolf9228 Posted September 15, 2009 Share Posted September 15, 2009 @wolf9228 Your function doesn't work for me. _BinaryToTarget('44A54C69',23143648) returns -371411555 (should return 0). Type the values of Data Array I will attempt uint Target = ((uint)Data[12] & 0xFF) | (((uint)Data[13] & 0xFF) << 8) | (((uint)Data[14] & 0xFF) << 16) | (((uint)Data[15] & 0xFF) << 24); //Target = 694CA544 Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ 23143648) - 0x746F4AE6; //Target = 0 These operations For C++ Programming language I think the problem in the type of the variable (uint) صرح السماء كان هنا Link to comment Share on other sites More sharing options...
CyRius Posted September 16, 2009 Author Share Posted September 16, 2009 @wolf9228 Data is an array which contains the bytes of binary variable (example: 0x2000FE0300000000E024610144A54C69EE98276115000000EDD4252F00000000). So the 12.,13.,14.,15. bytes are 0x44,0xA5,0x4C,0x69. Greetz, CyRius [font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now