Hey guys, basically what i'm trying to do is take each line from two text files and store them into two variables, salt and original. I then want to pass these 2 variables to a different method called:
crypt(String salt, String original)
How would I go about doing this?

Many thanks

public static void main(String[] args)
   {
	String salt = new String();
	String original = new String();

	try{
		// Open the file that is the first 
    		FileReader wordlist = new FileReader("/home/cougar/students/u335122/Desktop/Crypt/wordlist.txt");
		FileReader password = new FileReader("/home/cougar/students/u335122/Desktop/Crypt/salt.txt");

		BufferedReader bufRead = new BufferedReader(wordlist);
		BufferedReader bufRead2 = new BufferedReader(password);
		
		int count = 0;
		int count1 = 0;

		original = bufRead.readLine();
		salt = bufRead2.readLine();
		//count++;
		//count1++;

		// Read through file one line at time. Print line
         while (original != null){
                  System.out.println(original);
                  original = bufRead.readLine();
                 // count++;
	      }

	 while (salt != null){
                  System.out.println(salt);
                  salt = bufRead2.readLine();
                 // count1++;
	      }

		bufRead.close();
		bufRead2.close();
	} catch (Exception e) {
	System.out.println("Error: " + e.getMessage());
	} 
	
         System.out.println
         (
            "[" + salt + "] [" + original + "] => [" +
            JCrypt.crypt(salt, original) + "]"
         );
   }

Assuming both the files have the same number of lines i.e. a salt for each string, you need to keep reading the data from your readers till the readLine() method returns null . Something like:

while((original= readerOne.readLine()) != null &&
             (salt = readerTwo.readLine()) != null) {
    JCrypt.crypt(salt, original);
}

Thanks for your help. I have changed the code around now and have got it working for the first line of each file.

What I need to do now, is once each line from the file is processed, get the next line from the files and process again. So some kind of loop is needed. I'm just struggling to think of a way to do this!
Any help is much appreciated!
Thanks

public static void main(String[] args)
   {
	String salt = new String();
	String original = new String();

	try{
		FileReader password = new FileReader("/home/floyd/Desktop/Crypt/salt.txt");
    		FileReader wordlist = new FileReader("/home/floyd/Desktop/Crypt/wordlist.txt");
		
		BufferedReader bufRead2 = new BufferedReader(password);
		BufferedReader bufRead = new BufferedReader(wordlist);
		
	        salt = bufRead2.readLine();
                original = bufRead.readLine();
   
		bufRead.close();
		bufRead2.close();

	} catch (Exception e) {
	    System.out.println("Error: " + e.getMessage());
	}
 
	System.out.println
         ("[" + salt + "] [" + original + "] ===> [" + JCrypt.crypt(salt, original) + "]");

	String hash = "d10NX4B.EJem2";
 
	if (JCrypt.crypt(salt, original).equals(hash))
	{
	      System.out.println ("Password Cracked! " + JCrypt.crypt(salt, original) + " ===> " + original);
	}
   }
}

> So some kind of loop is needed

...which is what I have in my previous reply. Re-read my previous reply and try implementing that with the code you currently have. Just make sure you put all those JCrypt related statements *inside* the loop since you need it to be done for each original & salt string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.