Jump to content

Trying to populate value in array


Jason_A
 Share

Recommended Posts

I've looked on the board for this but the only other person I saw who had the same problem gave up on trying to get it to work.

Here is a snippet of the code:

Dim $charDec[25]
While 1
    For $i = 1 to 1000
    $line = FileReadLine($incoming,$i)
    If @Error > 0 Then
        ExitLoop
    Else
        If StringLeft($line,4) = "^PSE" Then
            $empID = StringMid($line,8,3)
            $passEnc = StringRight($line,(StringLen($line) - 23))
            For $j = 1 to (StringLen($passEnc)/4)
                $k = ($j * 4) - 3
                $charEnc = StringMid($passEnc,$k,4)
                $charDec[$j] = Decrypt($charEnc)
            Next
            $passDec = _ArrayToString($charDec,"")
            FileWriteLine($outgoing,"Employee ID = " & $empID & " - Password = " & $passDec)
        EndIf
    EndIf
    Next
    ExitLoop
WEnd

The error is in the line "$charDec[$j] = Decrypt($charEnc)." There is a custom function that seems to be working properly. Any time I try to get a value into $charDec[$j], it gives me the error: "Expected a "=" operator in assignment statement." The variable is correctly Dimmed as an array with more elements than I could possibly need. The custom function is returning a single character. I've also tried putting it into the [(j-1)]th element but got the same thing. Any ideas? Thanks.

Link to comment
Share on other sites

Do you have the code for the Decrypt function?

Not sure if it's going to help you much, but here you go... :o

Func Decrypt($charEnc)
    $work = Number($charEnc)
    Select
    Case $work < 2038
        $charDec = Chr($work - 1983)
    Case $work < 2048
        $charDec = Chr($work - 1985)
    Case $work < 2058
        $charDec = Chr($work - 1987)
    Case $work < 2068
        $charDec = Chr($work - 1989)
    Case $work < 2078
        $charDec = Chr($work - 1991)
    Case $work < 2108
        $charDec = Chr($work - 2013)
    Case $work < 2118
        $charDec = Chr($work - 2015)
    Case $work < 2128
        $charDec = Chr($work - 2017)
    Case $work < 2138
        $charDec = Chr($work - 2019)
    Case $work < 2148
        $charDec = Chr($work - 2021)
    Case Else
        $charDec = Chr(42)
    EndSelect
    Return($charDec)
EndFunc

Just curious (unrelated question), why is there a while loop if you just exitloop after the for loop is done?

Maybe unnecessary, just something I've picked up from somewhere. It gives me an easy way to exit from the loop if the process reaches the end of the file or encouters some other error.
Link to comment
Share on other sites

AutoIt only runs one case and then breaks (exits the select).

MsgBox (0, "", Decrypt (2000))


Func Decrypt($charEnc)
    $work = Number($charEnc)
    Select
    Case $work < 2038
        $charDec = Chr($work - 1983)
        MsgBox (0, "", " < 2038")
    Case $work < 2048
        $charDec = Chr($work - 1985)
        MsgBox (0, "", " < 2048")
    Case $work < 2058
        $charDec = Chr($work - 1987)
        MsgBox (0, "", " < 2058")
    Case $work < 2068
        $charDec = Chr($work - 1989)
        MsgBox (0, "", " < 2068")
    Case $work < 2078
        $charDec = Chr($work - 1991)
        MsgBox (0, "", " < 2078")
    Case $work < 2108
        $charDec = Chr($work - 2013)
        MsgBox (0, "", " < 2108")
    Case $work < 2118
        $charDec = Chr($work - 2015)
        MsgBox (0, "", " < 2118")
    Case $work < 2128
        $charDec = Chr($work - 2017)
        MsgBox (0, "", " < 2128")
    Case $work < 2138
        $charDec = Chr($work - 2019)
        MsgBox (0, "", " < 2138")
    Case $work < 2148
        $charDec = Chr($work - 2021)
        MsgBox (0, "", " < 2148")
    Case Else
        $charDec = Chr(42)
    EndSelect
    Return($charDec)
EndFunc
Link to comment
Share on other sites

I'm trying to test it here, but since I don't have enough info, it's being tough. Can you supply the line of text that fits the description ("^PSE")?

try this as a sample file...

^PSEMP(100,"PASSWORD")=205221362135213020622135
^PSEMP(104,"PASSWORD")=2063211221342130212721102052
^PSEMP(105,"PASSWORD")=212021332116211621272126211221142121212221272116
^PSEMP(106,"PASSWORD")=2032213421352071211221342134
^PSEMP(107,"PASSWORD")=2053213021332127206221272032204220402034
Link to comment
Share on other sites

