Jump to content

scramble code


Recommended Posts

this will be very difficult, i am trying to write a converter that will translate english into this code of mine. The "code" is simple. apple = aeplp, bascially you take first letter, cross it off, take last letter, cross it off, and then continue. Reading it is easy as well, start with the first letter, then read every other letter until you arrive at the last or second to last letter. Upon getting to this letter you read the one next to it that you havent read before (in aeplp. you arrive at p and then go to L.) then you continue to do the same thing going backwards.

Okay i understand that this sounds really retarded and that you all are probably busy but if any of you have some free time do you think you could figure it out? It is too advanced for my n00bish mind or i'd deal with it myself. Thanks in advance...

Link to comment
Share on other sites

Here's a transformation which scrambles the word. I leave a descrambler to you. A descrambler may be slightly harder, but you should be able to figure it out by studying this code.

Main()

Func Main()
    Local $s = "apple"
    Local $sExpected = "aeplp"
    
    Local $sResult = ConvertString($s)
    If $sResult <> $sExpected Then
        MsgBox(4096, "", "Failed: " & @CRLF & $sResult)
    Else
        MsgBox(4096, "", "Success: " & @CRLF & $sResult)
    EndIf
EndFunc

Func ConvertString($s)
    Local $sRes = ""
    Local $i = 0
    While StringLen($s)
        Local $index = 1
        $i = $i + 1
        If Not Mod($i, 2) Then $index = StringLen($s)
        $sRes = $sRes & ConsumeCharacter($s, $index)
    WEnd
    Return $sRes
EndFunc

; Eats a character from a string and returns the character
Func ConsumeCharacter(ByRef $s, $index)
    Local $sBegin, $sEnd, $cChar
    $cChar = StringMid($s, $index, 1)
    $sBegin = StringLeft($s, $index-1)
    $sEnd = StringRight($s, StringLen($s)-$index)
    $s = $sBegin & $sEnd
    Return $cChar
EndFunc
Link to comment
Share on other sites

im going insane, someone plz help, im so confused with this script!

<{POST_SNAPBACK}>

Here's a version I did a while ago. It scrambles a little differently because it starts with the last character, then the first, and so on.

;; For Testing
;$sOrig = "Apple"
$sOrig = "AutoIt3 is the best!"
$sScrambled = _Scramble($sOrig)
$sDeScrambled = _DeScramble($sScrambled)
MsgBox(4096, "test", "$sOrig = " & $sOrig &@LF& "$sScrambled = " & $sScrambled &@LF& "$sDeScrambled = " & $sDeScrambled)
Exit


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _Scramble($sText)
  ;; Scramble a text string.
   $iLen = StringLen($sText)
   $Scrambled = ""
   For $i1 = 1 To Int($iLen / 2)
      $Scrambled = $Scrambled & StringMid($sText, $iLen - $i1 + 1, 1) & StringMid($sText, $i1, 1)
   Next; $i1
  ; Pick up the odd character.
   If Mod($iLen, 2) Then
      $Scrambled = $Scrambled & StringMid($sText, $i1, 1)
   EndIf
   Return $Scrambled
EndFunc  ;==>_Scramble


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _DeScramble($sText)
  ;; De-Scramble a Scrambled text that was scrambled by _Scramble.
   Local $iLen = StringLen($sText)
   Local  $i, $DeScrambled1, $DeScrambled2
   $DeScrambled1 = ""
   $DeScrambled2 = ""
   For $i1 = 1 To $iLen step 2
      $DeScrambled1 = StringMid($sText, $i1, 1) & $DeScrambled1
      $DeScrambled2 = $DeScrambled2 & StringMid($sText, $i1 + 1, 1)
   Next; $i1
  ; Pick up the odd character.
   If Mod($iLen, 2) Then
      $DeScrambled1 = StringMid($sText, $i1, 1) & $DeScrambled1
   EndIf
   $sText = $DeScrambled2 & $DeScrambled1
   Return $DeScrambled2 & $DeScrambled1
EndFunc  ;==>_DeScramble

Phillip

Link to comment
Share on other sites

Regexp lib?

You mean RegExp function?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Where's that located?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Thanks, coulda sworn it was already in the core :lmao:

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
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...