2014-09-23 98 views
3

我是一名數學學生,我知道模運算,這可能會有所幫助。Autohotkey - 字母循環

我想在AutoHotkey的代碼,或AutoIt的,關鍵點擊我要運行輸入命令,如序列:

一個一個一個一個一個一個一個一個輸入

一個一個一個一個一個一個一個輸入

...

一個一個一個一個一個一個輸入

我想循環字母一路

žžžžžžžž輸入

我要生成a-z分離字母的所有12個長度排列輸入

我會做,因爲我做了任何提示,非常感謝。

+0

那麼,你只是想打印出所有可能的組合? – Xenobiologist 2014-09-23 12:25:11

+3

你知道12到8次方是4.3億,對不對? – 2014-09-23 12:36:40

+3

你想對密碼對話框進行暴力破解? – hubalu 2014-09-23 12:53:42

回答

3

的幾乎同樣的問題被問2個星期前:Counting with AHK, Letters 但我會很高興地再次回答這個問題:
(點擊上面的鏈接,評論少例如,它有相當混亂這裏)

BruteForce(Chars, Min, Max, Prefix:="", Stage:=0) { ;function header 
    Loop, Parse, Chars ;We loop through the character string that we are gonna pass to this function 
    { 
     If (Stage >= Min-1) { ;explained in the second if block 
      ;Prefix: our last generated string (at the first iteration AAAAAAAAAAA (11 As)) 
      ;A_LoopField: contains current character of the "Chars" string that we are looping through 
      ;"{Enter}": to tell SendInput to send an Enter after the Prefix and the current char 
     SendInput % Prefix A_loopField "{Enter}" ;AAAAAAAAAAA A {Enter} 
     } 
     If (Stage < Max-1) { 
      ;at this point it get really tricky 
      ;it's kinda hard to explain what exactly happens here 
      ;and at the same time pretty selfexplainatory if you simply know the used AHK commands/keywords 

      ;Basically what happens here is, the function is going to call itself again without leaving the loop 
      ;increasing the state step by step (everytime we get here) until we reach (in this case) 12-1 so 11 
      ;during the first "iteration" (in this case) we will be adding an A to the prefix parameter everytime the function re-calls itself 
      ;when it reached 11, then it generated the string AAAAAAAAAAA (11 As) 
      ;since the is at this point the expression state >= Min-1 (we passed a 12 for Min) is true 
      ;we will output the the string + the current char (A) in the if block above 
      ;then the second if statement will fail 
      ;and the loop of the current function call will go into it's second iteration 
      ;and output again 11 As and our second character (B) 
      ;etc etc until the loop is over, then the last function call is over and it will go to the one from before... 
      ;as I said... really hard to explain. to understnad it you are best of with simply going through the code like it would be executed and maybe take some notes of what has happened in each iteration 
     BruteForce(Chars, Min, Max, Prefix A_LoopField, Stage + 1) 
     } 
    } 
} 

F1:: ;hotkey is F1 
    BruteForce("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 12, 12) ;this would send possible combination of capital letters (min length 12, max length 12) 
    ;you can change the min length and max length, as well as the character string however you want 
Return 

這裏是一個不同的方法,將給予更加有序輸出,如果最小和最大長度是不一樣的:

Generate(prefix, len, chars) { 
    If (StrLen(prefix) = len) 
     SendInput % prefix " " 
    If (StrLen(prefix) < len) 
     Loop, Parse, chars 
      Generate(prefix A_LoopField, len, chars) 
} 

BruteForce(chars, minLen, maxLen) { 
    curLen := minLen 
    Loop % maxLen-minLen+1 { 
     Generate("", curLen, chars) 
     curLen++ 
    } 
} 

F1:: 
    BruteForce("abc", 2, 3) 
Return 

輸出爲:aa ab ac ba bb bc ca cb cc aaa aab aac aba abb abc aca acb acc baa bab bac bba bbb bbc bca bcb bcc caa cab cac cba cbb cbc cca ccb ccc

+0

你可能會添加更多的評論,所以我可以理解? 這確實做了A-Z的12個字母排列?爲什麼在'「ABCD ... Z」後面有'12,12)',長度爲12以及什麼? 謝謝你的時間! – Katie 2014-09-24 00:09:27

+0

@Katie當然,我會添加更多評論。 (爲什麼你不試試我的代碼,而是看看而不是問它是什麼?)這兩個12的意思實際上是什麼在評論中已經是「最小長度12,最大長度12」(它更清晰地回答了其他問題我鏈接)。 – Forivin 2014-09-24 02:22:52

+0

正如你所看到的我的評論比預期的要長一點,但是這是由於這個事實,這個函數總是會調用它自己,導致大量的迭代,每次都有點不同。 所以正如我在評論中所說的,如果你直接不瞭解代碼相關的東西,那麼問一下,我會解釋它。如果你基本理解每行代碼的功能,那麼你可以非常輕鬆地通過代碼來了解它的工作原理。 我可能會在您閱讀完代碼後再次刪除代碼註釋,除非有人真的認爲我應該離開它們。 – Forivin 2014-09-24 03:05:03