Jump to content

a problem with _ArrayToString


Recommended Posts

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 by DanielIvanCorti
Link to comment
Share on other sites

  • Moderators

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 by Melba23
Added question

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...