Jump to content

_StringEncrypt is returning ""


Recommended Posts

PsaltyDS, you're way too nice to this guy. :)

I mean, this is ridiculous, 12 friggin pages. And now it has come down to fixing his dumb mistakes like that. I think OP has more important things to do before trying to encrypt anything. Such as... learning to code. And most importantly, actually giving some EFFORT. Something that I didn't notice even once through this entire thread.

I agree CrazeStart1074 could have put more into this, but he seems to have found a legitimate bug in that _StringEncrypt fails when you have alternate code pages loaded. Has anyone else with other code pages loaded reproduced this symptom? If we can get a reliable reproducer then it can be moved to Bug Trac.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Replies 208
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

what happens when he runs the example from the helpfile?

Please don't go there again :)

It fails and returns "". Jos has already diagnosed the problem to be with codepages, the function just needs to be re-written. :)

Link to comment
Share on other sites

I agree CrazeStart1074 could have put more into this, but he seems to have found a legitimate bug in that _StringEncrypt fails when you have alternate code pages loaded. Has anyone else with other code pages loaded reproduced this symptom? If we can get a reliable reproducer then it can be moved to Bug Trac.

:)

Since that start of the thread no one has the same problem as me.. Wondering why..

Link to comment
Share on other sites

  • 1 month later...

I also have the same problem. For some reason, one one of my XP Pro computers, it doesn't return anything when running the _StringEncrypt function. On my dell Xp Pro computer, it works properly. I am guessing that it might fail due to the operating system and not autoit.

Link to comment
Share on other sites

I also have the same problem. For some reason, one one of my XP Pro computers, it doesn't return anything when running the _StringEncrypt function. On my dell Xp Pro computer, it works properly. I am guessing that it might fail due to the operating system and not autoit.

Do you have other language code pages besides the default English loaded? The suspicion from CrazeStar1074's problem is that alternate code pages are the problem, because the string-based encryption gets messed with, but no one else has duplicated that yet.

What is the language configuration on your two XP Pro boxes?

:)

P.S. I completed my modified version of _StringEncrypt(), which is called __StringEncrypt() (with two underscores), that was discussed earlier in this topic. It is posted in Example Scripts here: Alternative to _StringEncrypt(): "Standard" RC4 from SkinnyWhiteGuy used. If you don't have to use the string-conversion and multi-pass functionality similar to the original, then you might be better off just working with straight RC4().

;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Do you have other language code pages besides the default English loaded? The suspicion from CrazeStar1074's problem is that alternate code pages are the problem, because the string-based encryption gets messed with, but no one else has duplicated that yet.

What is the language configuration on your two XP Pro boxes?

P.S. I completed my modified version of _StringEncrypt(), which is called __StringEncrypt() (with two underscores), that was discussed earlier in this topic. It is posted in Example Scripts here: Alternative to _StringEncrypt(): "Standard" RC4 from SkinnyWhiteGuy used. If you don't have to use the string-conversion and multi-pass functionality similar to the original, then you might be better off just working with straight RC4().

:)

On the computer that is causing the return to be blank, the keyboard is set to Chinese while the system language is English. On the other, it is both English for the keyboard and the system. Determined language by @KBLayout and @OSLang.

Link to comment
Share on other sites

Well, since my name was mentioned a lot in this topic, I just had to come see what about an encryption function resulted in 13 pages of conversation. I read, and I see that the _StringEncrypt function was requested to be changed from using Asc() and Chr() to Dec() and Hex(). Well, loving a good challenge involving cryptography, I have been attempting just that.

