Jump to content

Recommended Posts

Posted (edited)

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
Posted

@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? 

Posted

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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)

 

Posted

@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)

   

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
×
×
  • Create New...