|
|
|
| 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 |
 aitor solozabal merino |
| Date : |
Apr 06th 2008 |
| Grade : |
2 of 5 (graded 1 times) |
| Viewed : |
776 |
| 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 |
|
|
|
|
|
|
|
|
|
| |
| <?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);
?> | | |
|
| A PHP function to encrypt and decrypt a number or string or a combination of the two. Categories : PHP, Encryption, Security | | | 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 | | | 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 very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | MD5 secured login Categories : PHP, Java Script, Authentication, Security | | | Secure URL $_GET Categories : PHP, Data Validation, Security | | | 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 | | | Encoding data using PGP via PHP's proc_* functions Categories : Cryptography, Security, Email, PHP, PGP | | | Easily Grant Temporary SSH Access to yourself when in remote location Categories : PHP, Linux, Cron, 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 | | | base64 with encryption - encode and decode sessions Categories : PHP, PHP Classes, Encryption, Sessions | | | 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 | | | Form Security - Match A Value For Success Categories : PHP, Authentication, HTML and PHP, Sessions, Security | | | Distribute PHP Software Protected by a License Key. Categories : PHP, Cryptography, Security, Software | |
|
|
|