使用 AppleScript 检查字符集大小

Check for charset size with AppleScript

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

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

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

我知道一种工作方式,但它对顺序敏感。

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

但我想让它不区分顺序。

您可能想要做的是遍历文本中的每个字符。然后,将该字符与字母表、数字以及您定义的符号进行比较。然后,跟踪您发现了哪些类型的东西。

您要查找的内容似乎是字母、数字和符号。如果您跟踪这三件事,您就可以构建您的要求中列出的组合。

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