Sign in to follow this  
Followers 0
MyEarth

Primitive easy cipher

7 posts in this topic

I'd like to make an easy number cipher, pratically just add N number to the final result

My attempt:

$sReturn = ""
$sText = "0123456789"
$nPos = 3
$aSplit = StringSplit($sText, "")
For $i = 0 To UBound($aSplit) - 1
    Select
        Case Number($aSplit[$i]) < 7
            $sReturn &= $aSplit[$i] + $nPos
        Case Number($aSplit[$i]) = 7
            $sReturn &= 0
        Case Number($aSplit[$i]) = 8
            $sReturn &= 1
        Case Number($aSplit[$i]) = 9
            $sReturn &= 2
    EndSelect
Next
ConsoleWrite($sReturn & @CRLF)

I don't know how to make the number start from zero if is bigger the 9, i can't make the case like the example because work only if $nPos = 3
Thanks

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Ok

I want to add a number to another number, in the example the position are three, but is a variable and this value can change so:

0 = 3 (0+3)

1 = 4 (1+3)

2 = 5 (2+3)

But when it come the 7

7 = 10 (7+3)

Is wrong, the number are only ten and the max value is 9, so need to start from zero:

7 = 0

8 = 1

9 = 2

So explected string is, if the position to move are three:

0123456789 = 3456789012

Is clear?

Oh, i need to reverse the process too :D

Edited by MyEarth

Share this post


Link to post
Share on other sites

using Mod() could do

$sReturn = ""
$sText = "0123456789"
$nPos = 3
$aSplit = StringSplit($sText, "", 2)
For $i = 0 To UBound($aSplit) - 1
    $sReturn &= Mod($aSplit[$i] + $nPos, 10)
Next
ConsoleWrite($sReturn & @CRLF)

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Thanks :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Wait, and for reverse the process:huh:

Come back from 3456789012 To 0123456789

Edited by MyEarth

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Wait, and for reverse the process:huh:

Come back from 3456789012 To 0123456789

:ermm:

this could do ...

$sReturn = ""
$sText = "0123456789"
$nPos = 3
$max = 10 ; (0-9)
;
; forth
$aSplit = StringSplit($sText, "", 2)
For $i = 0 To UBound($aSplit) - 1
    $sReturn &= Mod($aSplit[$i] + $nPos, $max)
Next
ConsoleWrite($sReturn & @CRLF)
;
; and back
$aSplit = StringSplit($sReturn, "", 2)
$sReturn = ""
For $i = 0 To UBound($aSplit) - 1
    $sReturn &= Mod($aSplit[$i] - $nPos + ($max * ($aSplit[$i] < $nPos)), $max)
Next
ConsoleWrite($sReturn & @CRLF)

;)

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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