Mungo Posted October 13, 2010 Share Posted October 13, 2010 (edited) I use the _StringEncrypt function and just realised that it does not seem to encrypt 0 (zero) resulting in 0 rather than what I would have expected, the encryption string e.g. 4A60 (see example). Well, zero is not a string of course and using "0" instead would work Other numbers however do get encrypted e.g. 1 etc. Maybe someone can enlighten me?ThanksMungo#include <String.au3> ; Set encryption pw and level $encrypt_pw = "mypassword" $encrypt_lev = 1 $status = 1 $status = 0 MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status' & @lf & @lf & 'Return:' & @lf & $status) ;### Debug MSGBOX $status_xx = _StringEncrypt(1, $status, $encrypt_pw, $encrypt_lev) MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status_xx' & @lf & @lf & 'Return:' & @lf & $status_xx) ;### Debug MSGBOX ; should be: 4A60 $status = "0" MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status' & @lf & @lf & 'Return:' & @lf & $status) ;### Debug MSGBOX $status_xx = _StringEncrypt(1, $status, $encrypt_pw, $encrypt_lev) MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status_xx' & @lf & @lf & 'Return:' & @lf & $status_xx) ;### Debug MSGBOX ; should be: 4A60 Edited October 13, 2010 by Mungo Link to comment Share on other sites More sharing options...
trung0407 Posted October 13, 2010 Share Posted October 13, 2010 maybe 0 or "0" is too short string or it thinks that 0 is a null value Link to comment Share on other sites More sharing options...
KaFu Posted October 13, 2010 Share Posted October 13, 2010 0 is consider as an empty string "" and returns @error. Take a look at the function itself in string.au3. expandcollapse popup#include <String.au3> ; Set encryption pw and level $encrypt_pw = "mypassword" $encrypt_lev = 1 $status = 1 $status = 0 MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status' & @lf & @lf & 'Return:' & @lf & $status) ;### Debug MSGBOX $status_xx = _StringEncrypt(1, $status, $encrypt_pw, $encrypt_lev) MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status_xx' & @lf & @lf & 'Return:' & @lf & $status_xx & @lf & @lf & "Error Code: " & @error) ;### Debug MSGBOX ; should be: 4A60 $status = "0" MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status' & @lf & @lf & 'Return:' & @lf & $status) ;### Debug MSGBOX $status_xx = _StringEncrypt(1, $status, $encrypt_pw, $encrypt_lev) MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status_xx' & @lf & @lf & 'Return:' & @lf & $status_xx & @lf & @lf & "Error Code: " & @error) ;### Debug MSGBOX ; should be: 4A60 $status = 0 MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status' & @lf & @lf & 'Return:' & @lf & $status) ;### Debug MSGBOX $status_xx = _StringEncryptEx(1, $status, $encrypt_pw, $encrypt_lev) MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status_xx' & @lf & @lf & 'Return:' & @lf & $status_xx & @lf & @lf & "Error Code: " & @error) ;### Debug MSGBOX ; should be: 4A60 $status = "0" MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status' & @lf & @lf & 'Return:' & @lf & $status) ;### Debug MSGBOX $status_xx = _StringEncryptEx(1, $status, $encrypt_pw, $encrypt_lev) MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$status_xx' & @lf & @lf & 'Return:' & @lf & $status_xx & @lf & @lf & "Error Code: " & @error) ;### Debug MSGBOX ; should be: 4A60 Func _StringEncryptEx($i_Encrypt, $s_EncryptText, $s_EncryptPassword, $i_EncryptLevel = 1) If $i_Encrypt <> 0 And $i_Encrypt <> 1 Then SetError(1, 0, '') ; ElseIf $s_EncryptText = '' Or $s_EncryptPassword = '' Then ; SetError(1, 0, '') Else If Number($i_EncryptLevel) <= 0 Or Int($i_EncryptLevel) <> $i_EncryptLevel Then $i_EncryptLevel = 1 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 If $i_Encrypt = 1 Then For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1 $i_EncryptCountG = '' $i_EncryptCountH = '' $v_EncryptModified = '' For $i_EncryptCountG = 1 To StringLen($s_EncryptText) If $i_EncryptCountH = StringLen($s_EncryptPassword) Then $i_EncryptCountH = 1 Else $i_EncryptCountH += 1 EndIf $v_EncryptModified = $v_EncryptModified & Chr(BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountG, 1)), Asc(StringMid($s_EncryptPassword, $i_EncryptCountH, 1)), 255)) Next $s_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] = Asc(StringMid($s_EncryptPassword, Mod($i_EncryptCountA, StringLen($s_EncryptPassword)) + 1, 1)) $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 StringLen($s_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(Asc(StringMid($s_EncryptText, $i_EncryptCountA, 1)), $i_EncryptCountE) $v_EncryptCipher &= Hex($v_EncryptCipherBy, 2) Next $s_EncryptText = $v_EncryptCipher Next Else For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1 $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] = Asc(StringMid($s_EncryptPassword, Mod($i_EncryptCountA, StringLen($s_EncryptPassword)) + 1, 1)) $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 StringLen($s_EncryptText) Step 2 $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(Dec(StringMid($s_EncryptText, $i_EncryptCountA, 2)), $i_EncryptCountE) $v_EncryptCipher = $v_EncryptCipher & Chr($v_EncryptCipherBy) Next $s_EncryptText = $v_EncryptCipher $i_EncryptCountG = '' $i_EncryptCountH = '' $v_EncryptModified = '' For $i_EncryptCountG = 1 To StringLen($s_EncryptText) If $i_EncryptCountH = StringLen($s_EncryptPassword) Then $i_EncryptCountH = 1 Else $i_EncryptCountH += 1 EndIf $v_EncryptModified &= Chr(BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountG, 1)), Asc(StringMid($s_EncryptPassword, $i_EncryptCountH, 1)), 255)) Next $s_EncryptText = $v_EncryptModified Next EndIf Return $s_EncryptText EndIf EndFunc ;==>_StringEncrypt OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Mungo Posted October 14, 2010 Author Share Posted October 14, 2010 (edited) Thanks a lot Kafu! Cheers Mungo Edited October 14, 2010 by Mungo Link to comment Share on other sites More sharing options...
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