Jump to content
nooneclose

[SOLVED] How to tell Autoit that "A" is different than "a"

Recommended Posts

I am sure you guys know of a simple solution but I am still kind of new to AutoIt and its special functions. I want my code to be able to know how to encrypt and decrypt "A" and "a" as two different chars.

my code is very long so here is just a snippet/example of it.  

;Encode==
Global $charAA   = "" ; ( Capital letter A )   = Global 184 = ¸    ( Cedilla )
           $charAA   = $charAA & Chr(65)           
Global $chara    = "" ; ( Lowercase letter a ) = Global 251 = û    ( û Latin Small Letter U With Circumflex )
           $chara    = $chara & Chr(97)
           
;Decode==  
Global $ch184 = ""          ;( Copyright symbol ) = $charAA
           $ch184 = $ch184 & Chr(184)          
Global $ch251 = ""          ;( û Latin Small Letter U With Circumflex ) = $chara
           $ch251 = $ch251 & Chr(251)

;Encode==          
stringreplace($test_String, $charAA, $ch184)
stringreplace($test_String, $chara,  $ch251)

;Decode==
stringreplace($$new_String, $ch184, $charAA)
stringreplace($$new_String, $ch251, $chara)

NOTE: my stringreplace function is nested in my actual code. I only separated them here for readability. )


I know there are better ways to Encrypt and Decrypt a message but I'm doing this as a fun side project for me and a select group of friends to enjoy. 

Again My code is not encrypting or decrypting capitals and lower case properly even though I use their ANSI codes. 

 

Example: Input "A a B b"  Encrypt: ". . $ $"  Decrypt: "A A B B"

Any and all help will be greatly appreciated.  

Edited by nooneclose

Share this post


Link to post
Share on other sites

You should set StringReplace's optional parameter casesense=1 (default=0: case-insensitive), see Help

Share this post


Link to post
Share on other sites

@RTFC Thank you for replying to my post in a timely manner. Can you show me an example of how that might look in a nested stringreplace function? 

stringreplace(stringreplace(stringreplace($test_String, $charAA, $ch184), $chara,  $ch251), $charBB, $char195, $STR_CASESENSE = 1)

Would I place the $STR_CASESENSE = 1 at the end like the example above? or at the end of each nested section? 

Share this post


Link to post
Share on other sites

You are using the parameter the wrong way: Just 1, not $str_casesense=1


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It appears you need to understand the AutoIt help file.
Look up the StringReplace function in the AutoIt help file.  (Cursor over StringReplace in SciTE and press F1 key)

See "StringReplace ( "string", "searchstring/start", "replacestring" [, occurrence = 0 [, casesense = 0]] )

Note: the square barackets around the two last optional parameters, each show their default values of zero.  
When the 5th parameter, casesense, needs to be 1, the 0ptional 4th parameter will be need to be in place in order to identify the 5th parameter.
In the include file "StringConstants.au3" you will find the variable, "$STR_CASESENSE" equal to 1. So, the 5th parameter can be "$STR_CASESENSE" or "1", they are the same value.

Also note:-
Return Value
Returns the new string .... 

#include <StringConstants.au3>

 ; Variable $Encode contains the new string
$Encode = StringReplace(StringReplace(StringReplace($test_String, $charAA, $ch184, 0, $STR_CASESENSE), $chara, $ch251, 0, $STR_CASESENSE), $charBB, $char195, 0, $STR_CASESENSE)

 

Share this post


Link to post
Share on other sites

@water @Malkey Thank you both very much for your help and thank you again @Malkey for your detailed explanation that really helped me to get the code to work right. Sadly, I do have to add the 0, 1) at the end of each nested line but this is a small price to pay for working code.

 

Example of final working code:

