Jump to content

Descramble Code


glasglow
 Share

Recommended Posts

I guess if you have a massive list of words, and need speed, you could use StringLen to split up your dictionary into smaller files. Something similar to this:

#include<array.au3>
#include<file.au3>
#include <GUIConstants.au3>
#include <ButtonConstants.au3>

Global $Array_Max[4] = [1000,1500,1000,1000], $Array_Increment = 100
Global $Words_1234[$Array_Max[0]][2], $Words_56[$Array_Max[1]][2], $Words_78[$Array_Max[2]][2], $Words_Over8[$Array_Max[3]][2]
Global $Idx[4], $Words_Idx, $i, $word, $str
GUICreate("Input the Scrambled Word", 320,120, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018); WS_EX_ACCEPTFILES
$input = GUICtrlCreateInput("", 10,  5, 300, 20)
$output = GUICtrlCreateLabel( "", 10,  40, 300, 20)
$btn = GUICtrlCreateButton("Ok", 40,  75, 60, 20, $BS_DEFPUSHBUTTON)
GUISetState () 

Process_Dictionary()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $btn
            $word = GUICtrlRead($input)
            $i = StringSplit($word,"", 2)
            _ArraySort($i)
            $word = _ArrayToString($i,"")
            Switch StringLen($word)
                Case 1,2,3,4
                    $Words_Temp = $Words_1234
                    $Words_Idx = $Idx[0]
                Case 5,6
                    $Words_Temp = $Words_56
                    $Words_Idx = $Idx[1]
                Case 7,8
                    $Words_Temp = $Words_78
                    $Words_Idx = $Idx[2]
                Case Else
                    $Words_Temp = $Words_Over8
                    $Words_Idx = $Idx[3]
            EndSwitch
            $i = _ArraySearch($Words_Temp, $word, 0, 0, 0, 0, 1, 1)
            If @error Then
                GUICtrlSetData($output,"<not found>")
            Else        
                $str = $Words_Temp[$i][0]
                While $i < $Words_Idx
                    $i = _ArraySearch($Words_Temp, $word, $i + 1, 0, 0, 0, 1, 1)
                    If @error Then ExitLoop
                    If $Words_Temp[$i][1] = $word Then
                        $str &= ", " & $Words_Temp[$i][0]
                    Else
                        ExitLoop
                    EndIf
                Wend
                GUICtrlSetData($output, $str)
            EndIf
        Case $GUI_EVENT_CLOSE   
            ExitLoop
    EndSwitch
WEnd
Exit

;-------------------------------------------------------------------------------
Func Process_Dictionary()
    GUICtrlSetState($input, $GUI_DISABLE)
    GUICtrlSetData($output,"Loading dictionary...")
    GuiCtrlSetColor($output, 0xFF0000); red

    $file_in = FileOpen('dictionary.txt', 0)
    If $file_in = -1 Then
        MsgBox(0, "Error", "Dictionary file not found")
        Exit
    EndIf
    While 1
        $word = FileReadLine($file_in)
        If @error = -1 Then ExitLoop
        $i = StringSplit($word,"", 2)
        _ArraySort($i)
;       ToolTip($Idx[0] & "  " & $Idx[1] & "  " & $Idx[2] & "  " & $Idx[3])
        Switch StringLen($word)
            Case 1,2,3,4
                $Words_1234[$Idx[0]][0] = $word
                $Words_1234[$Idx[0]][1] = _ArrayToString($i,"")
                $Idx[0] += 1
            Case 5,6
                $Words_56[$Idx[1]][0] = $word
                $Words_56[$Idx[1]][1] = _ArrayToString($i,"")
                $Idx[1] += 1
            Case 7,8
                $Words_78[$Idx[2]][0] = $word
                $Words_78[$Idx[2]][1] = _ArrayToString($i,"")
                $Idx[2] += 1
            Case Else
                $Words_Over8[$Idx[3]][0] = $word
                $Words_Over8[$Idx[3]][1] = _ArrayToString($i,"")
                $Idx[3] += 1
        EndSwitch
    WEnd
    Redim $Words_1234[$Idx[0]][2]
    _ArraySort($Words_1234, 0, 0, 0, 1)
;   _ArrayDisplay($Words_1234)
    Redim $Words_56[$Idx[1]][2]
    _ArraySort($Words_56, 0, 0, 0, 1)
;   _ArrayDisplay($Words_56)
    Redim $Words_78[$Idx[2]][2]
    _ArraySort($Words_78, 0, 0, 0, 1)
;   _ArrayDisplay($Words_78)
    Redim $Words_Over8[$Idx[3]][2]
    _ArraySort($Words_Over8, 0, 0, 0, 1)
;   _ArrayDisplay($Words_Over8)

    GUICtrlSetData($output,"")
    GuiCtrlSetColor($output, 0x000000); black
    GUICtrlSetState($input, $GUI_ENABLE)
    GUICtrlSetState($input, $GUI_FOCUS)
EndFunc

I yanked out the auto-resizing of the arrays, don't need it if you know the makeup of your dictionary file in advance, and can adjust the initial Dim statements. If you want to automatically handle any dictionary size, I guess you'd want to leave it in, although it slows things down.

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...