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 : ENCRYPT_DECRYPT_64 - A new version of ENCRYPT_DECRYPT without a known key with 2 added functions ENCODE and DECODE to ASCII characters between 32 and 127 codes.
Categories : PHP, Encryption, Security Click here to Update Your Picture
aitor solozabal merino
Date : Apr 06th 2008
Grade : 2 of 5 (graded 1 times)
Viewed : 4982
File : No file for this code example.
Images : No Images for this code example.
Search : More code by aitor solozabal merino
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?PHP
function show($title, $data)
{
   echo
$title, " (", strlen($data), " bytes):<br>\n", htmlentities($data), "<hr>\n";
}
function
ENCRYPT_DECRYPT($Str_Message)
{
   
//Function : encrypt/decrypt a string message v.1.0  without a known key
   //Author   : Aitor Solozabal Merino (spain)
   //Email    : aitor-3@euskalnet.net
   //Date     : 01-04-2005

   /*
   Description : A function with a very simple but powerful xor method to encrypt and/or decrypt a string 
   with an unknown key. Implicitly the key is defined by the string itself in a character by character way. 
   There are 4 items to compose the unknown key for the character in the algorithm:
   1.- The ascii code of every character of the string itself
   2.- The position in the string of the character to encrypt
   3.- The length of the string that include the character
   4.- Any special formula added by the programmer to the algorithm to calculate the key to use 
   */

   
$Len_Str_Message = STRLEN($Str_Message);
   
$Str_Encrypted_Message = "";
   for (
$Position = 0; $Position < $Len_Str_Message; $Position++) {
     
//long code of the function to  explain the algorithm
      //this function can be tailored by the programmer modifyng the formula
      //to calculate the key to use for every character in the string.
     
$Key_To_Use = (($Len_Str_Message + $Position) + 1);
     
// or +5 or *3 or ^2 or whatever more complicated
      // must be tailored in every applicaction by the programmer
      // this formula with the modified algorithm must be very confidential
      // after that we need a module division because can not be greater than 255
     
$Key_To_Use = (255 + $Key_To_Use) % 255;
     
$Byte_To_Be_Encrypted = SUBSTR($Str_Message, $Position, 1);
     
$Ascii_Num_Byte_To_Encrypt = ORD($Byte_To_Be_Encrypted);
     
$Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use;
     
//xor operation
     
$Encrypted_Byte = CHR($Xored_Byte);
     
$Str_Encrypted_Message .= $Encrypted_Byte;
     
//short code of  the function once explained
      //$str_encrypted_message .= chr((ord(substr($str_message, $position, 1))) ^ (255+(($len_str_message+$position)+1)) % 255));
   
}
   return
$Str_Encrypted_Message;
}
//end function
function ENCODE($Str_Message, $SIMBOLOS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
{
   
//Functions : ENCODE a string message v.1.0
   //            counterpart DECODE
   //Author   : Aitor Solozabal Merino (spain)
   //Email    : aitor-3@euskalnet.net
   //Date     : 07-10-2007
   // use in conjunction with encrypt/decrypt
   // There is a string $SIMBOLOS defined by default but
   // $SIMBOLOS can be defined on the fly by the function caller
   // the four conditions for the string $SIMBOLOS are:
   // 1.- the string $SIMBOLOS can not contain numbers 0,1,2,3,4,5,6,7,8,9 because are part of the algorithm
   // 2.- the lenght of string SIMBOLOS must be greater than 25 characters
   // 3.- every character in the strings SIMBOLOS must be unique and different
   // 4.- the string $SIMBOLOS must be the same to encode and to decode
   // Is not neccesary that the characters in string SIMBOLOS have any order like a sorted list or alphabetical
   // The length of the string can be expanded to double as a maximum when it is encoded
   // the string SIMBOLOS must be tailored in every applicaction by the programmer
   // the string SIMBOLOS with the modified algorithm ENCRYPT/DECRYPT must be very confidential
   
$Len_Simbolos = strlen($SIMBOLOS);
   if (
$Len_Simbolos > 25) {
     
$Len_Str_Message = strlen($Str_Message);
     
$Str_Encoded_Message = "";
      for (
$Position = 0; $Position < $Len_Str_Message; $Position++) {
         
$Byte_To_Be_Encoded = SUBSTR($Str_Message, $Position, 1);
         
$Ascii_Num_Byte_To_Encode = ORD($Byte_To_Be_Encoded);
         
$Rest_Modulo_Simbolos = ($Ascii_Num_Byte_To_Encode + $Len_Simbolos) % $Len_Simbolos;
         
$Plus_Modulo_Simbolos = (int)($Ascii_Num_Byte_To_Encode / $Len_Simbolos);
         
$Encoded_Byte = SUBSTR($SIMBOLOS, $Rest_Modulo_Simbolos, 1);
         if (
$Plus_Modulo_Simbolos == 0) {
           
$Str_Encoded_Message .= $Encoded_Byte;
         } else {
           
$Str_Encoded_Message .= $Plus_Modulo_Simbolos . $Encoded_Byte;
         }
      }
      return
$Str_Encoded_Message;
   }
}
//end function
function DECODE($Str_Message, $SIMBOLOS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
{
   
//Functions : DECODE a string message v.1.0
   //            counterpart ENCODE
   //Author   : Aitor Solozabal Merino (spain)
   //Email    : aitor-3@euskalnet.net
   //Date     : 07-10-2007
   // use in conjunction with encrypt/decrypt
   // There is a string $SIMBOLOS defined by default but
   // $SIMBOLOS can be defined on the fly by the function caller
   // the four conditions for the string $SIMBOLOS are:
   // 1.- the string $SIMBOLOS can not contain numbers 0,1,2,3,4,5,6,7,8,9 because are part of the algorithm
   // 2.- the lenght of string SIMBOLOS must be greater than 25 characters
   // 3.- every character in the strings SIMBOLOS must be unique and different
   // 4.- the string $SIMBOLOS must be the same to encode and to decode
   // Is not neccesary that the characters in string SIMBOLOS have any order like a sorted list
   // the string SIMBOLOS must be tailored in every applicaction by the programmer
   // the string SIMBOLOS with the modified algorithm ENCRYPT/DECRYPT must be very confidential
   
$Len_Simbolos = strlen($SIMBOLOS);
   if (
$Len_Simbolos > 25) {
     
$Len_Str_Message = strlen($Str_Message);
     
$Str_Decoded_Message = "";
      for (
$Position = 0; $Position < $Len_Str_Message; $Position++) {
         
$Plus_Modulo_Simbolos = 0;
         
$Byte_To_Be_Decoded = SUBSTR($Str_Message, $Position, 1);
         if (
$Byte_To_Be_Decoded > 0) {
           
$Plus_Modulo_Simbolos = $Byte_To_Be_Decoded;
           
$Position++;
           
$Byte_To_Be_Decoded = SUBSTR($Str_Message, $Position, 1);
         }
         
//finding the position in the string
         //$SIMBOLOS
         
$Byte_Decoded = 0;
         for (
$SecondPosition = 0; $SecondPosition < $Len_Simbolos; $SecondPosition++) {
           
$Byte_To_Be_Compared = SUBSTR($SIMBOLOS, $SecondPosition, 1);
            if (
$Byte_To_Be_Decoded == $Byte_To_Be_Compared) {
               
$Byte_Decoded = $SecondPosition;
            }
         }
         
$Byte_Decoded = ($Plus_Modulo_Simbolos * $Len_Simbolos) + $Byte_Decoded;
         
$Ascii_Num_Byte_To_Decode = CHR($Byte_Decoded);
         
$Str_Decoded_Message .= $Ascii_Num_Byte_To_Decode;
      }
      return
$Str_Decoded_Message;
   }
}
//end function
//sample use of the function
$Str_Test = "This function is free software; you can redistribute it and/or modify it under the 
    terms of the GNU General Public License as published by the Free Software Foundation in any version 
    of the License."
. "<br>" . "This program is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
    PARTICULAR PURPOSE."
. "<br>" . "Hello Aitor, Wellcome Home" . "<br>";
show('String original', $Str_Test);
$Str_Test2 = ENCRYPT_DECRYPT($Str_Test);
show('1º ENCRYPT_DECRYPT String', $Str_Test2);
// a sample without lower-case characters and with some symbols or default with ENCODE($Str_Test2);
$Str_Test3 = ENCODE($Str_Test2, "%?/\[]OPQRSTUVWXYZ<>()¡!@#&ABCDEFGHIJKLMN");
show('2º ENCODE (String Encrypted)', $Str_Test3);
// a sample without lower-case characters and with some symbols or default with DECODE($Str_Test3);
$Str_Test4 = DECODE($Str_Test3, "%?/\[]OPQRSTUVWXYZ<>()¡!@#&ABCDEFGHIJKLMN");
show('3º DECODE (String Encoded)', $Str_Test4);
$Str_Test5 = ENCRYPT_DECRYPT($Str_Test4);
show('4º ENCRYPT_DECRYPT String', $Str_Test5);
?>



Scramble Eggs - php class to scramble/encode
Categories : PHP, PHP Classes, Security, Encryption
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
A PHP function to encrypt and decrypt a number or string or a combination of the two.
Categories : PHP, Encryption, Security
PHP Cookies - Simple cookie write/read methods that allow basic encryption
Categories : PHP, Cookies, Security, Encryption
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
Function to generate readable/remeberable random password
Categories : PHP, Security, Security
MD5 secured login
Categories : PHP, Java Script, Authentication, Security
SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge response login algorithms over an insecure connection.
Categories : Algorithms, PHP, Security
A captcha image allows you to prevent spam posting when users reload the page and stop bots from submitting forms automatically. This version allows you to use your own fonts (.ttf) to show the text.
Categories : PHP, Security, Graphics, GD image library
A simple PHP login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page.
Categories : PHP, Sessions, Security, Authentication
session out Timer
Categories : PHP, Sessions, Security, Beginner Guides
Human readable PHP password generator
Categories : PHP, Security, Beginner Guides, Arrays
Antispoof - a class to help prevent people hi-jacking and misusing parts of a website
Categories : PHP, PHP Classes, Security
Forms protected from XSS attacks (FOPAXSS)
Categories : PHP, PHP Classes, Form Processing, Security
A few functions to create random passwords.
Categories : PHP, Security, Strings