Jump to content

Recommended Posts

I have a text file of usernames and encrypted passwords (this is a college assignment that I'm working on - no funny stuff).

 

The text file looks like this:

 

wwuser1,  rexrms/F3P1D2
wwuser2,  stq/WqYkSonuQ
wwuser3,  maslN9sW1ynog
wwuser4,  syo.HWp6snVw6
wwuser5,  exVAke3EE.HYw
wwuser6,  trmGMnhO6XOjw
wwuser7,  haybU2Bmy02BE
wwuser8,  unJE7ALfHZRKo
wwuser9,  coRe3NYe2UJc.
wwuser10,  rubou4spJ8aQA

 

What I have to do:

 

Explode the overall string from the text file by newline. Which will give me ten sep. lines (all of which are located in an array via means of explode("\n"). That's fine and working well. However the problem is that the 10th line has an extra space. The salt of each password is the first two characters of the actual pass. So for rexrms/F3P1D2, the salt is re. I'm pretty sure that the extra space on wwuser10 is apart of the salt; as it's the only password I can't crack. I've been using trim() to get rid of the white space around the passwords, so this white space is being trimmed. How can I get rid of only two white spaces per line?

Link to comment
https://forums.phpfreaks.com/topic/175329-solved-text-file-problem/
Share on other sites

By the way my code for reading in and sorting out the text file is:

 

<?php
/***************************************
	READ IN STUDENT PASSWORDS FILE
***************************************/

//name of password file to use
$password_file = "ww.txt";
//open password file
$fh = fopen($password_file, 'r');
//read data from file into string called $password_data
$password_data = fread($fh,filesize($password_file));
//close the file
fclose($fh);
//create an array called passwords_newlines
//by splitting up (explode) each word that is separated
//by a newline into their own indexes in an array
$passwords_newlines = explode("\n",$password_data);

  

$index = 0;
$usernames = array();
$enc_passwords = array();
$salt = array();

//then loop through that array and split each line
//up by exploding the string based on the comma
//also get rid of whitespace before and after
//by using trim()
foreach($passwords_newlines as $password_line){

	list($u,$p) = explode(",",trim($password_line));
	$usernames[$index] = trim($u);
	$enc_passwords[$index] = trim($p);

	//get salt
	$salts[$index] = substr($enc_passwords[$index],0,2);
	$index++;
}
?>

However the problem is that the 10th line has an extra space
No. It doesn't. The leading 'r' is under the 2nd character in the line above it because 10 in wwuser10 has one more character than all the other lines above it.

Running your code and dumping the $salts array gives the correct values -

Array
(
    [0] => re
    [1] => st
    [2] => ma
    [3] => sy
    [4] => ex
    [5] => tr
    [6] => ha
    [7] => un
    [8] => co
    [9] => ru
)

Thanks for the replies. STupid mistake on my part; I wasn't at the class where this project was handed out so I completely misunderstood what everyone meant by "the extra white space". Found the problem. It wasn't printing out the last cracked password. Max execution time was at ten seconds. Tried it on another host and it worked fine. Thanks.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.