HASH Generator By Mohamed Mansour (2006)

Input String

Source Code

<?
///////////////////////////////////
// 
// Mohamed Mansour 10/25/2006
// http://www.m0interactive.com
// 
// Very quick way to calculate SHA1
//   Learning: Beginner
//   Time: 15minutes
//
///////////////////////////////////
$answer '';
$error '';

// Print Head
displayHeader();

// Check to see if the submission was accepted
if(isset($_GET['s'])) {
    if(empty(
$_GET['q'])) {    // Check if the input is empty
        
$error 'Input is Empty';
        
displayAnswer($error);
    } else { 
// Calculate SHA1
        
$answer sha1($_GET['q']);
        
displayAnswer($answer);
    }
} else {
    
// Display HTML
    
displayHTML();
}

// Print Foot
displayFooter();

//========================================================================
// Methods
//========================================================================
/*
* Displays The Header
*
*/
function displayHeader() { 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>Introduction to Security SHA1 Hash Retreival</title>
    <style type="text/css">
        html, body {margin: 0; padding: 0; border: 0;}
        #main {width: 705px; margin: 5px auto; padding: 0;}
        #highlight {border: 1px dotted #666;padding: 5px;margin:5px 0}
        #answer {border: 1px dotted #666;padding: 5px;margin:5px 0}
        fieldset {border: 1px dotted #666;}
        h1,h2{margin:0;padding:0;color:#666}
        h1 em {font-size:0.5em;}
        input {border:1px solid #666;color:#666;padding-left:10px;}
        input#s {width:60px;border:1px solid #666;background:#fff;}
    </style>
</head>
<body>
<div id="main">
    <h1>HASH Generator <em>By Mohamed Mansour (2006)</em></h2>
<?
}

/*
* Displays The Footer
*
*/
function displayFooter() {
?>

<div id="highlight">
<h1>Source Code</h1>
<?
// Highlight the file
highlight_file('index.php');
?>
</div>
<p>Homepage: <a href="http://www.m0interactive.com">http://www.m0interactive.com</a></p>
</div>
</body>
</html>
<?
}

/*
* Displays Resulting Screen
* @param str - The string of the answer
*/
function displayAnswer($str) {
?>
    <div id="answer">
        <h2>Answer: </h2>
        <p><strong>Input: </strong><?=$_GET['q']?></p>
        <p><strong>Hash: </strong><?=$str?></p>
        <p><input id="s" type="button" value="Go Back" onclick="window.location='/files/downloads/sha1/';" /></p>
    </div>
<?
}

/*
* Displays The Core
*
*/
function displayHTML() {
?>
    <form method="get" action="">
    <fieldset>
        <legend>Input String</legend>
        <input name="q" id="q" type="text" value="" size="95" /> 
        <input name="s" id="s" type="submit" value="submit" />
    </fieldset>
    </form>
<?
}
?>

Homepage: http://www.m0interactive.com