Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I used the Disk Utility to encrypt an external HDD about a month ago. Now it seems that I have forgotten the password. I have formed it according to a set of rules, so I have generated a word list (with a Python script) of ~400,000 candidates. I'm pretty confident that my lost password is somewhere among these, but I don't really feel like trying them all out by hand.

So the question goes: is there any tool which would take my word list a try them automatically? Or if not, how should I go about writing a script like that?

I've used a similar tool on GPG earlier, it's called nasty.

(If someone is interested in my extremely simple permutation script, it can be found on Pastebin.)

share|improve this question
up vote 8 down vote accepted

The return value of

echo "passphrase" | sudo cryptsetup luksOpen /dev/sda1 encrypted


  • 0, if there's a key for this passphrase
  • 234, if there's no key for this passphrase

It shouldn't be too hard to write a bash script, that loops over your word list, trying each passphrase and checking the return value.




if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root." 1>&2
   exit 1

while read line; do

    echo "$line" | cryptsetup luksOpen "$DEVICE" encrypted 2>/dev/null

    # success
    if [[ $? -eq 0 ]]; then
        cryptsetup luksClose encrypted
        echo "Passphrase: $line"
        exit 0

done < "$1"

echo "Passphrase not contained in word list."
exit 1

Save, change device, make executable, run like sudo ./find-password /path/to/wordlist and wait.

Note: This is slow. I don't know if it's because I tried this on a SD card, but it took five seconds to test four wrong passphrases (almost 6 days for 400,000 possible passphrases).

Update: Seems CPU bound. If you split your word list and do something like

(sudo ./find-password words.0 &) ; (sudo ./find-password words.1 &)

It will use two cores and almost half the time per try.

share|improve this answer
Excellent, seems to work perfectly! Thank you. I suspected that it would be CPU bound since it was as slow on my HDD. – Procy0n Jun 5 '11 at 11:04

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.