// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashGenerator {
    private static MessageDigest md;
    public static void main(String[] args) throws NoSuchAlgorithmException {
        md = MessageDigest.getInstance("SHA-256");
        printAllHash("abcdefghij", 3);
    }
    public static void printAllHash(String valid, int maxlen) {
        for(int i = 1; i <= maxlen; i++) {
            printAllHash(valid.toCharArray(), new char[i], 0);
        }
    }
    public static void printAllHash(char[] valid, char[] buf, int ix) {
        if(ix < buf.length) {
            for(int i = 0; i < valid.length; i++) {
                buf[ix] = valid[i];
                printAllHash(valid, buf, ix + 1);
            }
        } else {
            printHash(new String(buf));
        }
    }
    private static void printHash(String pw) {
        System.out.println(pw + " -> " + toHex(md.digest(pw.getBytes())));
    }
    private static String toHex(byte[] ba) {
        char hexdigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        StringBuffer sb = new StringBuffer("");
        for (int i = 0; i < ba.length; i++) {
           sb.append(hexdigit[(ba[i] >> 4) & 0x0F]);
           sb.append(hexdigit[ba[i] & 0x0F]);
        }
        return sb.toString();
     }
}
