public static void main(String[] args) throws FileNotFoundException, IOException, InvalidKeyException, IllegalBlockSizeException, InvalidAlgorithmParameterException, BadPaddingException, Exception {
        
        //1. Initialization
        int ctr = 1;
        int sizeBytes = 0;
        int l= 128;
        int k = 128;
        
        
        ske1gen = KeyGenerator.getInstance("AES");
        
        ske1gen.init(k);
        
        ske1 = Cipher.getInstance("AES/OFB/PKCS5Padding");
        
        File f = new File("prueba1"); // Creamos un objeto file
        String path = f.getAbsolutePath(); // Llamamos al método que devuelve la ruta absoluta
        File f2 = new File("prueba2"); // Creamos un objeto file
        String path2 = f2.getAbsolutePath(); // Llamamos al método que devuelve la ruta absoluta 
        File f3 = new File("prueba1"); // Creamos un objeto file
        String path3 = f3.getAbsolutePath(); // Llamamos al método que devuelve la ruta absoluta

        PlainDocument doc = new PlainDocument("prueba1", path);
        PlainDocument doc1 = new PlainDocument("prueba2", path2);
        PlainDocument doc2 = new PlainDocument("prueba3", path3);
        
        
        
        Library lib = new Library();
        lib.addDocument(doc);
        lib.addDocument(doc1);
        lib.addDocument(doc2);
        
        Index index = new Index(lib);
        
        Keys K = new Keys();
        Key[] aKeys = K.gen(k, l);
        
        byte[][] tw = null;
        
        //2. Build array A
        Map<String, byte[]> array = new TreeMap<String, byte[]>(); 
        Map<String, byte[]> table = new TreeMap<String, byte[]>();
        
        byte[] gkey = generateKey();
        
        for (String keyword : index.getKeywords()){//build linked list Li with nodes Ni,j and store it in array A
            System.out.println("#####################");
            System.out.println(keyword);
            System.out.println("#####################");
            
            byte[] firstAddress = getAddress(ctr);
            
            //Key prevKey = ske1gen.generateKey(); 
            
            //SecretKeySpec prevKey = new SecretKeySpec(iv, "AES");
            SecretKeySpec prevKey = new SecretKeySpec(gkey, "AES");
            
            byte[] entry = tableEntry(keyword,aKeys[1],firstAddress, prevKey);
            byte[] address = getAddress(keyword);
            table.put(Util.hexArray(address), entry);
            
            TreeSet<Document> docsKeyword = index.getDocuments(keyword);
            ArrayList<Document> list = new ArrayList<Document>();
            for(Document idDoc:docsKeyword){
                list.add(idDoc);
            }
            int size = docsKeyword.size();
            //Creating the list
            
            
            for(int i=0;i<size-1;i++){
                
                //Key kf = ske1gen.generateKey();
                
                //SecretKeySpec key = new SecretKeySpec(iv, "AES");
                SecretKeySpec key = new SecretKeySpec(gkey, "AES");
                
                String id = list.get(i).getId();
                byte[] node = createNode(id, key, ctr+1);

                IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
                
                ske1.init(Cipher.ENCRYPT_MODE, prevKey, ivParameterSpec);
                byte[] cNode = ske1.doFinal(node);

                byte[] addr = getAddress(ctr);

                sizeBytes += cNode.length;
                
                array.put(Util.hexArray(addr), cNode);

                System.out.println("Node (bytes): " + Util.hexArray(node));
                System.out.print("A[" + Util.hexArray(addr) + "] = " + Util.hexArray(cNode));
                System.out.println();

                ctr++;

            }
            // Last node
            Document lastDoc = docsKeyword.pollLast();
            
            //Key[] kf = ske1gen.generateKey();
            //SecretKeySpec key = new SecretKeySpec(iv, "AES");
            SecretKeySpec key = new SecretKeySpec(gkey, "AES");

            byte[] node = createNode(lastDoc.getId(), key, 0);

            IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
            
            ske1.init(Cipher.ENCRYPT_MODE, prevKey, ivParameterSpec);//, new IvParameterSpec(ske1.getIV()));
            byte[] cNode = ske1.doFinal(node);
            byte[] addr = getAddress(ctr);

            sizeBytes += cNode.length;
            
            array.put(Util.hexArray(addr), cNode);

            System.out.println("Node (bytes): " + Util.hexArray(node));
            System.out.print("A[" + Util.hexArray(addr) + "] = " + Util.hexArray(cNode));
            System.out.println();

            ctr++;
        }
        System.out.println("Num keywords: "+index.numberOfKeywords());
        System.out.println("Num nodos del indice: " + ctr);
        System.out.println("Size array KBytes: " + (sizeBytes/1024));
  
        System.out.println("");
        System.out.println("####Search####");
        System.out.println("");
        
        for(String keyword : index.getKeywords()){
            System.out.println(keyword);
            System.out.println("########");
            tw = trapdoor(keyword,aKeys[2], aKeys[1]);
            search(array, table, tw);
        }
        
    }