Sign in to follow this  
Followers 0

decrypted array don't match ctrl-read

6 posts in this topic


I don't know whats wrong whit this picture :)
I've a encrypted and decrypted array called $usernames  (this was whit _Crypt_EncryptData)

if ubound($userNames)> 0 then
  for $i = 0 to ubound($usernames)-1
    If $usernames[$i] = GUICtrlRead($combo_usr_select) Then
      consolewrite("YES " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($combo_usr_select))
        consolewrite("NO " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($combo_usr_select))

When i try to look up the GUICtrlRead($combo_usr_select) in this array he can't find it :S
in every case the consolewrite say's NO instead of YES when $usernames[$i] And GUICtrlRead($combo_usr_select) are equal.

Did i do something wrong ???
please advice and thanks in advanced.


as finishing touch god created the dutch

Share this post

Link to post
Share on other sites

Make a runable script which showing the issue. 

Share this post

Link to post
Share on other sites
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#Include <Timers.au3>
#include <Crypt.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Pie", 170, 235, 190, 200)
local $usernames[0]
local $passwords[0]

$myText="Hello World"


global $selectuser = GUICtrlCreateCombo("", 21, 95, 130, 20)
$addusername = GUICtrlCreateButton("Add", 21, 170, 130, 30)
$usernamefield = GUICtrlCreateInput("", 21, 120, 130, 20)
$passwordfield = GUICtrlCreateInput("", 21, 145, 130, 20, 0x0020)

func encrypt()
    Local $hFileOpen = FileOpen("data.srmt",  $FO_APPEND)
   ;~     Local $hFileOpen = FileOpen("data.txt",  $FO_OVERWRITE + $FO_BINARY)

    if guictrlread($usernamefield) <> "" then
;~   local $encryptedusername = string(guictrlread($usernamefield))
;~   local $encryptedpassword = string(guictrlread($passwordfield))
      local $encryptedusername = string(_Crypt_EncryptData(guictrlread($usernamefield), "P14h735536jk3fvvbg", $CALG_AES_128))
      local $encryptedpassword = string(_Crypt_EncryptData(guictrlread($passwordfield ), "P14h735536jk3fvvbg", $CALG_AES_128))

        FileWrite($hFileOpen, $encryptedusername & @CRLF)
        FileWrite($hFileOpen, $encryptedpassword & @CRLF)


func decrypt()
    Local $hFileOpen = FileOpen("data.srmt", $FO_READ)

    consolewrite(_FileCountLines("data.srmt") & " lines in the file" & @CRLF)

    for $i = 1 to _FileCountLines("data.srmt")/2
        local $encryptedusername = FileReadLine($hFileOpen)
        local $encryptedpassword = FileReadLine($hFileOpen)

        consolewrite($encryptedusername  & @CRLF)
        consolewrite($encryptedpassword  & @CRLF)

;~         _ArrayAdd($usernames, FileReadLine($hFileOpen))
;~         _ArrayAdd($passwords, FileReadLine($hFileOpen))

        _ArrayAdd($usernames, binarytostring(_Crypt_DecryptData(binary($encryptedusername), "P14h735536jk3fvvbg", $CALG_AES_128)))
        _ArrayAdd($passwords, binarytostring(_Crypt_DecryptData(binary($encryptedpassword), "P14h735536jk3fvvbg", $CALG_AES_128)))


    consolewrite(ubound($usernames) & " entries in array")

    if ubound($userNames)> 0 then
        for $i = 0 to ubound($usernames)-1
            GUICtrlSetData($selectuser, $usernames[$i] & @CRLF)

func updatecomboandinfo()
   if not GUICtrlRead($usernamefield) = "" Then
      _ArrayAdd($usernames, GUICtrlRead($usernamefield))
      _ArrayAdd($passwords, GUICtrlRead($passwordfield))

      GUICtrlSetData($selectuser, $usernames[UBound($usernames)-1])



While True
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $addusername
         GUICtrlSetData($usernamefield, "")
         GUICtrlSetData($passwordfield, "")
      Case $selectuser
         if ubound($userNames)> 0 then
            for $i = 0 to ubound($usernames)-1
;~                      msg( "error",$usernames[$i])
               If $usernames[$i] = GUICtrlRead($selectuser) Then
                  consolewrite("YES " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser))
;~                         msg( "error",$usernames[$i])
                  consolewrite("NO " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser))

something like this? :)

as finishing touch god created the dutch

Share this post

Link to post
Share on other sites

thanks @AutoBert This was totaly the problem :)
Altough I don't get it why this wasn't working.
Can you explain why?

as finishing touch god created the dutch

Share this post

Link to post
Share on other sites

The string readed from combo has a carigereturn and a linefeed at the end, the original string in array doesn't. So there's no match.

