WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : MD5 based block cypher in 128 bit CFB
Categories : PHP, Encryption, MD5 Click here to Update Your Picture
leaping langoor
Date : Apr 30th 2005
Grade : 2 of 5 (graded 1 times)
Viewed : 4931
File : No file for this code example.
Images : No Images for this code example.
Search : More code by leaping langoor
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Below is MD5-based block cypher ( MDC-like ), which works in 128bit CFB mode. It is very useful to encrypt secret data before transfer it over the network.

<?php

/**********************************************
**
** MD5 block cypher
**
** Author..: leapinglangoor [ leapinglangoor@yahoo.co.in ]
** Date....: 30th Apr 2005
** version.: v1.00
**
** Desc....: Below is MD5-based block cypher ( MDC-like ),
** which works in 128bit CFB mode. It is very useful to
** encrypt secret data before transfer it over the network.
**
** $iv_len - initialization vector's length.
** 0 <= $iv_len <= 512
**
************************************************/

function get_rnd_iv( $iv_len )
{

   
$iv = '';
    while (
$iv_len-- > 0 )
    {
         
$iv .= chr( mt_rand(  ) & 0xff );
    }

     return
$iv;
}

function
md5_encrypt( $plain_text, $password, $iv_len = 16 )
{

   
$plain_text .= "\x13";
   
$n = strlen( $plain_text );
    if (
$n % 16 )
    {
       
$plain_text .= str_repeat( "\0", 16 - ( $n % 16 ) );
    }

   
$i = 0;
   
$enc_text = get_rnd_iv( $iv_len );
   
$iv = substr( $password ^ $enc_text, 0, 512 );
    while (
$i < $n )
    {
         
$block = substr( $plain_text, $i, 16 ) ^ pack( 'H*', md5( $iv ) );
         
$enc_text .= $block;
         
$iv = substr( $block . $iv, 0, 512 ) ^ $password;
         
$i += 16;
    }

    return
base64_encode( $enc_text );

}


function
md5_decrypt( $enc_text, $password, $iv_len = 16 )
{

   
$enc_text = base64_decode( $enc_text );
   
$n = strlen( $enc_text );
   
$i = $iv_len;
   
$plain_text = '';
   
$iv = substr( $password ^ substr( $enc_text, 0, $iv_len ), 0, 512 );
    while (
$i < $n )
    {
         
$block = substr( $enc_text, $i, 16 );
         
$plain_text .= $block ^ pack( 'H*', md5( $iv ) );
         
$iv = substr( $block . $iv, 0, 512 ) ^ $password;
         
$i += 16;
    }

    return
preg_replace( '/\\x13\\x00*$/', '', $plain_text );

}
?>


example.php:
<?php

include( 'md5.php' );

$plain_text = 'very secret string';
$password = 'very secret password';

echo
"plain text is: [${plain_text}]<br />\n";
echo
"password is: [${password}]<br />\n";

$enc_text = md5_encrypt( $plain_text, $password );
echo
"encrypted text is: [${enc_text}]<br />\n";

$plain_text2 = md5_decrypt( $enc_text, $password );
echo
"decrypted text is: [${plain_text2}]<br />\n";
?>



A PHP function to encrypt and decrypt a number or string or a combination of the two.
Categories : PHP, Encryption, Security
PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character.
Categories : PHP, Algorithms, Security, Authentication, Encryption
Encrypt/Decrypt string with a given key by using mcrypt module of PHP (suitable to store encrypted data into any type of databases).
Categories : PHP, Encryption
base64 with encryption - encode and decode sessions
Categories : PHP, PHP Classes, Encryption, Sessions
Scramble Eggs - php class to scramble/encode
Categories : PHP, PHP Classes, Security, Encryption
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Retrieve text from table and email to your e- address in pipe delimited format.
Categories : PHP, MySQL
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate.
Categories : Authentication, PHP
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
Function to remember password
Categories : PHP, Authentication, Personalization and Membership
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
readline -- Reads a line
Categories : PHP, PHP Functions, Readline
a function that builds an HTML select list from any mysql table.
Categories : PHP, MySQL, HTML and PHP