Skip to content

Instantly share code, notes, and snippets.

@bxt
Created February 27, 2011 12:27
Show Gist options
  • Save bxt/846141 to your computer and use it in GitHub Desktop.
Save bxt/846141 to your computer and use it in GitHub Desktop.
PHP-Script to calculate various hash sums
#!/usr/bin/php
<?php
$silent=false;
if($argc>2&&$argv[2]=="-") {
$silent=true;
} else {
fputs(STDOUT,"Enter text:");
}
$input = trim(fgets(STDIN));
$algo="";
if($argc>1&&$argv[1]=="--md5") {
$algo="1";
} elseif ($argc>1&&$argv[1]=="--sha1") {
$algo="2";
} elseif ($argc>1&&$argv[1]=="--sha512") {
$algo="3";
}
if($algo=="") {
echo "md5 : ";
echo md5($input);
echo "\n";
echo "sha1 : ";
echo sha1($input);
echo "\n";
echo "sha512 : ";
echo hash("sha512",$input);
echo "\n";
} elseif ($algo=="1") {
echo md5($input);
} elseif ($algo=="2") {
echo sha1($input);
} elseif ($algo=="3") {
echo hash("sha512",$input);
}
if(!$silent&&$algo!="") {
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment