queensoft Posted January 29, 2011 Posted January 29, 2011 I really need some help from someone who knows Javascript and AutoIt. I need to convert one simple function from Javascript to AutoIt. Javascript function decrypt(str, key1, key2) { var loc1 = []; for (var loc3 = 0; loc3 < str.length; ++loc3) { loc1.push(("000" + parseInt(str.charAt(loc3), 16).toString(2)).slice(-4)); } loc1 = loc1.join("").split(""); var loc6 = []; for (var loc3 = 0; loc3 < 384; ++loc3) { key1 = (key1 * 11 + 77213) % 81371; key2 = (key2 * 17 + 92717) % 192811; loc6[loc3] = (key1 + key2) % 128; } for (var loc3 = 256; loc3 >= 0; --loc3) { var loc5 = loc6[loc3]; var loc4 = loc3 % 128; var loc8 = loc1[loc5]; loc1[loc5] = loc1[loc4]; loc1[loc4] = loc8; } for (var loc3 = 0; loc3 < 128; ++loc3) { loc1[loc3] = loc1[loc3] ^ loc6[loc3 + 256] & 1; } var loc12 = loc1.join(""); var loc7 = []; for (var loc3 = 0; loc3 < loc12.length; loc3 = loc3 + 4) { var loc9 = loc12.substr(loc3, 4); loc7.push(loc9); } var loc2 = []; for (var loc3 = 0; loc3 < loc7.length; ++loc3) { loc2.push(parseInt(loc7[loc3], 2).toString(16)); } return loc2.join(""); } Test values: str = ad19c236bb89c8f39107af618e576fe8 key1 = 1745 key2 = 7617 result = b8a984a0ea5efdf6fd9f15f0f00411ad Thanks.
queensoft Posted January 29, 2011 Author Posted January 29, 2011 So far, I managed to convert just the first 6 lines (sloppy code, messy array indexes and deletes): Func decrypt($str, $key1, $key2) Local $loc1[1] for $loc3 = 0 to StringLen($str) _ArrayAdd($loc1, StringRight(_Bin(Dec(StringMid($str, $loc3, 1))), 4)) Next _ArrayDelete($loc1, 0) _ArrayDelete($loc1, 0) $t = "" for $i=0 to UBound($loc1)-1 $t = $t & $loc1[$i] Next Local $loc2[StringLen($t)] for $i=0 to StringLen($t)-1 $loc2[$i] = StringMid($t, $i, 1) Next ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $t = ' & $t & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console _ArrayDelete($loc2, 0) _ArrayDisplay($loc2) EndFunc
UEZ Posted January 29, 2011 Posted January 29, 2011 (edited) First, it is not working according to the result from post#1 (result = b8a984a0ea5efdf6fd9f15f0f00411ad) expandcollapse popup#include <Array.au3> #include <String.au3> MsgBox(0, "Test", decrypt("ad19c236bb89c8f39107af618e576fe8", 1745, 7617)) Func decrypt($str, $key1, $key2) Local $tString, $loc3, $loc4, $loc5, $loc8, $loc12 Dim $loc1[1], $loc2[1], $loc6[384], $loc7[1] For $loc3 = 1 To StringLen($str) _ArrayAdd($loc1, StringRight("000" & Integer2Binary(Dec(StringMid($str, $loc3, 1))), 4)) Next $loc1 = StringSplit(_ArrayToString($loc1, ""), "", 2) For $loc3 = 0 To 383 $key1 = Mod(($key1 * 11 + 77213), 81371) $key2 = Mod(($key2 * 17 + 92717), 192811) $loc6[$loc3] = Mod(($key1 + $key2), 128) Next For $loc3 = 256 To 0 Step - 1 $loc5 = $loc6[$loc3] $loc4 = Mod($loc3, 128) $loc8 = $loc1[$loc5] $loc1[$loc5] = $loc1[$loc4] $loc1[$loc4] = $loc8 Next For $loc3 = 0 To 127 $loc1[$loc3] = BitXOR($loc1[$loc3], BitAND($loc6[$loc3 + 256], 1)) Next $loc12 = _ArrayToString($loc1, "") $loc7 = StringRegExp($loc12, ".{4}", 3) For $loc3 = 0 To UBound($loc7) - 1 _ArrayAdd($loc2, Hex(Binary2Integer($loc7[$loc3]), 1)); Next _ArrayDelete($loc2, 0) Return _ArrayToString($loc2, "") EndFunc Func Integer2Binary($in) If $in = 0 Then Return 0 Local $bin While $in > 0 $bin &= Mod($in, 2) $in = Floor($in / 2) WEnd Return(_StringReverse($bin)) EndFunc Func Binary2Integer($in) If $in = "" Then SetError(1, 0, "") Local $i, $aIn, $int, $b $aIn = StringSplit($in, "") For $i = $aIn[0] To 1 Step - 1 $int += $aIn[$i] * 2 ^ $b $b += 1 Next Return SetError(0, 0, $int) EndFunc I've only a little knowledge with JS and do not know how to debug properly JS. But you can use it as a start. Br, UEZ Edited January 30, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Daddy Posted January 29, 2011 Posted January 29, 2011 I did it in a slightly different way than UEZ, but I still came up with the exact same incorrect result that he did.expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <Array.au3> #NoTrayIcon Global $sResult = _Decrypt("ad19c236bb89c8f39107af618e576fe8", 1745, 7617) ConsoleWrite("!" & $sResult & @CRLF) ; result = b8a984a0ea5efdf6fd9f15f0f00411ad Func _Decrypt($s_Str, $s_Key1, $s_Key2) Local $aLoc1[StringLen($s_Str)] = [StringLen($s_Str)] For $i = 1 To StringLen($s_Str) $aLoc1[$i - 1] = StringRight(_DecToBinary("000" & Dec(StringMid($s_Str, $i, 1))), 4) Next $aLoc1 = StringSplit(_ArrayToString($aLoc1, ""), "", 2) ;_ArrayDisplay($aLoc1) Local $aLoc6[384] For $i = 0 To 383 $s_Key1 = Mod(($s_Key1 * 11 + 77213), 81371) $s_Key2 = Mod(($s_Key2 * 17 + 92717), 192811) $aLoc6[$i] = Mod(($s_Key1 + $s_Key2), 128) Next ;_ArrayDisplay($aLoc6) Local $iLoc4, $iLoc5, $iLoc8 For $i = 256 To 0 Step -1 $iLoc5 = $aLoc6[$i] $iLoc4 = Mod($i, 128) $iLoc8 = $aLoc1[$iLoc5] $aLoc1[$iLoc5] = $aLoc1[$iLoc4] $aLoc1[$iLoc4] = $iLoc8 Next ;_ArrayDisplay($aLoc1) For $i = 0 To 127 $aLoc1[$i] = BitAND($aLoc1[$i] ^ $aLoc6[$i + 256], 1) Next Local $sLoc12 = _ArrayToString($aLoc1, ""), $aLoc7[StringLen($sLoc12) / 4], $sLoc9, $x = 1 For $i = 0 To UBound($aLoc7) - 1 $sLoc9 = StringMid($sLoc12, $x, 4) $aLoc7[$i] = $sLoc9 $x += 4 Next ;_ArrayDisplay($aLoc7) Local $aLoc2[UBound($aLoc7)] For $i = 0 To UBound($aLoc7) - 1 $aLoc2[$i] = Hex($aLoc7[$i], 1) Next ;_ArrayDisplay($aLoc2) Return _ArrayToString($aLoc2, "") EndFunc ;==>_Decrypt Func _DecToBinary($i_Dec) Local $i = 1, $x, $s_BinChar = "" Do $x = 16 ^ $i $i += 1 Until $i_Dec < $x For $n = 4 * ($i - 1) To 1 Step -1 If BitAND(2 ^ ($n - 1), $i_Dec) Then $s_BinChar &= "1" Else $s_BinChar &= "0" EndIf Next Return $s_BinChar EndFunc ;==>_DecToBinaryI assume the function comes from this script, so I'll try using it to see what we're doing wrong.http://userscripts.org/scripts/review/42944
Daddy Posted January 30, 2011 Posted January 30, 2011 Okay, I found the problem, but I have no idea why it's happening. Test 4 is the one that is failing so there has to be something wrong with this loop.;for (var loc3 = 0; loc3 < 128; ++loc3) { For $i = 0 To 127 ; loc1[loc3] = loc1[loc3] ^ loc6[loc3 + 256] & 1 $aLoc1[$i] = BitAND($aLoc1[$i] ^ $aLoc6[$i + 256], 1) NextHere's my full current code.expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <Array.au3> #NoTrayIcon Global $string = "c98a452aea51564bc7312ab466f909b9" Global $key_1 = 27525 Global $key_2 = 24350 Global $test_1 = "11001001100010100100010100101010111010100101000101010110010010111100011100110001001010101011010001100110111110010000100110111001" Global $test_2 = "615457796668559291175199472205518317755103104971141026611373126412012387735661122253782119116125492359848373116106781141087963116810894657271149985111414650615780276323532922810511044987411011518124628910811143851877827116836892227723219722711910620858921181031241133212287981094079666873821836490123816870103985649115401101191156811811557056154375581107299413748313574532127266128111731566794124614411665942310679253106100215129103231215347556781112338179100240108146211120319699102993115722811257998286815112637771001148911590631684491237110210880601261135897465063355106396811461043241131092857016107681108787695654841165684784186287681424582891026964713118807012111428122821161077110860076651251218709119751242878410401510923921222657228329505119550691022711887357425711612551709264120388084101639513281122710255385117897567951116" Global $test_3 = "00101011111001000110011001011110000011010101001110010000010001011101010110010011100010111010011001101001000001101011110100001110" Global $test_4 = "10010001101011110010111110011110010010000001010110110000100001101100100110011101101001100111001111011111000001010111011111011000" Global $test_5 = "10010001101011110010111110011110010010000001010110110000100001101100100110011101101001100111001111011111000001010111011111011000" Global $test_6 = "91af2f9e4815b086c99da673df0577d8" Global $sResult = _Decrypt($string, $key_1, $key_2) ConsoleWrite("!" & $sResult & @CRLF) ConsoleWrite("!Test 6 = " & ($sResult=$test_6) & @CRLF) Func _Decrypt($s_Str, $s_Key1, $s_Key2) Local $aLoc1[StringLen($s_Str)] = [StringLen($s_Str)] For $i = 1 To StringLen($s_Str) $aLoc1[$i - 1] = StringRight(_DecToBinary("000" & Dec(StringMid($s_Str, $i, 1))), 4) Next $aLoc1 = StringSplit(_ArrayToString($aLoc1, ""), "", 2) ;_ArrayDisplay($aLoc1) ConsoleWrite("!Test 1 = " & (_ArrayToString($aLoc1, "")=$test_1) & @CRLF) Local $aLoc6[384] For $i = 0 To 383 $s_Key1 = Mod(($s_Key1 * 11 + 77213), 81371) $s_Key2 = Mod(($s_Key2 * 17 + 92717), 192811) $aLoc6[$i] = Mod(($s_Key1 + $s_Key2), 128) Next ;_ArrayDisplay($aLoc6) ConsoleWrite("!Test 2 = " & (_ArrayToString($aLoc6, "")=$test_2) & @CRLF) Local $iLoc4, $iLoc5, $iLoc8 For $i = 256 To 0 Step -1 $iLoc5 = $aLoc6[$i] $iLoc4 = Mod($i, 128) $iLoc8 = $aLoc1[$iLoc5] $aLoc1[$iLoc5] = $aLoc1[$iLoc4] $aLoc1[$iLoc4] = $iLoc8 Next ;_ArrayDisplay($aLoc1) ConsoleWrite("!Test 3 = " & (_ArrayToString($aLoc1, "")=$test_3) & @CRLF) ;for (var loc3 = 0; loc3 < 128; ++loc3) { For $i = 0 To 127 ; loc1[loc3] = loc1[loc3] ^ loc6[loc3 + 256] & 1 $aLoc1[$i] = BitAND($aLoc1[$i] ^ $aLoc6[$i + 256], 1) Next ;_ArrayDisplay($aLoc1) ConsoleWrite("!Test 4 = " & (_ArrayToString($aLoc1, "")=$test_4) & @CRLF) Local $sLoc12 = _ArrayToString($aLoc1, ""), $aLoc7[StringLen($sLoc12) / 4], $sLoc9, $x = 1 For $i = 0 To UBound($aLoc7) - 1 $sLoc9 = StringMid($sLoc12, $x, 4) $aLoc7[$i] = $sLoc9 $x += 4 Next ;_ArrayDisplay($aLoc7) ConsoleWrite("!Test 5 = " & (_ArrayToString($aLoc7, "")=$test_5) & @CRLF) Local $aLoc2[UBound($aLoc7)] For $i = 0 To UBound($aLoc7) - 1 $aLoc2[$i] = Hex($aLoc7[$i], 1) Next ;_ArrayDisplay($aLoc2) Return _ArrayToString($aLoc2, "") EndFunc Func _DecToBinary($i_Dec) Local $i = 1, $x, $s_BinChar = "" Do $x = 16 ^ $i $i += 1 Until $i_Dec < $x For $n = 4 * ($i - 1) To 1 Step -1 If BitAND(2 ^ ($n - 1), $i_Dec) Then $s_BinChar &= "1" Else $s_BinChar &= "0" EndIf Next Return $s_BinChar EndFunc
jaberwacky Posted January 30, 2011 Posted January 30, 2011 (edited) When I run the original javascript in IE the result that I get back is e08e5e85b27927d3e299b23711757ac9. Is the '^' bitwise XOR? Edited January 30, 2011 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
Daddy Posted January 30, 2011 Posted January 30, 2011 (edited) When I run the original javascript in IE the result that I get back is e08e5e85b27927d3e299b23711757ac9. I get the same result with this HTML code. expandcollapse popup<html><body><script type="text/javascript"> function decrypt(str, key1, key2) { var loc1 = []; for (var loc3 = 0; loc3 < str.length; ++loc3) { loc1.push(("000" + parseInt(str.charAt(loc3), 16).toString(2)).slice(-4)); } loc1 = loc1.join("").split(""); var loc6 = []; for (var loc3 = 0; loc3 < 384; ++loc3) { key1 = (key1 * 11 + 77213) % 81371; key2 = (key2 * 17 + 92717) % 192811; loc6[loc3] = (key1 + key2) % 128; } for (var loc3 = 256; loc3 >= 0; --loc3) { var loc5 = loc6[loc3]; var loc4 = loc3 % 128; var loc8 = loc1[loc5]; loc1[loc5] = loc1[loc4]; loc1[loc4] = loc8; } for (var loc3 = 0; loc3 < 128; ++loc3) { loc1[loc3] = loc1[loc3] ^ loc6[loc3 + 256] & 1; } var loc12 = loc1.join(""); var loc7 = []; for (var loc3 = 0; loc3 < loc12.length; loc3 = loc3 + 4) { var loc9 = loc12.substr(loc3, 4); loc7.push(loc9); } var loc2 = []; for (var loc3 = 0; loc3 < loc7.length; ++loc3) { loc2.push(parseInt(loc7[loc3], 2).toString(16)); } return loc2.join(""); } var x = decrypt('ad19c236bb89c8f39107af618e576fe8', 1745, 7617) document.write(x); </script></body></html> http://www.w3schools.com/js/tryit.asp?filename=tryjs_intro EDIT: Using the string and keys from my last post gives a result matching what I have in the code ($test_6). Is the '^' bitwise XOR? Yes, it is. Nice catch. Edited January 30, 2011 by Daddy
jaberwacky Posted January 30, 2011 Posted January 30, 2011 Good work, Johnson. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
queensoft Posted January 30, 2011 Author Posted January 30, 2011 (edited) Thanks guys for all your help !! I also managed to finish a working script, late last night. It's basically same as your, but more sloppy. I never knew about _ArrayToString and StringSlip using "" as delimiter. Anyway, I get the same results as you, different from test one. And yes, the function is from Direct Megavideo FLV link script. But, one good think: even this different result works !!! I can download the video just fine !! And one more discovery: there are different versions of same video. Now I have to figure out how the get the HD direct link !!! There's also a greasemoney script, but no source code for this one: https://addons.mozilla.org/en-US/firefox/addon/748 Later edit: got it !!!! HD parameters are inside XML file, just like regular ones !! I'm using the exact same function, different paraemtes, I'm able to get the HD link ! Great ! Edited January 30, 2011 by queensoft
UEZ Posted January 30, 2011 Posted January 30, 2011 Yes, indeed the ^ is the xor operator! To complete also my code I update it on my 1st post. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
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