Share this post

Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening
      I was looking around the forum if I could find a function that allows to convert a string into a 2 dimensional array...
      The first column of the array is always the same, but the rows could change...
      I have a pattern like:

      Column A|Column B
      Static Text 1|Data 1
      Static Text 2|Data 2
      Static Text 3|Data 3
      Static Text 4|Data 4

      Where, Static Text (1...4) will be always the same, and I don't want to change them... But, Data 1...4 are dynamic fields... So, I could have the pattern above AND I coould have the pattern I'm going to show you right below

      Column A|Column B
      Static Text 1|Data 1
      Static Text 2|Data 2
      Static Text 3|Data 3
      Static Text 4|Data 4
      Static Text 1|Data 5
      Static Text 2|Data 6
      Static Text 3|Data 7
      Static Text 4|Data 8

      How can I do in this case?

      Thanks for everyone's help

    • ur
      By ur
      I have a string with comma seperated as below.
      $machine_names = StringSplit($tempINIValue, ',', $STR_ENTIRESPLIT) with the above line i can get a single dimension array.
      But I want a tabular format array like 4X4 where I want to add the 4 single dimension arrays as different columns in them.
      Is there any option to do the same.
    • 232showtime
      By 232showtime
      im getting strange output in array display,$split_[1] is not properly aligned to other arrays and why guictrlsetdata is not writting any data if i put comma(,) at the end of the text in $Input1???
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\user\Desktop\Script\StringSplit.kxf $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Input1 = GUICtrlCreateInput("50UGITQ421X, 50UGITQ422X, 50UGITQ423X, 50UGITQ427X, 50UGITQ431X, 50UGITQ435X, 50UGITQ436X, 50UGITQ437X, 50UGITQ441X, 50UGITQ445X, 50UGITQ449X, 50UGITQ453X, 50UGITQ454X, 50UGITQ455X, 50UGITQ459X", 24, 16, 553, 21) $Split = GUICtrlCreateButton("Split", 24, 48, 75, 25) $List1 = GUICtrlCreateList("", 24, 96, 553, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Split $read = GUICtrlRead($Input1) $split_ = StringSplit($read, ",") $Max = UBound($split_, 1) For $i = 1 To UBound($split_) - 1 ConsoleWrite($split_[$i] & @CRLF) ;~ ControlSetText($Form1, "", $List1, $split_[$i]) GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $i) Next _ArrayDisplay($split_) EndSwitch WEnd  
    • hcI
      By hcI
      Hey !
      I was looking for an array display to see the result of StringSplit but when i called the <Array.au3>, an error is showing up when i try to launch the script.
      I took a screenshoot of the windows dialog box error : imp.bmp
      And when I look into the Array.au3 there is no error :
      Why is it doing this ?
    • spudw2k
      By spudw2k
      I was reading a recent post about converting a 2D array into a 1D array.  The OP, from my understanding, more-or-less wanted to extract a single column of data and format it in a 1D array.  The solutions were proper and efficient compared to what I wanted to share, but I figured I'd share as it's a good lesson and a neat, purely mathematical approach to mapping an index to a 2D array.  As-is, this only works for 2D arrays.  
      By knowing how big a 2D array is, an index can be calculated for each indices/subscript.  The functions below define a random sized 2D array, and calculate an index that matches the indices on the 2D array.
      #include "Array.au3" $iRow = Random(2,10,1) $iCol = Random(2,10,1) $iRandomIndex = Random(0,($iRow*$iCol)-1,1) $sIndicies = _IndexTo2DIndicies($iRandomIndex, $iRow, $iCol) _2DArrayTo1DIndexes($iRow, $iCol, $iRandomIndex & " = $aArr" & $sIndicies) Func _2DArrayTo1DIndexes($iRow = 1, $iCol = 1, $sMsg = Default) $iRow = Int($iRow) $iCOl = Int($iCol) Local $aData[$iRow][$iCol] For $iY = 0 to $iRow - 1 For $iX = 0 to $iCol - 1 Local $iIndex ;Index = ($iColMax * $iY) + $iX $aData[$iY][$iX] = ($iCol * $iY) + $iX Next Next If $sMsg = Default Then $sMsg = "1D Indexes of 2D Array Indicies" _ArrayDisplay($aData,$sMsg) EndFunc Func _IndexTo2DIndicies($iIndex = 0, $iRow = 0, $iCol = 0) $iIndex = Int($iIndex) $iRow = Int($iRow) $iCol = Int($iCol) If $iIndex = 0 Then Return "[0][0]" If $iIndex >= $iRow * $iCol Then Return SetError(1,0,0) Local $iX = Mod($iIndex, $iCol) ;Local $iY = ($iIndex-$iX) / $iCol Local $iY = Int($iIndex / $iCol) ;Thanks Chimp Return "[" & $iY & "][" & $iX & "]" EndFunc I used this type of approach before with a pixel array.  I had a 1D array for storing individual pixel information, then mapped the pixels to an X|Y grid (2D array or XY coords).

      Now if the purpose is just to flatten an array, the most efficient way I am aware of would be to create a new 1D array the size of the total number of indices in the 2D array (RowMax * ColMax), and loop through the array.  I suppose these methods (above) would be particularly useful if you need to randomly or programmatically access indices in a non-linear fashion.

      Anyways, just wanted to share a fun exercise with arrays.