Jump to content

Is this a bug in Crypt.au3 or I am doing something wrong?


Recommended Posts

Hi 🙂

For some unknown reason, the same code behaves differently if I run it multiple times.

Currently this is the most secure software ever as it seems like I must have the correct value for $myPASS and a lot of luck too 😁

The relevant part of the code:

#include <Crypt.au3>
#include <MsgBoxConstants.au3>

global $special='[@#$%^&+=]'

ConsoleWrite(@CRLF &@CRLF &'@@ Debug(' & @ScriptLineNumber & ') : TEST1' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
Local $StringToEncrypt="LA.Alalalala123123@"
global $myPASS="LA.Alalalala123123@"
$test=ENCRYPTit($StringToEncrypt,$myPASS)
$test=DECRYPTit($test, $myPASS)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $test = ' & $test & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

ConsoleWrite(@CRLF &@CRLF &'@@ Debug(' & @ScriptLineNumber & ') : TEST2' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$StringToEncrypt="AA.Alalalala123123@"
$myPASS="LA.Alalalala123123@"
$test=ENCRYPTit($StringToEncrypt,$myPASS)
$test=DECRYPTit($test, $myPASS)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $test = ' & $test & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Func ENCRYPTit($StringToEncrypt,$myPASS)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : ENCRYPT' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $myPASS = ' & $myPASS & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $StringToEncrypt = ' & $StringToEncrypt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    Local $hKey = _Crypt_DeriveKey(Binary(LOGIN($myPASS)), $CALG_AES_256,$CALG_SHA_512) ; Declare a password string and algorithm to create a cryptographic key.
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Binary($hKey) = ' & Binary($hKey) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    local $encrypted = _Crypt_EncryptData($StringToEncrypt, Binary($hKey), $CALG_AES_256)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : binary($encrypted) = ' & binary($encrypted) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $encrypted = ' & $encrypted & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    _Crypt_DestroyKey($hKey) ; Destroy the cryptographic key.
    return Binary($encrypted)
EndFunc


Func DECRYPTit($StringToDecrypt, $myPASS)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : DECRYPT' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $myPASS = ' & $myPASS & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $StringToDecrypt = ' & $StringToDecrypt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    Local $hKey = _Crypt_DeriveKey(Binary(LOGIN($myPASS)), $CALG_AES_256, $CALG_SHA_512) ; Declare a password string and algorithm to create a cryptographic key.
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Binary($hKey) = ' & Binary($hKey) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    Local $decrypted = _Crypt_DecryptData($StringToDecrypt, Binary($hKey), $CALG_AES_256)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : binary($decrypted) = ' & Binary($decrypted) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $decrypted = ' & $decrypted & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    _Crypt_DestroyKey($hKey) ; Destroy the cryptographic key.
    Return BinaryToString(binary($decrypted))
EndFunc   ;==>DECRYPT

 

Results when it fails:

@@ Debug(6) : TEST1
>Error code: 0
@@ Debug(21) : ENCRYPT
>Error code: 0
@@ Debug(22) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(23) : $StringToEncrypt = LA.Alalalala123123@
>Error code: 0
@@ Debug(25) : Binary($hKey) = 0xC0E709E4EC010000
>Error code: 0
@@ Debug(27) : binary($encrypted) = 0x13756D1C3845579E5CAE2065B087E3661165445612CFE4A40E18372BCA170DB1
>Error code: 0
@@ Debug(28) : $encrypted = 0x13756D1C3845579E5CAE2065B087E3661165445612CFE4A40E18372BCA170DB1
>Error code: 0
@@ Debug(35) : DECRYPT
>Error code: 0
@@ Debug(36) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(37) : $StringToDecrypt = 0x13756D1C3845579E5CAE2065B087E3661165445612CFE4A40E18372BCA170DB1
>Error code: 0
@@ Debug(39) : Binary($hKey) = 0xC0E709E4EC010000
>Error code: 0
@@ Debug(41) : binary($decrypted) = 0x4C412E416C616C616C616C6131323331323340
>Error code: 0
@@ Debug(42) : $decrypted = 0x4C412E416C616C616C616C6131323331323340
>Error code: 0
@@ Debug(11) : $test = LA.Alalalala123123@
>Error code: 0


@@ Debug(13) : TEST2
>Error code: 0
@@ Debug(21) : ENCRYPT
>Error code: 0
@@ Debug(22) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(23) : $StringToEncrypt = AA.Alalalala123123@
>Error code: 0
@@ Debug(25) : Binary($hKey) = 0xC0E709E4EC010000
>Error code: 0
@@ Debug(27) : binary($encrypted) = 0x0F2E2D69E210E72B7BEC05CF7E628A7D2D872D8F38B578AD046891BCBB8B044B
>Error code: 0
@@ Debug(28) : $encrypted = 0x0F2E2D69E210E72B7BEC05CF7E628A7D2D872D8F38B578AD046891BCBB8B044B
>Error code: 0
@@ Debug(35) : DECRYPT
>Error code: 0
@@ Debug(36) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(37) : $StringToDecrypt = 0x0F2E2D69E210E72B7BEC05CF7E628A7D2D872D8F38B578AD046891BCBB8B044B
>Error code: 0
@@ Debug(39) : Binary($hKey) = 0x40F209E4EC010000
>Error code: 0
@@ Debug(41) : binary($decrypted) = 0xFFFFFFFF
>Error code: 0
@@ Debug(42) : $decrypted = -1
>Error code: 70
@@ Debug(18) : $test = ÿÿÿÿ
>Error code: 0
+>19:17:42 AutoIt3.exe ended.rc:0
+>19:17:43 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 4.54

Another different failed try without any change in the code:

@@ Debug(6) : TEST1
>Error code: 0
@@ Debug(21) : ENCRYPT
>Error code: 0
@@ Debug(22) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(23) : $StringToEncrypt = LA.Alalalala123123@
>Error code: 0
@@ Debug(25) : Binary($hKey) = 0xA0E3B88EAA010000
>Error code: 0
@@ Debug(27) : binary($encrypted) = 0x8717DBB452965C093FD48B7B14C9DA4803A8D60A9189DBE97228503B3D098653
>Error code: 0
@@ Debug(28) : $encrypted = 0x8717DBB452965C093FD48B7B14C9DA4803A8D60A9189DBE97228503B3D098653
>Error code: 0
@@ Debug(35) : DECRYPT
>Error code: 0
@@ Debug(36) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(37) : $StringToDecrypt = 0x8717DBB452965C093FD48B7B14C9DA4803A8D60A9189DBE97228503B3D098653
>Error code: 0
@@ Debug(39) : Binary($hKey) = 0x20F0B88EAA010000
>Error code: 0
@@ Debug(41) : binary($decrypted) = 0xFFFFFFFF
>Error code: 0
@@ Debug(42) : $decrypted = -1
>Error code: 70
@@ Debug(11) : $test = ÿÿÿÿ
>Error code: 0


@@ Debug(13) : TEST2
>Error code: 0
@@ Debug(21) : ENCRYPT
>Error code: 0
@@ Debug(22) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(23) : $StringToEncrypt = AA.Alalalala123123@
>Error code: 0
@@ Debug(25) : Binary($hKey) = 0x20E1B88EAA010000
>Error code: 0
@@ Debug(27) : binary($encrypted) = 0xC993721623667138C0A2C523163694C08D35BDB55682AC3979AFF804CF914592
>Error code: 0
@@ Debug(28) : $encrypted = 0xC993721623667138C0A2C523163694C08D35BDB55682AC3979AFF804CF914592
>Error code: 0
@@ Debug(35) : DECRYPT
>Error code: 0
@@ Debug(36) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(37) : $StringToDecrypt = 0xC993721623667138C0A2C523163694C08D35BDB55682AC3979AFF804CF914592
>Error code: 0
@@ Debug(39) : Binary($hKey) = 0xA0DEB88EAA010000
>Error code: 0
@@ Debug(41) : binary($decrypted) = 0xFFFFFFFF
>Error code: 0
@@ Debug(42) : $decrypted = -1
>Error code: 70
@@ Debug(18) : $test = ÿÿÿÿ
>Error code: 0
+>19:25:53 AutoIt3.exe ended.rc:0
+>19:25:53 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 3.022

 

Another try and different result again!

@@ Debug(6) : TEST1
>Error code: 0
@@ Debug(21) : ENCRYPT
>Error code: 0
@@ Debug(22) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(23) : $StringToEncrypt = LA.Alalalala123123@
>Error code: 0
@@ Debug(25) : Binary($hKey) = 0xC0EBD63F03020000
>Error code: 0
@@ Debug(27) : binary($encrypted) = 0x6916F4099537D771E17B8C970134D14EF369DEFA5937BBD5A995425023730D37
>Error code: 0
@@ Debug(28) : $encrypted = 0x6916F4099537D771E17B8C970134D14EF369DEFA5937BBD5A995425023730D37
>Error code: 0
@@ Debug(35) : DECRYPT
>Error code: 0
@@ Debug(36) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(37) : $StringToDecrypt = 0x6916F4099537D771E17B8C970134D14EF369DEFA5937BBD5A995425023730D37
>Error code: 0
@@ Debug(39) : Binary($hKey) = 0x40EDD63F03020000
>Error code: 0
@@ Debug(41) : binary($decrypted) = 0xFFFFFFFF
>Error code: 0
@@ Debug(42) : $decrypted = -1
>Error code: 70
@@ Debug(11) : $test = ÿÿÿÿ
>Error code: 0


@@ Debug(13) : TEST2
>Error code: 0
@@ Debug(21) : ENCRYPT
>Error code: 0
@@ Debug(22) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(23) : $StringToEncrypt = AA.Alalalala123123@
>Error code: 0
@@ Debug(25) : Binary($hKey) = 0xC0EBD63F03020000
>Error code: 0
@@ Debug(27) : binary($encrypted) = 0xB1FD73FE621D58CFE20D18386424EF788D4ED0528B9A95937C5FCABEE5BFB0F2
>Error code: 0
@@ Debug(28) : $encrypted = 0xB1FD73FE621D58CFE20D18386424EF788D4ED0528B9A95937C5FCABEE5BFB0F2
>Error code: 0
@@ Debug(35) : DECRYPT
>Error code: 0
@@ Debug(36) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(37) : $StringToDecrypt = 0xB1FD73FE621D58CFE20D18386424EF788D4ED0528B9A95937C5FCABEE5BFB0F2
>Error code: 0
@@ Debug(39) : Binary($hKey) = 0xC0EBD63F03020000
>Error code: 0
@@ Debug(41) : binary($decrypted) = 0x41412E416C616C616C616C6131323331323340
>Error code: 0
@@ Debug(42) : $decrypted = 0x41412E416C616C616C616C6131323331323340
>Error code: 0
@@ Debug(18) : $test = AA.Alalalala123123@
>Error code: 0
+>19:29:06 AutoIt3.exe ended.rc:0
+>19:29:07 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 2.95

 

 

Then magically, after being insistent by running the same code again, it works:

@@ Debug(6) : TEST1
>Error code: 0
@@ Debug(21) : ENCRYPT
>Error code: 0
@@ Debug(22) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(23) : $StringToEncrypt = LA.Alalalala123123@
>Error code: 0
@@ Debug(25) : Binary($hKey) = 0x1095A7F58D010000
>Error code: 0
@@ Debug(27) : binary($encrypted) = 0x5DBA6E0DD474E2C394E9ADDD688C45333ABD5CD125510849B8CD60575015C146
>Error code: 0
@@ Debug(28) : $encrypted = 0x5DBA6E0DD474E2C394E9ADDD688C45333ABD5CD125510849B8CD60575015C146
>Error code: 0
@@ Debug(35) : DECRYPT
>Error code: 0
@@ Debug(36) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(37) : $StringToDecrypt = 0x5DBA6E0DD474E2C394E9ADDD688C45333ABD5CD125510849B8CD60575015C146
>Error code: 0
@@ Debug(39) : Binary($hKey) = 0x1095A7F58D010000
>Error code: 0
@@ Debug(41) : binary($decrypted) = 0x4C412E416C616C616C616C6131323331323340
>Error code: 0
@@ Debug(42) : $decrypted = 0x4C412E416C616C616C616C6131323331323340
>Error code: 0
@@ Debug(11) : $test = LA.Alalalala123123@
>Error code: 0


@@ Debug(13) : TEST2
>Error code: 0
@@ Debug(21) : ENCRYPT
>Error code: 0
@@ Debug(22) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(23) : $StringToEncrypt = AA.Alalalala123123@
>Error code: 0
@@ Debug(25) : Binary($hKey) = 0x1095A7F58D010000
>Error code: 0
@@ Debug(27) : binary($encrypted) = 0xAA6F0C080AB9D2582FFDB980409286CF25DA2CAA2D62995C2EEE0F82205FBDEF
>Error code: 0
@@ Debug(28) : $encrypted = 0xAA6F0C080AB9D2582FFDB980409286CF25DA2CAA2D62995C2EEE0F82205FBDEF
>Error code: 0
@@ Debug(35) : DECRYPT
>Error code: 0
@@ Debug(36) : $myPASS = LA.Alalalala123123@
>Error code: 0
@@ Debug(37) : $StringToDecrypt = 0xAA6F0C080AB9D2582FFDB980409286CF25DA2CAA2D62995C2EEE0F82205FBDEF
>Error code: 0
@@ Debug(39) : Binary($hKey) = 0x1095A7F58D010000
>Error code: 0
@@ Debug(41) : binary($decrypted) = 0x41412E416C616C616C616C6131323331323340
>Error code: 0
@@ Debug(42) : $decrypted = 0x41412E416C616C616C616C6131323331323340
>Error code: 0
@@ Debug(18) : $test = AA.Alalalala123123@
>Error code: 0
+>19:32:26 AutoIt3.exe ended.rc:0
+>19:32:26 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 3.397

 

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