Sign in to follow this  
Followers 0
haggard

Changing letters to numbers from one string

10 posts in this topic

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

Share this post


Link to post
Share on other sites



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?


MCR.jpg?t=1286371579

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

Share this post


Link to post
Share on other sites

Every letter have numerical value, like you said: a - 0, A - 1, b - 2, B - 3, etc.

Share this post


Link to post
Share on other sites

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.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

never mind :unsure:

Edited by SalehSouqi

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Damein

MCR.jpg?t=1286371579

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

Share this post


Link to post
Share on other sites

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!"

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Try this out, if encrypt goes over 254 charactors you can't use inputbox you could use GUICtrlCreateEdit though:

Global $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 by rogue5099

Share this post


Link to post
Share on other sites

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!"

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
Sign in to follow this  
Followers 0