What am I understanding wrong here?
crunch doesn't work like this and the manual is somewhat misleading. Its logic makes sense once you get it; and to get it you need examples (available in the manual), trials and errors.
Or this answer maybe. :)
From the manual:
crunch <min-len> <max-len> [<charset string>] [options]
You may specify character sets for crunch to use on the command line or if you leave it blank
crunch will use the default character sets. The order MUST BE lower case characters, upper case characters, numbers, and then symbols. If you don't follow this order you will not get the results you want. You MUST specify either values for the character type or a plus sign. […]
Where the manual says "lower case characters", "upper case characters", "numbers", and "symbols", it could say "set 1", "set 2", "set 3" and "set 4". The default sets correspond to the terms the manual uses, respectively, but aside from this "lower case characters" is just an abstract "set 1". In this context
@ refers to "set 1" and
% refers to "set 3". The tool doesn't check if "set 1" or "lower case characters" are indeed lower case characters!
Consider this command:
crunch 1 1 aA bB cC dD
# ^^ these are "lower case characters"
# ^^ there are "upper case characters"
# ^^ these are "numbers"
# ^^ these are "symbols"
The output is
crunch by default uses "lower case characters" only. If we explicitly tell it to use "numbers"
crunch 1 1 aA bB cC dD -t %
then it will use the third set of symbols:
Your original command
crunch 3 3 aA -d 1@
aA as "lower case characters" set. Yes, you did tell
A was a "lower case character". Now
Limits the number of duplicate characters.
-d 2@ limits the lower case alphabet to output like
aaa would not be generated as that is 3 consecutive letters of
a. The format is number then symbol where number is the maximum number of consecutive characters and symbol is the symbol of the the character set you want to limit i.e.
So you told
crunch that any "lower case character" (from your set, i.e.
A) can appear at most 1 time in a row. And indeed the output you got contains neither
Sometimes it's useful to forget about "lower case characters" etc., to think in terms of "set N" instead. The manual seems to be fixed on the premise that "lower case characters" should all be lower case and so on. Still (at least in Ubuntu) there is a file
/usr/share/crunch/charset.lst which can be used with
-f; it defines various sets that mix the four basic sets or their fragments. This strongly suggests any set acting as "lower case characters" (or "symbols", or …) is silently supported.
So if you need to generate strings so the first character is
( and the second character is
), then this is the way to go:
crunch 2 2 'a0(' 'a1)' -t @,
Try it. Notice
aa appears in the output, but it's neither "
a from the first set twice", nor "
a from the second set twice". The pattern
@, guarantees the first
a is from the first set and the second
a is from the second set. However this distinction is not so strict when
-d is involved. The command
crunch 2 2 'a0(' 'a1)' -t @, -d 1@
will not generate
aa. This observation leads to the following trick:
crunch 3 3 aA a -d 1,
The output is:
which is almost what you wanted. The mechanism seems to be like this:
- There is no
-t, so the tool uses the first set only.
- It generates all possible outputs (like
crunch 3 3 aA).
- It discards lines that contradict
-d 1,. This option says there cannot be
aa in the output. It doesn't matter the option refers to the second set and all the output comes from the first set. No
You didn't anticipate
aAa because you misinterpreted
-d 1@ as "limiting the number of duplicates", while it's "limiting the number of consecutive duplicates".
Finally note the answer is mostly based on observation rather than the documentation. In particular the trick seems undocumented, it may be just an accidental result of how
crunch works under the hood. Future upgrades may make the tool behave differently in this matter without breaking documented features.