haggard Posted April 24, 2011 Share Posted April 24, 2011 Hello, I am trying to find method to change parts of string on set before numbers. For example, I've string like: oOc2sX and i wanna change it for set before: "o" = 10 "O" = 20 "c" = 5 "s" = 8 "X" = 18 Maybe the best way is to put numbers for selected letters to the array? But i am not sure how to do that and later use to change this string. Would you like to help me? Thanks Link to comment Share on other sites More sharing options...
Damein Posted April 24, 2011 Share Posted April 24, 2011 Is it a certain string of letters or do you want every letter to have a numerical value? And do you want specific letters to have specific values? IE: Can a = 1 and A = 2 or do you want it to be something different? Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
haggard Posted April 24, 2011 Author Share Posted April 24, 2011 Every letter have numerical value, like you said: a - 0, A - 1, b - 2, B - 3, etc. Link to comment Share on other sites More sharing options...
wakillon Posted April 24, 2011 Share Posted April 24, 2011 Try ConsoleWrite ( _StringReplace ( "oOc2sX" ) & @CRLF) Func _StringReplace ( $sString ) Local $Pattern[5][2] = [["[o]", 10], ["[O]", 20], ["[c]", 5], ["[s]", 8], ["[X]", 18]] For $i = 0 To 4 $sString = StringRegExpReplace ( $sString, $Pattern[$i][0], $Pattern[$i][1] ) Next Return $sString EndFunc AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
SalehSouqi Posted April 24, 2011 Share Posted April 24, 2011 (edited) never mind Edited April 24, 2011 by SalehSouqi Link to comment Share on other sites More sharing options...
Developers Jos Posted April 24, 2011 Developers Share Posted April 24, 2011 Translating this back is going to be "fun". 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 More sharing options...
Damein Posted April 24, 2011 Share Posted April 24, 2011 (edited) *** EDIT *** Didn't know Al-Mighty Wakillon posted! This is probably a really confusing way to do it, but it may work. #include <Array.au3> Global $LowerCase[130], $UpperCase[91], $Number[7000], $Number2[7000], $Count For $i = 97 To 122 $LowerCase[$i] = Chr($i) Next For $i = 65 To 90 $UpperCase[$i] = Chr($i) Next For $i = 97 To 122 $Count += 1 $Number[$Count] = Asc($LowerCase[$i]) Next $Count = 0 For $i = 65 To 90 $Count += 1 $Number2[$Count] = Asc($UpperCase[$i]) Next So the Array $Number holds all the lowercase numerical values. 1-26 has a range of 97-122 and $Number2 holds the uppercase numerical values of 65-90 Edited April 24, 2011 by Damein Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
GEOSoft Posted April 24, 2011 Share Posted April 24, 2011 Like Jos pointed out, trying to convert it back could be a problem. This should solve that for you because each letter in the string would be replaced by 3 numeric characters. $sStr = "This is Some Test string." For $i = 62 to 122 $sStr = StringReplace($sStr, Chr($i), StringFormat("%03u",$i)) Next MsgBox(0, "TEST", $sStr) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Rogue5099 Posted April 24, 2011 Share Posted April 24, 2011 (edited) Try this out, if encrypt goes over 254 charactors you can't use inputbox you could use GUICtrlCreateEdit though: expandcollapse popupGlobal $LowerCase[130], $UpperCase[91], $Number[7000], $Number2[7000], $Count $Message = InputBox("Test", "Enter Message to Encrypt") For $i = 97 To 122 $LowerCase[$i] = Chr($i) If StringInStr($Message, $LowerCase[$i]) Then $Message = StringReplace($Message, $LowerCase[$i], StringFormat("%03u",$i) & ":", 0, 1) EndIf Next For $i = 65 To 90 $UpperCase[$i] = Chr($i) If StringInStr($Message, $UpperCase[$i]) Then $Message = StringReplace($Message, $UpperCase[$i], StringFormat("%03u",$i) & ":", 0, 1) EndIf Next $Message = StringToBinary($Message) MsgBox(0, "Encrypted", $Message) $Message = BinaryToString($Message) For $i = 97 To 122 $LowerCase[$i] = StringFormat("%03u", $i) If StringInStr($Message, $LowerCase[$i] & ":") Then $Message = StringReplace($Message, $LowerCase[$i] & ":", Chr($i), 0, 1) EndIf Next For $i = 65 To 90 $UpperCase[$i] = StringFormat("%03u", $i) If StringInStr($Message, $UpperCase[$i] & ":") Then $Message = StringReplace($Message, $UpperCase[$i] & ":", Chr($i), 0, 1) EndIf Next MsgBox(0, "Decrypted", $Message) Edited April 24, 2011 by rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
GEOSoft Posted April 28, 2011 Share Posted April 28, 2011 I know this thread is getting old but I just had another though about how to handle it and still be able to reverse the process easily. If there is no explicit reason why you have to use numbers then just use the Binary equivalent. It could then be recovered using a Regular Expression with the xdigit class. $sStr = "This is Some Test string." $bStr = StringMid(Binary($sStr), 3) MsgBox(0, "Result", $bStr) The expression to recover the original would be "([[:xdigit:]]{2})" George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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