WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : Data encryption and decryption class.
Categories : PHP, PHP Classes, Security Click here to Update Your Picture
saji nair
Date : Feb 19th 2007
Grade : 4 of 5 (graded 3 times)
Viewed : 8888
File : 4581.php
Images : No Images for this code example.
Search : More code by saji nair
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This is a class which will encrypt the data into a numeric string. The encryption is not a straight forward one. It incorporates the ascii of the character does some mathemetical calculation over it using the key and then just returns the value (numerical value). This return value is then concatenated to give a numeric representation of the whole text. The decryption logic is a reverse application of the logic for encryption.


<?php
/** Class for encryption and decryption of the text. This is a simple class which returns the numeric encryption of the text.
**It can be further optimised to give better encryption output.
**Saji Nair
**/
   
class Encryption{
    var
$key;
    var
$text;
   
    function
Encryption(){
       
$this->key="SajIMTsENcRYptiOnKey"; /// key to encrypt with
   
}
   
/**Function to encrypt the text using the key.
** Returns numeric values for each character concatinated togather.
**Saji Nair
**/
   
function encrypt(){
       
$lenText=strlen($this->text);
       
$lenKey=strlen($this->key);
       
$str="";
       
$j=0;
       for(
$i=0;$i<$lenText;$i++,$j++){
           if(
$j==$lenKey){
               
$j=0;
           }   
           
$val=(ord($this->text[$i])*2)+ord($this->key[$j]);
       
$str.=$val;   
       }
       return
$str;
   }


/**Function to encrypt the text using the key.
** Returns the text from the encrypted numeric value.
**Saji Nair
**/
   
function decrypt(){
   
//    $this->text=explode("##",$this->text);
   
$temp=$this->text;
   
$temptext=array();
   
$templen=strlen($temp);
   for(
$i=0,$j=0;$i<$templen;$i=$i+3,$j++){
       
$temptext[$j]=substr($this->text,$i,3);
   }
       
$lenText=count($temptext);
       
$lenKey=strlen($this->key);
       
$str="";
       
       for(
$i=0,$j=0;$i<$lenText;$i++,$j++){
           if(
$j==$lenKey){
               
$j=0;
           }   
           
$val=$temptext[$i]-ord($this->key[$j]);
           
$val=$val/2;
           
$str.=chr($val);
       }
       return
$str;
   }
}
?>



Usage Example
<?php
$objCls
=new Encryption();
$objCls->text="this is my text.";
$objCls->text=$objCls->encrypt();
$objCls->decrypt();
?>



A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
Generating and Matching Secure and Strong Password Hash
Categories : PHP, PHP Classes, Cryptography, Security
Function to generate readable/remeberable random password
Categories : PHP, Security, Security
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security
Use of bitmasks to represent permissions
Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes
Scan Apache access log files and report possible worms attack
Categories : PHP, PHP Classes, Security, Apache, Log Files
Scramble Eggs - php class to scramble/encode
Categories : PHP, PHP Classes, Security, Encryption
Forms protected from XSS attacks (FOPAXSS)
Categories : PHP, PHP Classes, Form Processing, Security
Antispoof - a class to help prevent people hi-jacking and misusing parts of a website
Categories : PHP, PHP Classes, Security
A very basic and fast XML parser
Categories : PHP, PHP Classes, XML
Dollar Serial Number Validator
Categories : PHP, Security, Algorithms
send_mail function to defeat Header Injection Hacking/Spamming
Categories : PHP, Email, Form Processing, Security
Encoding data using PGP via PHP's proc_* functions
Categories : Cryptography, Security, Email, PHP, PGP
Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself.
Categories : PHP, PHP Classes, Templates, Complete Programs
POP3 Class
Categories : PHP Classes, PHP, Email
 saji nair wrote :1682
This is not a simple ascii conversion function. This piece of code converts text to numeric values irrespective of the length of data to be ciphered. If you try to convert the output you see for encrypt function into character you will get something different. Secondly this ciphered value can be deciphered only using the decrypting function. I have concatenated the numeric (ciphered) values of individual text.  I had to stop at the numeric value of characters if you convert it to characters after ciphering then it gives you some characters which are not compatible with the databases like MySQL. So when I tried to use that with password encryption for MySQL I was not able to retrive the exact value from the database once the chphered value was inserted, so the comparision was failing. Thats why I have used the numeric values only and concatenated it directly.