반응형
PHP를 이용한 암호화방법이다.
source : http://www.weberdev.com/get_example.php3?count=4118
Descript-xion : 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
source : http://www.weberdev.com/get_example.php3?count=4118
Descript-xion : 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
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
<?PHP
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
$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 algoritm
//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); // (+5 or *3 or ^2)
//after that we need a module division because can´t 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
//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>";
ECHO $Str_Test."<br>";
$Str_Test2 = ENCRYPT_DECRYPT($Str_Test);
ECHO $Str_Test2."<br><br>";
$Str_Test3 = ENCRYPT_DECRYPT($Str_Test2);
ECHO "<br>".$Str_Test3."<br>";
?>
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
$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 algoritm
//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); // (+5 or *3 or ^2)
//after that we need a module division because can´t 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
//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>";
ECHO $Str_Test."<br>";
$Str_Test2 = ENCRYPT_DECRYPT($Str_Test);
ECHO $Str_Test2."<br><br>";
$Str_Test3 = ENCRYPT_DECRYPT($Str_Test2);
ECHO "<br>".$Str_Test3."<br>";
?>
[출처] [PHP] Encrypt/Decrypt |작성자 달빛변신
반응형
'웹프로그램' 카테고리의 다른 글
PHP Foreach 문을 이용한 배열출력 (0) | 2008.10.19 |
---|---|
PHP 정규식 (0) | 2008.10.19 |
PHP sleep 함수..(지정한 시간동안 딜레이를 가짐) (0) | 2008.10.19 |
PHP 파일 다운받을때 한글파일문제 해결방법 (0) | 2008.10.19 |
PHP $_SERVER 함수 (0) | 2008.10.19 |
PHP 웹에서 엑셀문서 작업 (0) | 2008.10.19 |
php용 강력하면서 쉬운 소켓(socket)클래스 , Snoopy (0) | 2008.10.19 |
PHP 배열로 된 테이블의 값을 담은 값으로 테이블 만들기 (0) | 2008.10.19 |