2014-09-23 253 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