Guest User

Untitled

a guest
Feb 18th, 2013
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2.     $sanidata = "";
  3.  
  4.     if(isset($_POST['data']))
  5.     {
  6.         $data = $_POST['data'];
  7.         if(isset($_POST['normalize']) && $_POST['normalize'] == "yes")
  8.         {
  9.             $data = str_replace("\r", "", $data);
  10.             $data = str_replace("\n", "", $data);
  11.         }
  12.         $sanidata = htmlentities($data, ENT_QUOTES);
  13.     }
  14.     elseif(isset($_FILES['filetohash']['tmp_name']) && file_exists($_FILES['filetohash']['tmp_name']))
  15.     {
  16.         if(filesize($_FILES['filetohash']['tmp_name']) > 5 * 1024 * 1024)
  17.         {
  18.             @unlink($_FILES['filetohash']['tmp_name']);
  19.             die('File is too big. Max: 5MB. <a href="checksums.htm">go back</a>.');
  20.         }
  21.         $data = file_get_contents($_FILES['filetohash']['tmp_name']);
  22.         @unlink($_FILES['filetohash']['tmp_name']);
  23.         $sanidata = "";
  24.     }
  25. ?>
  26.  
  27. <h1>Online Text &amp; File Checksum Calculator</h1>
  28. <p>This page lets you hash ASCII text or a file with many different hash algorithms. Checksums are commonly used to verify the integrety of data. The most common use is to verify that a file has been downloaded without error. The data you enter here is 100% private, neither the data nor hash values are ever recorded.</p>
  29. <p><strong>Enter some ASCII or UNICODE text...</strong></p>
  30. <form action="checksums.htm#checksums" method="post">
  31.     <textarea name="data" rows="15" cols="40" style="width:100%;" ><?php echo $sanidata; ?></textarea>
  32.     <br />
  33.     <input type="checkbox" name="normalize" value="yes" />Remove line endings <br /><input type="submit" name="submit" value="Calculate checksums.." />
  34. </form>
  35. <h3>File (5MB MAX)</h3>
  36. <form action="checksums.htm#checksums" method="post" enctype="multipart/form-data">
  37. <input type="file" name="filetohash" /><input type="submit" name="hashfile" value="Calculate checksums..." />
  38. </form>
  39. <?php
  40. if(isset($data))
  41. {
  42.     $filename = "";
  43.     if(isset($_FILES['filetohash']['name']))
  44.     {
  45.         $filename = "(" . htmlentities($_FILES['filetohash']['name'], ENT_QUOTES) . ")";
  46.     }
  47.     echo "<a name=\"checksums\"></a><h2>Checkums $filename</h2>";
  48.     $hashes = hash_algos();
  49.     echo "<table border=\"0\" cellpadding=\"10\" style=\"font-family:monospace;\" >";
  50.     foreach($hashes as $hashtype)
  51.     {
  52.         $hash = hash($hashtype, $data);
  53.         if(strlen($hash) > 64)
  54.         {
  55.             $hash = substr($hash,0,64) . "<br />" . substr($hash,64);
  56.         }
  57.         echo "<tr><th>$hashtype</th><td>$hash</td></tr>";
  58.     }
  59.     echo "</table>";
  60. }
  61. else
  62. {
  63.     echo "<h2>Supported Hash Algorithms</h2><p>";
  64.     $hashes = hash_algos();
  65.     foreach($hashes as $hashtype)
  66.     {
  67.         echo "$hashtype ";
  68.     }
  69.     echo "</p>";
  70. }
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment