package org.funsec.util;

import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

public class Permutations {

    /**
     * Call the handler once for each permutation alphabet in len, calculated by count(alphabet)^len.
     */
    public static void addAndCarry(int len, byte[] alphabet, Consumer<byte[]> handler) {
        byte[] word = new byte[len];
        int[] index = new int[len];

        while (true) {

            for (int i = 0; i < len; i++)
                word[i] = alphabet[index[i]];

            try {
                handler.accept(word);
            } catch (RuntimeException rte) {
                return;
            }


            for (int i = len - 1; ; i--) {
                if (i < 0) return;

                index[i]++;
                if (index[i] == alphabet.length)
                    index[i] = 0;
                else
                    break;

            }
        }
    }

}

@@ -23,205 +23,8 @@
 l;%0A%0A
-import java.util.Arrays;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A
 impo

remove imports