There's just one problem: in my opinion, _StringEncrypt() is weird. It's not like most other encryption functions. I can get it to successfully encrypt a string just like the current implementation works, but I'm having to do a lot of hackery to do so. Apparently, even with the Encrypt level set to 1, the function runs 2 times: once on the original input string, and then a second time on (and here's where I have the problem) the string representation of the hex of the encrypted text. i.e. if the function at first produces "5170D8EE" internally for the string "test", each 2 chars in the encrypted text matches just 1 character in the original string. However, that encrypted string is treated as a brand new string, and reencrypted as a literal string "5170D8EE". This is making a conversion to Hex and Dec very confusing for me (as I'm also using the Binary functions for storage as I have done in the past).

Now, I have made it work just as it did before. It is ugly, and will probably break with unicode still, as it uses at one point BinaryToString() to maintain compatibility with the old version. However, this method of encryption seems wrong to me, splitting up byte values and treating the raw value as a string again just doesn't seem right.

Here is my modified version that "should" work, but I can make no guarantees:

Func __StringEncrypt($i_Encrypt, $s_EncryptText, $s_EncryptPassword, $i_EncryptLevel = 1, $i_Flag = 1)
    If $i_Encrypt <> 0 And $i_Encrypt <> 1 Then
        SetError(1)
        Return ''
    ElseIf $s_EncryptText = '' Or $s_EncryptPassword = '' Then
        SetError(1)
        Return ''
    Else
        If Number($i_EncryptLevel) <= 0 Or Int($i_EncryptLevel) <> $i_EncryptLevel Then $i_EncryptLevel = 1
        Local $b_EncryptText
        Local $b_EncryptPassword
        Local $v_EncryptModified
        Local $i_EncryptCountH
        Local $i_EncryptCountG
        Local $v_EncryptSwap
        Local $av_EncryptBox[256][2]
        Local $i_EncryptCountA
        Local $i_EncryptCountB
        Local $i_EncryptCountC
        Local $i_EncryptCountD
        Local $i_EncryptCountE
        Local $v_EncryptCipher
        Local $v_EncryptCipherBy
        $b_EncryptText = StringToBinary($s_EncryptText, $i_Flag)
        $b_EncryptPassword = StringToBinary($s_EncryptPassword, $i_Flag)
        If $i_Encrypt = 1 Then
            For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
                $i_EncryptCountG = ''
                $i_EncryptCountH = ''
                $v_EncryptModified = Binary('')
                For $i_EncryptCountG = 1 To BinaryLen($b_EncryptText)
                    If $i_EncryptCountH = BinaryLen($b_EncryptPassword) Then
                        $i_EncryptCountH = 1
                    Else
                        $i_EncryptCountH += 1
                    EndIf
                    $v_EncryptModified = Binary($v_EncryptModified) & Binary('0x' & Hex(BitXOR(BinaryMid($b_EncryptText, $i_EncryptCountG, 1), BinaryMid($b_EncryptPassword, $i_EncryptCountH, 1), 255),2))
                Next
                $b_EncryptText = $v_EncryptModified
                $i_EncryptCountA = ''
                $i_EncryptCountB = 0
                $i_EncryptCountC = ''
                $i_EncryptCountD = ''
                $i_EncryptCountE = ''
                $v_EncryptCipherBy = ''
                $v_EncryptCipher = ''
                $v_EncryptSwap = ''
                $av_EncryptBox = ''
                Local $av_EncryptBox[256][2]
                For $i_EncryptCountA = 0 To 255
                    $av_EncryptBox[$i_EncryptCountA][1] = Dec(StringTrimLeft(BinaryMid($b_EncryptPassword, Mod($i_EncryptCountA, BinaryLen($b_EncryptPassword)) + 1, 1),2))
                    $av_EncryptBox[$i_EncryptCountA][0] = $i_EncryptCountA
                Next
                For $i_EncryptCountA = 0 To 255
                    $i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA][0] + $av_EncryptBox[$i_EncryptCountA][1]), 256)
                    $v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA][0]
                    $av_EncryptBox[$i_EncryptCountA][0] = $av_EncryptBox[$i_EncryptCountB][0]
                    $av_EncryptBox[$i_EncryptCountB][0] = $v_EncryptSwap
                Next
                For $i_EncryptCountA = 1 To BinaryLen($b_EncryptText)
                    $i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
                    $i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC][0]), 256)
                    $i_EncryptCountE = $av_EncryptBox[Mod(($av_EncryptBox[$i_EncryptCountC][0] + $av_EncryptBox[$i_EncryptCountD][0]), 256) ][0]
                    $v_EncryptCipherBy = BitXOR(BinaryMid($b_EncryptText, $i_EncryptCountA, 1), $i_EncryptCountE)
                    $v_EncryptCipher = Binary($v_EncryptCipher) & Binary('0x' & Hex($v_EncryptCipherBy, 2))
                Next
                $b_EncryptText = StringTrimLeft($v_EncryptCipher,2)
            Next
        Else
            $b_EncryptText = $s_EncryptText
            For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
                $b_EncryptText = Binary('0x' & $b_EncryptText)
                $i_EncryptCountB = 0
                $i_EncryptCountC = ''
                $i_EncryptCountD = ''
                $i_EncryptCountE = ''
                $v_EncryptCipherBy = ''
                $v_EncryptCipher = ''
                $v_EncryptSwap = ''
                $av_EncryptBox = ''
                Local $av_EncryptBox[256][2]
                For $i_EncryptCountA = 0 To 255
                    $av_EncryptBox[$i_EncryptCountA][1] = Dec(StringTrimLeft(BinaryMid($b_EncryptPassword, Mod($i_EncryptCountA, BinaryLen($b_EncryptPassword)) + 1, 1),2))
                    $av_EncryptBox[$i_EncryptCountA][0] = $i_EncryptCountA
                Next
                For $i_EncryptCountA = 0 To 255
                    $i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA][0] + $av_EncryptBox[$i_EncryptCountA][1]), 256)
                    $v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA][0]
                    $av_EncryptBox[$i_EncryptCountA][0] = $av_EncryptBox[$i_EncryptCountB][0]
                    $av_EncryptBox[$i_EncryptCountB][0] = $v_EncryptSwap
                Next
                For $i_EncryptCountA = 1 To BinaryLen($b_EncryptText)
                    $i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
                    $i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC][0]), 256)
                    $i_EncryptCountE = $av_EncryptBox[Mod(($av_EncryptBox[$i_EncryptCountC][0] + $av_EncryptBox[$i_EncryptCountD][0]), 256) ][0]
                    $v_EncryptCipherBy = BitXOR(BinaryMid($b_EncryptText, $i_EncryptCountA, 1), $i_EncryptCountE)
                    $v_EncryptCipher = Binary($v_EncryptCipher) & Binary('0x' & Hex($v_EncryptCipherBy,2))
                Next
                $b_EncryptText = $v_EncryptCipher
                $i_EncryptCountG = ''
                $i_EncryptCountH = ''
                $v_EncryptModified = ''
                For $i_EncryptCountG = 1 To BinaryLen($b_EncryptText)
                    If $i_EncryptCountH = BinaryLen($b_EncryptPassword) Then
                        $i_EncryptCountH = 1
                    Else
                        $i_EncryptCountH += 1
                    EndIf
                    $v_EncryptModified = Binary($v_EncryptModified) & Binary('0x' & Hex(BitXOR(BinaryMid($b_EncryptText, $i_EncryptCountG, 1), BinaryMid($b_EncryptPassword, $i_EncryptCountH, 1), 255),2))
                Next
                $b_EncryptText = BinaryToString($v_EncryptModified, $i_Flag)
            Next
        EndIf
        Return $b_EncryptText
    EndIf