while 1
$line = FileReadLine($incoming,$i)
    If @Error == -1 Then
        ExitLoop
    ElseIf StringLeft($line,4) = "^PSE" Then
        $empID = StringMid($line,8,3)
        $passEnc = StringRight($line,(StringLen($line) - 23))
        $charDec = "";;Clear the string $charDec
        For $j = 1 to StringLen($passEnc) Step 4
            $charEnc = StringMid( $passEnc, $j, 4)
            $charDec &= Decrypt($charEnc);;Append result from Decrypt to $charDec
        Next
        $passDec = $charDec
        FileWriteLine($outgoing, "Employee ID = " & $empID & " - Password = " & $passDec)
    EndIf
WEnd

Try this

#)

EDIT: Requres Beta for the &= operator (i think)

Edited by nfwu
Link to comment
Share on other sites

Ok, I was beat to it, but I just wanted to point out that it worked.

Global $NewCharDec[250], $line[7]
$line[1] = '^PSEMP(100,"PASSWORD")=205221362135213020622135'
$line[2] = '^PSEMP(104,"PASSWORD")=2063211221342130212721102052'
$line[3] = '^PSEMP(105,"PASSWORD")=212021332116211621272126211221142121212221272116'
$line[4] = '^PSEMP(106,"PASSWORD")=2032213421352071211221342134'
$line[5] = '^PSEMP(107,"PASSWORD")=2053213021332127206221272032204220402034'
For $zzzz = 1 To 5
    If StringLeft($line[$zzzz],4) = "^PSE" Then
        $empID = StringMid($line[$zzzz],8,3)
        $passEnc = StringRight($line[$zzzz],(StringLen($line[$zzzz]) - 23))
        For $j = 1 to (StringLen($passEnc)/4)
            $k = ($j * 4) - 3
            $charEnc = StringMid($passEnc,$k,4)
            $NewCharDec[$j] = Decrypt($charEnc)
            $NewCharDec[0] += 1
        Next
        $passDec = ""
        For $i = 1 To $NewCharDec[0]
            $passDec &= $NewCharDec[$i]
        Next
        MsgBox (0, "", "Employee ID = " & $empID & @CRLF & "Password = " & $passDec)
    EndIf
Next

Func Decrypt($charEnc)
    $work = Number($charEnc)
    Select
    Case $work < 2038
        $charDec = Chr($work - 1983)
    Case $work < 2048
        $charDec = Chr($work - 1985)
    Case $work < 2058
        $charDec = Chr($work - 1987)
    Case $work < 2068
        $charDec = Chr($work - 1989)
    Case $work < 2078
        $charDec = Chr($work - 1991)
    Case $work < 2108
        $charDec = Chr($work - 2013)
    Case $work < 2118
        $charDec = Chr($work - 2015)
    Case $work < 2128
        $charDec = Chr($work - 2017)
    Case $work < 2138
        $charDec = Chr($work - 2019)
    Case $work < 2148
        $charDec = Chr($work - 2021)
    Case Else
        $charDec = Chr(42)
    EndSelect
    Return $charDec
EndFunc

Result:

Employee ID = 100

Password = AutoIt

Employee ID = 104

Password = Jason_A

Employee ID = 105

Password = greenmachine

Employee ID = 106

Password = 1stPasschine

Employee ID = 107

Password = BornIn1973ne

Edit - I remember what I was going to say a few minutes ago. I was having a big issue with the fact that the name of the array and the variable in the function were the same. I changed the name of the array to compensate, and it worked.

Edited by greenmachine
Link to comment
Share on other sites

I get the same error with nwfu's script even with the beta.

gm, you got all the passwords right except that the last two should have been 1stPass and BornIn1973... so I'll probably need to Dim the array between lines.

So, maybe the problem really is that I don't know what I'm doing with functions. But this is how I'll learn. :o

Link to comment
Share on other sites

Yeah I was wondering about the last two lines.. since "greenmachine" is longer than the other two, it leaked over. I think I know what to fix though. I'll update in a minute.

Edit - yep, thought so. Ok, all you have to do is change this little bit.

MsgBox (0, "", "Employee ID = " & $empID & @CRLF & "Password = " & $passDec)
    EndIf
$NewCharDec[0] = 0
Next

Just put that back and it'll work fine.

Edited by greenmachine
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...