使用AppleScript

时间:2015-05-24 18:18:24

标签: security passwords applescript

我试图创建一个基于字符集大小和每秒猜测的脚本,估计破解用户在框中输入的密码需要多长时间。到目前为止,我只能通过尝试将框中输入的文本添加到自身来检查数字。我怎样才能检查字符集是否

...只有alpha,然后是字母数字,然后是混合字母,然后是混合字母数字,然后只是符号,然后是alpha符号,然后是混合字母符号,然后是混合字母数字符号,然后是数字符号,然后是字母数字符号等?

我知道它很长但是......你明白了。 (右?)

我知道一种有效的方式,但它的顺序敏感。

set thetext to "asdf"
set alpha to {"a", "b"}
if thetext contains alpha then
    say "yes"
else
    say "no"
end if

但我想让它对顺序不敏感。

1 个答案:

答案 0 :(得分:1)

您可能想要做的是遍历文本中的每个字符。然后,将该字符与字母表,数字进行比较,然后定义符号。然后,跟踪你发现的事情。

看起来你正在寻找的东西是alpha,numeric和symbolic。如果你跟踪这三件事,你可以构建你需求中列出的组合。

set theText to "asdf"

set theAlphabet to "abcdefghijklmnopqrstuvwxyz"
set theNumbers to "0123456789"

set containsAlpha to false
set containsNumber to false
set containsSomethingElse to false

repeat with theCharacter in theText
    if theAlphabet contains theCharacter then
        set containsAlpha to true
    else if theNumbers contains theCharacter then
        set containsNumber to true
    else
        set containsSomethingElse to true
    end if
end repeat

if containsAlpha and (containsNumber or containsSomethingElse) then
    if containsNumber and containsSomethingElse then
        say "The text contains a mix of letters, numbers, and something else."
    else if containsNumber then
        say "The text contains a mix of letters and numbers."
    else
        say "The text contains a mix of letters and something non-numeric."
    end if
else if containsAlpha then
    say "The text contains only characters from the ASCII alphabet."
else if containsNumber and containsSomethingElse then
    say "The text contains a mix of numbers and something non-alphabetic."
else if containsNumber then
    say "The text contains only numbers."
else if containsSomethingElse then
    say "The text contains only non-numeric and non-alphabetic characters."
else
    say "I think there is something wrong with my logic, Dave."
end if

我称第三类为“别的东西”而不是象征性的,因为我不想假设你的符号是什么标准;就此而言,您可能对字母表有不同的标准。比较是不区分大小写的,但是当前计数非ASCII字母是“别的”。

如果你想要区分大小写(给你四个标准而不是三个标准),你可以用a considering statement包围比较。例如:

if theAlphabet contains theCharacter then
    set containsAlpha to true
    considering case
        if theAlphabet contains theCharacter then
            set containsLowerAlpha to true
        end if
        if theUpperAlphabet contains theCharacter then
            set containsUpperAlpha to true
        end if
    end considering
else if theNumbers contains theCharacter then
…

然后,在谈话部分,添加新标准:

else if containsAlpha then
    if containsLowerAlpha and containsUpperAlpha then
        say "The text contains only upper and lower-case characters from the ASCII alphabet."
    else if containsLowerAlpha then
        say "The text contains only lower-case characters from the ASCII alphabet."
    else
        say "The text contains only upper-case characters from the ASCII alphabet."
    end if
else if containsNumber and containsSomethingElse then
…

显然,有四个考虑而不是三个,复杂性大大增加。如果说话部分是真实用例,我可以考虑在说出复杂性之前设置文本包含的字母类型:

-- set what kind of letters it contains
if containsAlpha then
    if containsLowerAlpha and containsUpperAlpha then
        set letterPhrase to "upper and lower-case letters"
    else if containsLowerAlpha then
        set letterPhrase to "lower-case letters"
    else
        set letterPhrase to "upper-case letters"
    end if
end if

--speak the complexity of the phrase
if containsAlpha and (containsNumber or containsSomethingElse) then
    if containsNumber and containsSomethingElse then
        say "The text contains a mix of " & letterPhrase & ", numbers, and something else."
    else if containsNumber then
        say "The text contains a mix of " & letterPhrase & " and numbers."
    else
        say "The text contains a mix of " & letterPhrase & " and something non-numeric."
    end if
else if containsAlpha then
    say "The text contains only " & letterPhrase & " from the ASCII alphabet."
…