Jump to content

Primitive easy cipher


Recommended Posts

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

Link to comment
Share on other sites

Please explain a bit more "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"

and exact goal of script.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...