EndFunc   ;==>_StringEncrypt

I believe the entire StringEncrypt Function needs to be revisited, and a different encryption method should be found.

I added the $i_Flag variable to the function, which ties into the BinaryToString and StringToBinary flags used internally, so the flags that apply to those functions should help with endianess somewhat.

Edited by SkinnyWhiteGuy
Link to comment
Share on other sites

I find the problem intersting as well.

CrazeStar1074, you're probably tired of debugging this but if you could just for reference please run this script-

$regInstance=1
$outFile=FileOpen(@ScriptDir&"\Output.txt",2)
while 1
    $val=RegEnumVal("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage",$regInstance)
    if @error<>0 then
        if @error=-1 then Exit
        FileWrite($outFile,"Instance "&$regInstance&": Enum failed with-"& @error&@CRLF)
    EndIf
    $read=RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage",$val)
    if $read="" then 
        FileWrite($outFile,"Instance" &$regInstance&"("&$val&")"&": Read empty with-"& @error&@CRLF)
        $regInstance+=1
        ContinueLoop
    EndIf
    FileWrite($outFile,"Instance" &$regInstance&"("&$val&")"&":"&$read&@CRLF)
    $size=FileGetSize(@SystemDir&"\"&$read)
    if $size=0 then 
        FileWrite($outFile,"Instance" &$regInstance&"("&$val&")"&": Get Size Failed"&@CRLF)
    EndIf
    FileWrite($outFile,"Instance" &$regInstance&"("&$val&")"&": Size-"&$size&@CRLF&@CRLF)
    $regInstance+=1
WEnd

and upload the Output.txt file it creates. It's to get a baseline for you codepage configuration which seems to be the problem causing this...

Link to comment
Share on other sites

Well, since my name was mentioned a lot in this topic...

I have been using your name in vain alot recently. Hope you don't mind! :)

Have you had a chance to see if there are any problems with the __StringEncrypt() version I did? You obviously have much more experience with the crypto than I do, so I'd like your opinion on its servicability.

I can't speak for them, but I think the devs are fully aware of the limitations of the old _StringEncrypt(), but are very wary of breaking backward compatibility. The function I did abandons backward compatibility, so it is not suitable as a direct replacement where previously encrypted data is used.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I find the problem intersting as well.

CrazeStar1074, you're probably tired of debugging this but if you could just for reference please run this script-

$regInstance=1
$outFile=FileOpen(@ScriptDir&"\Output.txt",2)
while 1
    $val=RegEnumVal("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage",$regInstance)
    if @error<>0 then
        if @error=-1 then Exit
        FileWrite($outFile,"Instance "&$regInstance&": Enum failed with-"& @error&@CRLF)
    EndIf
    $read=RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage",$val)
    if $read="" then 
        FileWrite($outFile,"Instance" &$regInstance&"("&$val&")"&": Read empty with-"& @error&@CRLF)
        $regInstance+=1
        ContinueLoop
    EndIf
    FileWrite($outFile,"Instance" &$regInstance&"("&$val&")"&":"&$read&@CRLF)
    $size=FileGetSize(@SystemDir&"\"&$read)
    if $size=0 then 
        FileWrite($outFile,"Instance" &$regInstance&"("&$val&")"&": Get Size Failed"&@CRLF)
    EndIf
    FileWrite($outFile,"Instance" &$regInstance&"("&$val&")"&": Size-"&$size&@CRLF&@CRLF)
    $regInstance+=1
WEnd

and upload the Output.txt file it creates. It's to get a baseline for you codepage configuration which seems to be the problem causing this...

Heres the output of the file ..

P.s. : it is attached below..

Output.txt

Link to comment
Share on other sites

Thanks, this does have some variance from my own (which I beleive to be standard) results. Fixing the problem for you might be as simple as selecting a new code page.

Try going to Start Menu->Settings->Control Pannel, then opening "Regional and Language Options". Then go to the "advanced" tab and scroll down the list 'code page conversion tables'. Make note of any checkboxes that are unchecked (for furture reverence) and then check them. Once they have all been checked, click OK to save the changes (might need to restart the computer). Then see if the encrypt problem still happens.

Edit: Also while you're in these menu you can verify that it is set to an English locale like we gathered before from the AutoIt macros.

Edited by evilertoaster
Link to comment
Share on other sites

  • 3 months later...

Hello,

I have exactly the same problem!!

I'd like to know if there is a solution already?

The problem is still there, because I'm using the latest autoit. I confirm the problem is still UNSOLVED.

I don't know how hard it will be to correct this. But I think it should be put to the bug list of the current release.

I followed all the tests in this thread and got the same results as xVivoCity had. I have the same OS too.

What should I do? I also accept "sit back and wait" as a solution, because I'm not urgent with this problem.

But it's still at large. Anyone can give a confirmed answer? Thanks in advance!

Link to comment
Share on other sites

Hello,

I have exactly the same problem!!

I'd like to know if there is a solution already?

The problem is still there, because I'm using the latest autoit. I confirm the problem is still UNSOLVED.

I don't know how hard it will be to correct this. But I think it should be put to the bug list of the current release.

I followed all the tests in this thread and got the same results as xVivoCity had. I have the same OS too.

What should I do? I also accept "sit back and wait" as a solution, because I'm not urgent with this problem.

But it's still at large. Anyone can give a confirmed answer? Thanks in advance!

The code page issue is not resolved. Have you tried avoiding it by using the binary RC4 version I posted in example scripts as __StringEncrypt()?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The code page issue is not resolved. Have you tried avoiding it by using the binary RC4 version I posted in example scripts as __StringEncrypt()?

:P

Nope. But I noticed that. Thank you,PsaltyDS!

So this is a known bug?:D That's good. For backward compatibility consideration I prefer to use the functionalities shipped with AutoIt release if possible. But I may try the UDF you mentioned there. I plan to make a personal password reminder, so I need encryption. :mad: But it's not very urgent. You know, everyone has a secret place to put them. :P

What I'm curious about is: Is StringEncrypt() the only function having this codepage problem? If not, it should have a higher priority on the to do list. Or people could not be confident with the international compatibility of their wonderful program made in autoit. Luckily it seems no much people care about it or use it in serious development. Forgive my rudeness. Is that true or not is another curious question. :)

Link to comment
Share on other sites

  • Developers

Forgive my rudeness. Is that true or not is another curious question. :)

Its quite simple: The OP haven't been too bothered with providing a way for me to test it myself and I am not going to load some Asian WinXp OS just to be able to replicate this.

So if any of the folks out in Asia has a vested interest in getting this resolved I am open for any fixes to the code. Pretty sure I gave a hint what function is failing and in what direction the solution should be found.

A simple testscript is provided in the thread.

I am not feeling the urge at this moment to create the test environment myself.

:P

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Its quite simple: The OP haven't been too bothered with providing a way for me to test it myself and I am not going to load some Asian WinXp OS just to be able to replicate this.

So if any of the folks out in Asia has a vested interest in getting this resolved I am open for any fixes to the code. Pretty sure I gave a hint what function is failing and in what direction the solution should be found.

A simple testscript is provided in the thread.

I am not feeling the urge at this moment to create the test environment myself.

:P

Hi Jos, I'm in Belgium now :) This is not an excuse not having some Asian testing environment. :D On winxp you have to do no more than few clicks to have it. I'm working on an English winXP with Chinese input method enabled. The interface is still in English. I have no any problem to reproduce this issue. If you like, I'd like to tell you my language settings. I think you could also reproduce it with ease. Then the problem should be almost solved I guess, because you know how to do it. :P

Link to comment
Share on other sites

I gave a test solution to it, where someone with that OS could try it and see if it worked. Might be worth seeing if it worked for them or not.

Hi,skinnywhiteguy. I'd like to have a try for that. Could you please give me the link of which post you refer to?

Although I remember I tried almost all the testing cases in this thread, I'd like to help to figure this issue out.

In fact everyone of you could reproduce the issue if it's merely caused by the language settings on WinXP.

Open "regional and language options" in the control panel, on tab "regional options" change "standard and formats" to "Chinese(PRC)", leave the "location" on this tab untouched(I don't think this setting causes problem, I have "belgium" there). Then go to the next tab "languages", I have "install files for East Asian languages" checked , others unchecked. (This step may need the origional OS CD or internet download I don't remember.) Finally go to the last tab "advanced", select again "Chinese(PRC)" under "language for non-unicode program" , under "code page conversion tables", maKe sure code page 10001, 10002, 10003, 10008,20936,50227,50229,52936,54936,936,950 are checked(normally these are automatically checked if you have done the previous steps). restart. Now you have an international language testing system. And you should be able to reproduce the issue of this thread.

Note: even you keep the language setting as I said above, it will not bother you too much. Because most Asian languages include the western characters, no displaying problem. If you don't like them, just go to control panel again, switch the setting back to what you like. This time you do not need to install anything since you have everything installed already.

To be honest, I saw many softwares developed by western people didn't take care of Asian languages. Just recent years because of the prevailing of UTF encoding, things start being changed. But still not perfect. You can also see this problem in may web script projects. On many webserver in US, you have to manually change the script to use UTF8 to communicate with the database server, causing many annoying problems. You know what, this creates a huge market in Asian country like China for CHinese IT companies, meaning those US companies losing a lot of potential users, although they provide normally lower hosting fee and better services. I really wonder why they simply ignore this. :) So I suggest every software developer should not diminish the importance of internationalization if you really wish more people would use it.

Sorry said too much nonsense. Go back to the topic. I'd like to test your or others' function and hope we could solve it.

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...