private static String encrypt(final int[] key, final String text) {
        String encryptedText = "";
        logger.log(Level.INFO, "Plain text: {0}", text);
        logger.log(Level.FINE, "Key: {0}", Arrays.toString(key));
        char temp[][] = new char[text.length()][key.length];
        int order[] = new int[key.length];
        for (int i = 0; i < order.length; i++) {
            int j = 0;
            while (key[j] != i + 1) {
                j++;
            }
            order[i] = j;
        }
        int n = 0, maxrow = 0;
        for (int row = 0; n < text.length(); row++, maxrow++) {
            for (int column = 0; n < text.length() && column < key.length; column++) {
                temp[row][column] = text.charAt(n++);
            }
//            System.out.println(Arrays.toString(temp[row]));
        }
        for (int column = 0; column < key.length; column++) {
            for (int row = 0; row < maxrow; row++) {
                if (temp[row][order[column]] != '\0') {
                    encryptedText += temp[row][order[column]];
                } else {
//                    encryptedText += ' ';
                }
            }
        }
        logger.log(Level.INFO, "Encrypted text: {0}", encryptedText);
        return encryptedText;
    }