-
hash md5 e \r\n
Salve a tutti, ho un problema.
Ho un file .txt con circa 96000 parole messe una sotto all'altra.
Devo criptarle tutte in md5, ma mi sono accorto che se faccio:
Codice PHP:
<?php
$f = file("d2.txt");//fie delle parole
$fp = fopen("d1.txt","at");//file in cui metto gli hash
for($i=0;$i<count($f);$i++) {
$hash = md5($f[$i]);
fputs($fp, $hash."\n");
}
fclose($fp);
?>
non funziona, perchè mi cripta Parola\r\n. Se ad esempio ho la parola 'ciao' da criptare, dal file ricavo 'ciao\r\n', e l'hash derivato è diverso da quello che dovrebbe essere. Ecco la mia domanda: come faccio a togliere \r\n dalle parole?
-
$hash = md5(trim($f[$i]));
Ciao!
-
Oppure carichi il file così:
Codice PHP:
$f = file("d2.txt", FILE_IGNORE_NEW_LINES);
-
Ho trovato str_replace() su google e ho risolto con quella. Grazie comunque per l'aiuto
-
Perchè scomodare str_replace quando ci sono funzioni apposite?
Ciao!
-
Ho un'altro problema. Il sito non bruta gli hash, ma restituisce sempre Hash non found. Eppore in locale tutto funziona. Ho provato ad attivare php5 (anche se non utilizzo le funzioni di php5 in locale lavoro con quello) ma nulla. Posto il codice (si tratta di una sola pagina):
Codice PHP:
<?php
function addLine($f,$t) {
$fp = fopen($f, "at");
fputs($fp, $t."\n");
fclose($fp);
}
?>
<html>
<head>
<title>MD5 Search</title>
<style type="text/css">
#title {
text-align: center;
font-size: 30;
font-weight: bold;
font-style: italic;
}
#hash {
margin-top: 80px;
text-align: center;
}
.foot {
text-align: center;
font-size: 12;
font-style: italic;
}
</style>
<script type="text/javascript">
function check() {
if(document.forms[0].hash.value != '')
document.forms[0].submit();
else
alert("Insert something!");
}
</script>
</head>
<body>
<form id="hash" action="" name="md5" method="get">
<img src="title.gif"><br>
<input type="text" name="hash" size="55" value="<?php print (isset($_GET['hash'])) ? $_GET['hash'] : ""; ?>"><br>
<label for="sc">Encode</label><input name="sc" type="radio" value="encode" <?php print ($_GET['sc'] == "encode") ? "checked=\"checked\"" : "" ?>>
<label for="sc">Brute</label><input name="sc" type="radio" value="brute" <?php print ($_GET['sc'] == "brute") ? "checked=\"checked\"" : "" ?>>
<input type="button" value="Search!" onclick="check()">
</form>
<center>
<?php
if(isset($_GET['hash'])) {
switch($_GET['sc']) {
case "encode":
echo "<b>Result: ".md5($_GET['hash'])."</b>";
$ff = file("d2.txt");
for($i=0;$i<count($ff);$i++)
$ff[$i] = str_replace("\r\n","",$ff[$i]);
if(!in_array($_GET['hash'],$ff)) {
addLine("d2.txt",$_GET['hash']);
addLine("d1.txt",md5($_GET['hash']));
}
break;
case "brute":
$hs = file("d1.txt");
$ws = file("d2.txt");
for($i=0;$i<count($hs);$i++)
$hs[$i] = str_replace("\r\n","",$hs[$i]);
for($i=0;$i<count($ws);$i++)
$ws[$i] = str_replace("\r\n","",$ws[$i]);
if(in_array($_GET['hash'],$hs))
print "<b>Result: ".$ws[array_search($_GET['hash'], $hs)]."</b>";
else
print "<b>Hash not found</b>";
break;
}
}
?>
</center>
</body>
<pre>
</pre>
<div class="foot">By Crashinside. <a href="http://crashinside.net">crashinside.net</a></font>
</html>
Il link per un test lo sapete.
Spiego il funzionamento del sito:
ci sono due files (d1.txt e d2.txt) in cui sono rispettivamente contenuti gli hash e le parole. Se nella riga 1 del file d2.txt c'è la parola 'a', allora nella riga 1 del file d1.txt c'è l'hash corrispondente. Uso array_search() per recuperare l'indice dell'hash e scrivere la parola. Se si prova a criptare 'ciao', viene restituito il messaggio: 'hash not found'. In realtà l'hash di ciao c'è, ma non so perchè non lo riconosce.
EDIT: nessuno mi aiuta? Scusate l'impazienza ma mi fa rabbia questa cosa. In locale funziona tutto a meraviglia mentre qui no.