Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a homework, there is an exercise in which I have a script that is used to search for a password.

One of the questions is if is possible to make it "more intelligent", and I'm stuck on it.


space1="a b c d e f g h i j k l m n o p q r s t u v w x y z"

if [  $# -le 1 ]
    echo "Ussage: " $0 SALT PASSWORD_CODED

for i in $space1
for j in $space1
for k in $space1

    variable=$(openssl passwd -crypt -salt "$1" "$i$j$k")
    if [ "$variable" = $2 ]
        echo password found: $i$j$k

If it is possible, I prefer only a clue to help me to discover the answer correct, not the answer itself. I promise to post the result when I get the answer for myself.

share|improve this question
+1 for request only for clue – Sunny Oct 7 '11 at 16:17
As suggested, you could use common words first or a dictionary, but brute force is brute force. In this case it's only 3 lower case characters, so it should take no time at all. I don't know if there is any other way to make the algorithm more intelligent. – Matt Oct 9 '11 at 8:16
What does "more intelligent" mean? – palacsint Nov 6 '11 at 21:57
up vote 3 down vote accepted

There's no real way to speed up the brute-force enumeration of all possible 3-letter passwords.

Perhaps you could use the dictionary. There's a finite list of 3-letter English words. They may be slightly more common.

Also, if you google for "most common passwords", some kind of 3-letter version of that list could be tried before anything else.

share|improve this answer

Look at the man page for openssl

It is the command being executed here:

$(openssl passwd -crypt -salt "$1" "$i$j$k")

Another Clue below.
Only roll your curser over it if you need the extra help.

Do you need to pass the passwords one at a time.

Still have not worked it out!

Try: openssl passwd -crypt -salt <salt> <passwd1> <password2> <password3> ....

share|improve this answer

The best way to do

space1="a b c d e f g h i j k l m n o p q r s t u v w x y z"
for i in $space1; do
    for j in $space1; do
        for k in $space1; do
            echo $i$j$k

in bash is probably :

for i in {a..z}{a..z}{a..z}; do echo $i; done    

Then, depending on what your homeworks says, it might or might not be what you are looking for.

share|improve this answer

If you want to support passwords with 4-5-6-n characters without more loops you could write a bijective function which maps integers to strings.

Maybe you want to check the homepage of the John the Ripper password cracker. It has downloadable word lists and maybe you can find some information about how John generates the passwords. Also check the Methods of attack chapter in Rob Shimonski's Hacking techniques article.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.