Jump to content

Word Scrammbler


CodyBarrett
 Share

Recommended Posts

lol i made this while i was bored today... im STILL bored so i might as well make a GUI for it.. but later..

WHAT THIS DOES

it scrambles a word that is typed into the Input box.. and displays it in a Msgbox... although it reuses the letters.. :\ havent figured that out yet haha tell me what you think?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=ico.ico
#AutoIt3Wrapper_Res_Comment=Authored by : Bob
#AutoIt3Wrapper_Res_Description=Scambles and converts text
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <Misc.au3>
#include <String.au3>
#include <Array.au3>

FileInstall ('F:\DIGITAL LOGIC\Word scrammbler\GUI.bmp', @ScriptDir & '\GUI.bmp')
$Gui=GUICreate(@ScriptName, 400, 400, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUICtrlCreatePic(@ScriptDir & '\GUI.bmp', 0, 0, 400, 400)
GUICtrlSetState(-1, $GUI_DISABLE)

$Title=GUICtrlCreateLabel(@ScriptName, 50, 10, 300, 30, $SS_CENTER)
GUICtrlSetBkColor($Title, 0x1f1f1f)
GUICtrlSetColor($Title, 0xc8b77d)
GUICtrlSetFont($Title, 20, 300, 4, '')

$Exit=GUICtrlCreateLabel('x', 350, 10, 20, 20)
GUICtrlSetBkColor($Exit, 0x1f1f1f)
GUICtrlSetColor($Exit, 0xe8e8e8)
GUICtrlSetFont($Exit, '', 300, '', 'Arial Black')

$Min=GUICtrlCreateLabel('_', 20, 10, 20, 20)
GUICtrlSetBkColor($Min, 0x1f1f1f)
GUICtrlSetColor($Min, 0xe8e8e8)
GUICtrlSetFont($Min, '', 300, '', 'Arial Black')

$Help=GUICtrlCreateLabel('?', 40, 10, 20, 20)
GUICtrlSetBkColor($Help, 0x1f1f1f)
GUICtrlSetColor($Help, 0xe8e8e8)
GUICtrlSetFont($Help, '', 300, '', 'Arial Black')

$Input=GUICtrlCreateInput('Type word\phrase in here...', 50, 70, 300, 100, 5)
GUICtrlSetFont($Input, 10, 800, '', 'Lucida Console')
GUICtrlSetBkColor($Input, 0xe8e8e8)

$Output=GUICtrlCreateEdit('', 50, 220, 300, 100, 2103360)
GUICtrlSetFont($Output, 10, 800, '', 'Lucida Console')
GUICtrlSetBkColor($Output, 0xe8e8e8)

$bScammble=GUICtrlCreateButton('Scammble', 55, 180, 90, 30)
$bHEX=GUICtrlCreateButton('HEX it', 155, 180, 90, 30) 
$bBIN=GUICtrlCreateButton('BIN it', 255, 180, 90, 30)
$bBINCHR=GUICtrlCreateButton('BIN to Chr', 255, 330, 90, 30)
$bHEXCHR=GUICtrlCreateButton('HEX to Chr', 155, 330, 90, 30) 

GUICtrlSetState($bHEXCHR, $GUI_DISABLE)
GUICtrlSetState($bBINCHR, $GUI_DISABLE)
GUICtrlSetState($bHEX, $GUI_ENABLE)
GUICtrlSetState($bScammble, $GUI_ENABLE)
GUICtrlSetState($bBIN, $GUI_ENABLE)
GUISetState()

While 1
    $m=GUIGetMsg() 
    $a=GUICtrlRead($Input)
    If $m=$Help Then 
        MsgBox(32, '_____This is a Help Guide to WORD SCRAMMBLER._____', '' & _ 
                @CRLF & '<This is authored by Cody Barrett.>' & _
                @CRLF & @CRLF & 'The Controls are as follows :' & _
                @CRLF & '*To Exit Click on the "X" in the top right corner.' & _
                @CRLF & '*OR Alternately Press "ESC" while the window is active' & _
                @CRLF & '*To Minimize Click the "_" in the Top left corner.' & _
                @CRLF & @CRLF & 'The Steps to using it are:' & _
                @CRLF & '1. Firstly type in any phrase or word into the input box.' & _
                @CRLF & '2. Then Click "SCAMMBLE" and it will show the scrammbled string in the bottom box.' & _
                @CRLF & '3. Or Click "HEX it" and it will show the Hexadecimal string in the bottom box.' & _
                @CRLF & '4. And Click "HEX to Chr" and it will show the Chr string in the top box.' & _
                @CRLF & '5. Or Click "BIN it" and it will show the Binary string in the bottom box.' & _
                @CRLF & '6. And Click "BIN to Chr" and it will show the Chr string in the Top box.' & _
                '')
    EndIf
    If $m=$Min Then WinSetState($Gui, '', @SW_MINIMIZE)
    If $m=$Exit Or $m = $GUI_EVENT_CLOSE Then Exit
    If $m=$Title Then
        Do ;DO UNTIL loop
            $mgp=MouseGetPos()
            WinMove($Gui, '', $mgp[0], $mgp[1])
        Until Not _IsPressed('01')
    EndIf
    If $m=$bHEX Then 
        GUICtrlSetData($Output, '') 
        $string=GUICtrlRead($Input)
        $string=_StringToHex($string)
        GUICtrlSetData($Output, $string) 
        GUICtrlSetData($Input, '')
        GUICtrlSetState($bHEX, $GUI_DISABLE)
        GUICtrlSetState($bHEXCHR, $GUI_ENABLE)
        GUICtrlSetState($bScammble, $GUI_DISABLE)
        GUICtrlSetState($bBIN, $GUI_DISABLE)
        GUICtrlSetState($bBINCHR, $GUI_DISABLE)
        $string=''
    EndIf
    If $m=$bHEXCHR Then
        GUICtrlSetData($Input, '')
        $string=GUICtrlRead($Output)
        $string=_HexToString($string)
        GUICtrlSetData($Input, $string)
        GUICtrlSetData($Output, '')
        GUICtrlSetState($bHEXCHR, $GUI_DISABLE)
        GUICtrlSetState($bHEX, $GUI_ENABLE)
        GUICtrlSetState($bScammble, $GUI_ENABLE)
        GUICtrlSetState($bBIN, $GUI_ENABLE)
        $string=''
    EndIf
    If $m=$bBIN Then 
        GUICtrlSetData($Output, '')
        $string=''
        $a=StringSplit($a, '') 
        For $i=1 To $a[0] 
            $Asc=Asc($a[$i]) 
            If $Asc<>32 Then 
                $oBin=''
                For $iii=7 To 0 Step -1 
                    If $Asc>=2^$iii Then
                        $Asc-=2^$iii 
                        $oBin&=1 
                    Else
                        $oBin&=0
                    EndIf
                Next
                GUICtrlSetData($Output, GUICtrlRead($Output) & ' ' & $oBin) 
            Else
                GUICtrlSetData($Output, GUICtrlRead($Output) & ' -') 
            EndIf
        Next
        GUICtrlSetData($Input, '')
        GUICtrlSetState($bBIN, $GUI_DISABLE)
        GUICtrlSetState($bScammble, $GUI_DISABLE)
        GUICtrlSetState($bHEX, $GUI_DISABLE)
        GUICtrlSetState($bBINCHR, $GUI_ENABLE)
    EndIf
    If $m=$bBINCHR Then 
        $string='' 
        $Asc=''
        $a=GUICtrlRead ($Output)
        $a=StringSplit($a, '-') 
        For $i=1 To $a[0] 
            If StringLeft ($a[$i],1)=' ' Then $a[$i]=StringTrimLeft ($a[$i], 1)
            If StringRight ($a[$i],1)=' ' Then $a[$i]=StringTrimRight($a[$i], 1)
            $b=StringSplit ($a[$i], ' ')
            For $ii=1 To $b[0] 
                $Asc=0 
                For $iii=0 To 7 
                    If StringMid ($b[$ii], 8-$iii, 1)=1 Then $Asc+=2^$iii 
                Next
                $l=Chr ($Asc)
                $string&=$l
                $l=''
            Next
        Next
        GUICtrlSetData ($Input ,$string)
        GUICtrlSetData ($Output , '')
        GUICtrlSetState($bHEX, $GUI_ENABLE)
        GUICtrlSetState($bBIN, $GUI_ENABLE)
        GUICtrlSetState($bScammble, $GUI_ENABLE)
        GUICtrlSetState($bBINCHR, $GUI_DISABLE)
    EndIf
    If $m=$bScammble Then 
        GUICtrlSetData($Output, '')
        $string=''
        $a=StringSplit($a, '')
        For $i=1 To $a[0]
            Do
                $r=Random(1, $a[0], 1) 
            Until StringLen($a[$r]) > 0
            $string&=$a[$r]
            $a[$r]=''
        Next
        GUICtrlSetData($Output, $string, '')
        $string=''
        $a[0]=''
    EndIf
WEnd
Edited by CodyBarrett
Link to comment
Share on other sites

Wasn't someone looking for this a while back?

very nice, but a few things:

use params and return instead of input and msgbox.

spell choiCe correctly (not choise)

"... although it reuses the letters.." isn't that what a word scrambler does?

other than that, I can see little wrong with it!

MDiesel

Oh, one more thing on your to-do list: Get a life and stop being bored.

Link to comment
Share on other sites

Scrambler that uses each letter once

Dim $string
Main ()
Func Main ()
    $a=InputBox ('Word Scrammbler', 'Please type in a word of your choice.')
    If Not @error Then
        $a=StringSplit ($a, '')
        For $i=1 To $a[0]
            Do
                $r=Random (1, $a[0],1)
;~              MsgBox(0,"",$r)
            Until StringLen($a[$r]) > 0
            $string&=$a[$r]
            $a[$r] = ""
        Next
        MsgBox (0, '', $string)
$string = ""
        If @error Then
            Exit
        Else
            Main ()
        EndIf
    EndIf
EndFunc

Edit: forgot to clear the $string variable

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

hey thank you ^_^ now ill add that & a GUI to it haha..

Link to comment
Share on other sites

Link to comment
Share on other sites

im a little bored too!

Dim $string

choice()


Func Scramble()
    $a=InputBox ('Word Scrammbler', 'Please type in a word of your choice.')
    $desc = $a
    If Not @error Then
        $a=StringSplit ($a, '')
        For $i=1 To $a[0]
            Do
                $r=Random (1, $a[0],1)

            Until StringLen($a[$r]) > 0
            $string&=$a[$r]
            $a[$r] = ""
        Next
    $desco = $string
        IniWrite(@ScriptDir & "\decrip",$desco, "key", $desc)
        MsgBox (0, '', $string)
$string = ""
        If @error Then
            Exit
        Else
            choice()
        EndIf
    EndIf
EndFunc

Func Unscramble()
    $a=InputBox ('Word De-Scrammbler', 'Please type in scrambled word.')
    $var = IniReadSection(@ScriptDir & "\decrip",$a)
If @error Then 
    MsgBox(4096, "", "Scrambled word not reconized")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", $var[$i][1])
    Next
EndIf
EndFunc

Func choice()
    $m1 = MsgBox(3,"Scamble/Unscramble words","Would you like to scramble? if No Unscrambles or else cancel.") 
if $m1 = 6 Then
    scramble()
elseif $m1 = 7 Then
    Unscramble()
Else
    Exit
EndIf
EndFunc
[Cheeky]Comment[/Cheeky]
Link to comment
Share on other sites

What I would have done:

MsgBox (48, "Results", Scramble ("AutoIt"))

Func Scramble ($Word)
   Local $String, $r, $i

   $Word = StringSplit ($Word, '')
   For $i = 1 To $Word[0]
      Do
         $r = Random (1, $Word[0], 1)
      Until StringLen ($Word[$r]) > 0
      $string &= $Word[$r]
   Next
   Return $string

EndFunc; ==> Scramble

I am working on a better one that reuses letters only once.... Right now its using a very bad method (It writes info to a file, reads a random line, and deletes it afterwards.)...

its not working out to well, anyone want to improve it and continue that idea, feel free to pm me and I'll send you what I've got so far...

Link to comment
Share on other sites

Still bored?. Then here's an idea for making the script better ^_^

Olny srmat poelpe can raed tihs.

I cdnuolt blveiee taht I cluod aulaclty uesdnatnrd waht I was rdanieg. The phaonmneal pweor of the hmuan mnid, aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, t he olny iprmoatnt tihng is taht the frist and lsat ltteer be in the rgh it pclae. The rset can be a taotl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Amzanig huh? yaeh and I awlyas tghuhot slpeling was ipmorantt! if you can raed tihs psas it on !!"

Link to comment
Share on other sites

Still bored?. Then here's an idea for making the script better

QUOTE

Olny srmat poelpe can raed tihs.

I cdnuolt blveiee taht I cluod aulaclty uesdnatnrd waht I was rdanieg. The phaonmneal pweor of the hmuan mnid, aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, t he olny iprmoatnt tihng is taht the frist and lsat ltteer be in the rgh it pclae. The rset can be a taotl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Amzanig huh? yaeh and I awlyas tghuhot slpeling was ipmorantt! if you can raed tihs psas it on !!"

well this could be done by stringsplit ($abovestring, ' ', 1) to split the words up between the spaces... but you would have to use a dictionary reference to REassemble the words... scrammbleing them is onething.. reassembling is another

Link to comment
Share on other sites

Still bored?. Then here's an idea for making the script better ^_^

Here's a really quick stab at it,

Probably not the best way, but it gets the job done. (Doesn't handle "." and such)

$text = "Only smart people can read this"
msgbox(-1,"test",_Scramble($text))

Func _Scramble($text)
    $sentence = ""
    $splitSentence = StringSplit($text," ")
    For $n = 1 to $splitSentence[0]
        If StringLen($splitSentence[$n]) > 3 Then
            $wordbuff = $splitSentence[$n]
            $splitWord = StringSplit($splitSentence[$n],"")
            For $o = 2 to $splitWord[0]-1
                $random = Random(2,$splitWord[0]-1,1)
                $buff = $splitWord[$o]
                $splitWord[$o] = $splitWord[$random]
                $splitWord[$random] = $buff
                $word = ""
                For $p = 1 to $splitWord[0]
                    $word &= $splitWord[$p]
                Next
            Next
            If $wordbuff = $word Then
                $n -= 1
            Else
                $sentence &= $word & " "
            EndIf
        Else
            $sentence &= $splitSentence[$n] & " "
        EndIf
    Next
    return $sentence
EndFunc
Link to comment
Share on other sites

Added punctuation

$text = "In theory, only smart people can read this."
MsgBox(-1, "test", _Scramble($text))

Func _Scramble($text)
    $sentence = ""
    $splitSentence = StringSplit($text, " ")
    For $n = 1 To $splitSentence[0]
        $Punctuation = ""
        If StringInStr($splitSentence[$n], ".") Then $Punctuation = "."
        If StringInStr($splitSentence[$n], ",") Then $Punctuation = ","
        If $Punctuation <> "" Then $splitSentence[$n] = StringTrimRight($splitSentence[$n], 1)

        If StringLen($splitSentence[$n]) > 3 Then
            $wordbuff = $splitSentence[$n]
            $splitWord = StringSplit($splitSentence[$n], "")
            For $o = 2 To $splitWord[0] - 1
                $random = Random(2, $splitWord[0] - 1, 1)
                $buff = $splitWord[$o]
                $splitWord[$o] = $splitWord[$random]
                $splitWord[$random] = $buff
                $word = ""
                For $p = 1 To $splitWord[0]
                    $word &= $splitWord[$p]
                Next
            Next
            If $wordbuff = $word Then
                $n -= 1
            Else
                $sentence &= $word & $Punctuation & " "
            EndIf
        Else
            $sentence &= $splitSentence[$n] & $Punctuation & " "
        EndIf
    Next
    Return $sentence
EndFunc   ;==>_Scramble

8)

NEWHeader1.png

Link to comment
Share on other sites

Must be that time of year when people are getting bored ^_^

Here's an example that can scramble and unscramble. You need to provide a random seed though. I'm using the result of GetTickCount().

_Main()

Exit

Func _Main()
    Local $sWord = InputBox("Scramble", "Enter the word to scramble", ""), $i
    If StringLen($sWord) > 1 Then
        Local $sTest = $sWord, $iSeed
        For $i = 1 To 10
            $iSeed = DllCall("kernel32.dll", "dword", "GetTickCount")
            $sWord = _ScrambleWord($sWord, $iSeed[0])
            If $sWord <> $sTest Then ExitLoop
        Next
        MsgBox(64, "Scrambled", $sWord, 5)
        $sWord = _UnscrambleWord($sWord, $iSeed[0])
        MsgBox(64, "Unscrambled", $sWord, 5)
    EndIf
EndFunc

Func _ScrambleWord($sWord, $iSeed)
    If StringLen($sWord) < 2 Then Return $sWord
    Local $aSeq = _GetSequence(StringLen($sWord), $iSeed), $i, $sRet = ""
    For $i = 1 To StringLen($sWord)
        $sRet &= StringMid($sWord, $aSeq[$i], 1)
    Next
    Return $sRet
EndFunc

Func _UnscrambleWord($sWord, $iSeed)
    If StringLen($sWord) < 2 Then Return $sWord
    Local $aSeq = _GetSequence(StringLen($sWord), $iSeed), $i, $sRet = "", $aUns[StringLen($sWord) + 1]
    For $i = 1 To StringLen($sWord)
        $aUns[$aSeq[$i]] = StringMid($sWord, $i, 1)
    Next
    For $i = 1 To StringLen($sWord)
        $sRet &= $aUns[$i]
    Next
    Return $sRet
EndFunc

Func _GetSequence($iLength, $iSeed)
    Local $aRet[$iLength + 1], $i, $j, $k
    $aRet[0] = $iLength
    For $i = 1 To $iLength
        $aRet[$i] = $i
    Next
    SRandom($iSeed)
    For $i = 1 To $iLength
        $j = Random(1, $iLength, 1)
        $k = $aRet[$j]
        $aRet[$j] = $aRet[$i]
        $aRet[$i] = $k
    Next
    Return $aRet
EndFunc

WBD

Link to comment
Share on other sites

This seems a one-loop, once-per-letter, scramble:

MsgBox (48, "Results", Scramble ("ABCDEF"))

Func Scramble ($Word)
   Local $string, $r, $i
   $Word = StringSplit ($Word, '')
    For $i= $Word[0] to 1 Step -1
        $r = Random(0, $i - 1) + 1
        $string &= $Word[$r]
        $Word[$r] = $Word[$i]
    Next
    Return $string
EndFunc; ==> Scramble

Edit: Or:

MsgBox (48, "Results", Scramble2("In theory, only smart people can read this."))
Func Scramble2($stringin)
   Local $word, $stringout, $r, $i, $j
    $Sentence = StringSplit ($stringin, ',. ')
    For $h= 1 to $Sentence[0]
        $Word = StringSplit($Sentence[$h], '')
        $j += $word[0] + 1
        For $i= $Word[0] to 1 Step -1
            $r = Random(0, $i - 1) + 1
            $stringout &= $Word[$r]
            $Word[$r] = $Word[$i]
        Next
        $stringout &= StringMid($stringin, $j, 1)
    Next
    Return $stringout
EndFunc; ==> Scramble
Edited by Spiff59
Link to comment
Share on other sites

wow valuater love the punctuation!

EDIT!

Technically in order for it to work it the first and last letters must remain the same. Maybe uses the Lefttrim, RightTrim ’s and reapply them after?

Edited by lordicast
[Cheeky]Comment[/Cheeky]
Link to comment
Share on other sites

His keeps the first and last letters.

I made it say this

If yuor gnoig to say "In teorhy, olny sarmt poelpe can raed tsih.. Tehn you slhuod mkae it a ltlite mroe ducfiilft to raed wtih lenogr wagdore to cofsnue the coommn iidot

After pasting this I see it has an error valuater, the tsih.. should be tsih." In my script it is this."

Giggity

Link to comment
Share on other sites

Oh I get it! First AND last?

That doesn't allow for much scrambling with these tiny words...

MsgBox (48, "Results", Scramble2("In theory, only smart people could possibly read this."))
Func Scramble2($stringin)
   Local $word, $stringout, $r, $i, $j
    $Sentence = StringSplit ($stringin, '!?-,. ')
    For $h= 1 to $Sentence[0]
        $Word = StringSplit($Sentence[$h], '')
        $j += $word[0] + 1
        If $word[0] Then $stringout &= $Word[1]             
        For $i= $Word[0] -1 to 2 Step -1
            $r = Random(0, $i - 2) + 2
            $stringout &= $Word[$r]
            $Word[$r] = $Word[$i]
        Next
        If $word[0] Then $stringout &= $Word[$word[0]]              
        $stringout &= StringMid($stringin, $j, 1)
    Next
    Return $stringout
EndFunc; ==>

Edit: added a couple more common punct chars to stringsplit

Edited by Spiff59
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...