DanielIvanCorti Posted November 20, 2016 Posted November 20, 2016 (edited) Hi all, I am facing a problem with _ArrayToString: when it's used on an array filled usign BinaryToString, it only puts the first element in the string generated. I have been trying for an hour different solutions without success.. #include <String.au3> #include <Array.au3> global $array[4] $array[0] = BinaryToString(99) $array[1] = BinaryToString(89) _ArrayDisplay($array) MsgBox(0, "", _ArrayToString($array)) Am I wrong or is there a bug? Thank you very much, Daniel Edited November 20, 2016 by DanielIvanCorti
Moderators Melba23 Posted November 20, 2016 Moderators Posted November 20, 2016 (edited) DanielIvanCorti, Welcome to the AutoIt forums. Looking at the way AutoIt stores the BinaryToString result, it seems it pads the return with zeros as you can see here: #include <String.au3> #include <Array.au3> global $array[4] $array[0] = BinaryToString(99) $array[1] = BinaryToString(89) ConsoleWrite(StringToBinary($array[0]) & " - " & StringLen($array[0]) & @CRLF) ConsoleWrite(StringToBinary($array[1]) & " - " & StringLen($array[1]) & @CRLF) _ArrayDisplay($array) $sString = _ArrayToString($array) ConsoleWrite(StringToBinary($sString) & " - " & $sString & @CRLF) MsgBox(0, "", _ArrayToString($array)) So the string created by _ArrayToString terminates at the first 00 which is interpreted as EOL. Now to look into why it does this. A question for you: why are you using BinaryToString to convert the elements for storage? M23 Edited November 20, 2016 by Melba23 Added question Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
DanielIvanCorti Posted November 21, 2016 Author Posted November 21, 2016 Hi M23, thank you for your reply. Umh.. I am a bit confused now.. I am taking a string into an array as binary and doing BitXOR operations (to decrypt a text), it works fine. But as you can see I cannot have back the plaintext string from the array.. Func _Crypt gives its output as HEX to simplify the handling of the crypted message. #include <Array.au3> #include <String.au3> $string = "ABCD" $key="GGHJ" $Crypted = _Crypt(StringSplit($string, ""), StringSplit($key, "")) $Decrypted = _Decrypt(StringSplit($Crypted, ":"), StringSplit($key, "")) MsgBox(0, "", $Crypted) MsgBox(0, "", $Decrypted) Func _Crypt($array, $key) For $a = 1 To $array[0] $array[$a] = Hex(BitXOR(StringToBinary($array[$a]), StringToBinary($key[$a])),2) Next Return _ArrayToString($array, ":", 1) EndFunc Func _Decrypt($array, $key) _ArrayDisplay($array) MsgBox(0, "", _ArrayToString($array, "", 1)) For $a = 1 To $array[0] $array[$a] = BinaryToString(BitXOR(Dec($array[$a]), StringToBinary($key[$a]))) Next Return _ArrayToString($array, "", 1) EndFunc
Moderators Melba23 Posted November 21, 2016 Moderators Posted November 21, 2016 DanielIvanCorti, The immediate solution to the problem is easy - use StringLeft to extract only the first character of the decrypted string, so removing all the unwanted EOLs: $array[$a] = StringLeft(BinaryToString(BitXOR(Dec($array[$a]), StringToBinary($key[$a]))), 1) However, I am unsure quite why the returned string is padded with these additional 00 characters - I will investigate further. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
DanielIvanCorti Posted November 21, 2016 Author Posted November 21, 2016 (edited) Ok, thank you very much for your help. One last question.. is it correct to do XOR like am I doing? BitXOR is really doing the XOR between bits or it is operating on the RAPPRESENTATION of that bits (like if it was a string)? Edited November 21, 2016 by DanielIvanCorti
Moderators Melba23 Posted November 21, 2016 Moderators Posted November 21, 2016 DanielIvanCorti, The explanation for the added zeroes is that AutoIt treats the number as a 32-bit integer (4 bytes) so its binary variant is same. No idea about the new question - well beyond my ken. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
UEZ Posted November 21, 2016 Posted November 21, 2016 As a workaround you can use this function: Func _Decrypt($array, $key) _ArrayDisplay($array) MsgBox(0, "", _ArrayToString($array, "", 1)) For $a = 1 To $array[0] $array[$a] = StringStripWS(BinaryToString(BitXOR(Dec($array[$a]), StringToBinary($key[$a]))), 8) Next Return _ArrayToString($array, "", 1) EndFunc 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