stringreplace(stringreplace(stringreplace($test_String, $charAA, $ch184, 0, 1), $chara,  $ch251, 0, 1), $charBB, $char195, 0, 1)

   

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

  • Similar Content

    • By TheXman
      Encryption / Decryption / Hashing
      Purpose
      Cryptography API: Next Generation (CNG) is Microsoft's long-term replacement for their CryptoAPI.  CNG is designed to be extensible at many levels and cryptography agnostic in behavior.  Although the Crypt.au3 UDF that is installed with AutoIt3 still works perfectly, the advapi32.dll functions that it uses have been deprecated.  This UDF was created to offer a replacement for the deprecated functions.  According to Microsoft, deprecated functions may be removed in future release.  Therefore, this UDF will be available when/if that happens.
      Description
      This UDF implements some of Microsoft's Cryptography API: Next Generation (CNG) Win32 API functions.  In its initial release, it implements functions to encrypt text & files, decrypt text and files, generate hashes, and the Password-Based Key Derivation Function 2 (PBKDF2) function.  The UDF can implement any the encryption/decryption algorithms or hashing algorithms that are installed on the PC in which it is running.  Most, if not all, of the values that you would commonly use to specify that desired algorithms, key bit lengths, and other magic number type values, are already defined as constants or enums in the UDF file.
      To flatten the learning curve, there is an example file that shows examples of all of the major functionality.  This example file is not created to be an exhaustive set of how to implement each feature and parameter.  It is designed to give you a template or guide to help you hit the ground running in terms of using the functions.  I have tried to fully document the headers of all of the functions as well as the code within the functions themselves.
      The UDF currently has all of the same functionality as the Crypt.au3 except for the random number generation function.  I left that out of the initial version because the functionality already exists in the Crypt.au3 UDF as well as the Random() function in AutoIt3 itself.
      Current UDF Functions
      _CryptoNG_DecryptData($sAlgorithmId, $xData, $vEncryptionKey, $sProvider = "Microsoft Primitve Provider") _CryptoNG_DecryptFile($sAlgorithmId, $sInputFile, $sOutputFile, $vEncryptionKey, $sProvider = "Microsoft Primitve Provider") _CryptoNG_EncryptData($sAlgorithmId, $sText, $vEncryptionKey, $sProvider = "Microsoft Primitve Provider") _CryptoNG_EncryptFile($sAlgorithmId, $sInputFile, $sOutputFile, $vEncryptionKe, $sProvider = "Microsoft Primitve Provider") _CryptoNG_EnumAlgorithms($iAlgorithmOperations) _CryptoNG_EnumRegisteredProviders() _CryptoNG_HashData($sAlgorithmId, $vData, $bHMAC = False, $vHMACSecret = "", $sProvider = "Microsoft Primitve Provider") _CryptoNG_HashFile($sAlgorithmId, $sFilePath, $bHMAC = False, $vHMACSecret = "", $sProvider = "Microsoft Primitve Provider") _CryptoNG_LastErrorMessage() _CryptoNG_PBKDF2($sPassword, $vSalt, $iIterations, $iDKeyBitLength, $sHashAlgorithmId = $CNG_BCRYPT_SHA1_ALGORITHM, $sProvider = "Microsoft Primitve Provider")  
       
      Related Links
      Cryptography API: Next Generation - Main Page
      Cryptography API: Next Generation - Reference
      Cryptography API: Next Generation - Primitives
      Cryptography API: Next Generation - Cryptographic Algorithm Providers
    • By SC0U7
      Hello i have a text file which contain over 600KB of BASE64 strings like :
      TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
      Now what i need is divide this long string as autoit variable each max lenght (4000characters per line) example:
      Local $var
      $var &=  TVqQAAMAAAAEAAA..
      $var &=  VbAmejwqqqAACEE..
      and then how to i add encrypt function on every line ? how to i can xor it? example final will be :
      $var &=  XorEnc(TVqQAAMAAAAEAAA..)
      $var &=  XorEncVbAmejwqqqAACEE..)
       
      Thanks for any help and ideas 
    • By FMS
      Hello,
      I think this is a simple question if you know the answer.
      At this function i try to  (encrypt -> decrypt -> change -> encrypt ->decrypt->check ) an array.
      This is a snippet from a larger script but the error is the same.
      I do this encrypt decrypt action so i can save some setting along the way in a file.
      But at the end (when i change the data and not when i dont change the data) is empty.
      does somebody see what i'm doing wrong here?
       
      Func test() Local $LC_timestamp = @MDAY & "." & @MON & "." & @YEAR & "_" & @HOUR & ":" & @MIN & ":" & @SEC Global $GL_USS_base_count = 4 Global $GL_USS_base[$GL_USS_base_count][2] = [["nickname", "FMS"], ["last_login", $LC_timestamp], ["login_count", "1" ], ["naam3", $LC_timestamp]] Global $encrypted_GL_USS_true[$GL_USS_base_count] Global $encrypted_GL_USS_content_true[$GL_USS_base_count] Global $GL_array_decrypted_USS_names[$GL_USS_base_count] Global $GL_array_decrypted_USS_settings[$GL_USS_base_count] MsgBox($MB_SYSTEMMODAL, "should be 1", $GL_USS_base[2][1]) ;make for $i = 0 to $GL_USS_base_count -1 $encrypted_GL_USS_true[$i] = _Crypt_EncryptData($GL_USS_base[$i][0], $GL_encr_key_settings, $CALG_AES_128) $encrypted_GL_USS_content_true[$i] = _Crypt_EncryptData($GL_USS_base[$i][1], $GL_encr_key_settings, $CALG_AES_128) Next ;get for $i = 0 to $GL_USS_base_count -1 $GL_array_decrypted_USS_names[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) $GL_array_decrypted_USS_settings[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_content_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) Next MsgBox($MB_SYSTEMMODAL, "should be 1", $GL_array_decrypted_USS_settings[2]) ;change $GL_array_decrypted_USS_settings[2] = $GL_array_decrypted_USS_settings[2] + "1" MsgBox($MB_SYSTEMMODAL, "should be 2", $GL_array_decrypted_USS_settings[2]) ;save for $i = 0 to $GL_USS_base_count -1 $encrypted_GL_USS_true[$i] = _Crypt_EncryptData($GL_array_decrypted_USS_names[$i], $GL_encr_key_settings, $CALG_AES_128) $encrypted_GL_USS_content_true[$i] = _Crypt_EncryptData($GL_array_decrypted_USS_settings[$i], $GL_encr_key_settings, $CALG_AES_128) Next ;get for $i = 0 to $GL_USS_base_count -1 $GL_array_decrypted_USS_names[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) $GL_array_decrypted_USS_settings[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_content_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) Next ;check MsgBox($MB_SYSTEMMODAL, "should be 2", $GL_array_decrypted_USS_settings[2]) ;why is this emty????? EndFunc thanks in advanced
×
×
  • Create New...