Find password to a word document I am using Java and COM4j to communicate with Word. The approach I used here is brute force. I have a password protected .doc, and I forgot its password.

Complexity is (26)(maxPassLength). [a-z characters only]

Before I run this code and wait for 7-10 days here are my concerns.

My main concern is checking whether a generated string matches the password. Is there any alternative to this? Would you recommend threading to reduce the search space?

import com4j.Variant;
import java.util.HashMap;
import javax.swing.JOptionPane;
import word.Documents;
import word.WdOpenFormat;
import word._Application;
import word._Document;

public class DocPasswordFinder {

    public final static String filePath2 = "\\file\\abc.doc";
    private static HashMap&lt;Integer, Character&gt; mapC;
    private static final int passMaxLength;
    public static  _Application app;
    public static Documents doc;
    public static char[] arr;

    static {
    passMaxLength=9;
    arr = new char[passMaxLength];
    app = word.ClassFactory.createApplication();
    doc = app.documents();
    mapC=new HashMap&lt;&gt;();
        for (int i = 0; i &lt; 26; ++i) {
            mapC.put(i, (char) ('a' + i));
        }
    }

    public static void genPass(int start, int indx) {
        if (indx == passMaxLength) {
            String PASSWORD = String.valueOf(arr);
            try {                
        doc.open2000(filePath, false, true, false, PASSWORD, "", false,   
    PASSWORD, "", WdOpenFormat.wdOpenFormatAuto, false, false);
                JOptionPane.showMessageDialog(null, "FOUND: " + PASSWORD);
                System.exit(0);
            } catch (com4j.ComException ex) {
                //continue;
            }
        } else {
            if (indx &lt; arr.length) {
                for (int i = start; i &lt; 26; ++i) {
                    arr[indx] = mapC.get(i);
                    genPass(start, indx + 1);
                }
            }
        }
    }

    public static void main(String[] args) {
        genPass(0, 0);
    }
}


EDIT
Bottleneck appears to be the doc.open2000() part.
Complexity is (26)(maxPassLength).


You know that the password is only lower-case alpha characters?


  Would you recommend threading to reduce the search space?


It's possible that threads wouldn't help. The doc.open2000 will be more expensive than anything else, and your communication with Word may (I don't know) be effectively single-threaded (i.e. talking to a single Word process/task).

You might get better performance from a Word emulator which is designed to run on a server, e.g. from http://www.aspose.com/