Показать сообщение отдельно

  #2  
Старый 22.01.2007, 02:19
Foster
Познающий
Регистрация: 14.07.2005
Сообщений: 62
С нами: 10960703

Репутация: 6
По умолчанию

и ещё одно... можно ли с помощью пхп шифровать информацию, не хешировать а именно зашифровывать..? например я хочу зашифровать при помощи пароля текст в файле mess.txt а потом таким же образом востановить...
ЗЫ: base64_encode, md5, crypt не предлогать =)

Нашол кое че, да вот помоему чето не робит

PHP код:
// encode function - encodes text to quet sequre text 

// 

function encrypt( &$ftext, $fkey='fenyxxxx' ){ 

$prevchr=0; 

$answ=''; 


if (
$im = strlen($ftext)) { 

$k=0; 


for(
$i=0;$i<$im;$i++){ 

$thischr = ord(substr($ftext,$i,1)) + $prevchr; 

if(isset(
$fkey[$k])){ 

$key_chr=ord($fkey[$k])+ord($fkey[$k+1])+ord($fkey[$k+2])-ord($fkey[$k+3]);} 

else{
$k=0;$key_chr=ord($fkey[$k]);$fkey=substr($fkey,1).$fkey[0]; 

}; 

$key_chr=$key_chr+$old_chr^$i; 

$old_chr = checkbit($key_chr, 7) + 

checkbit($key_chr, 64)*$fkey[1] + 

checkbit($key_chr, 1)*$fkey[2] + 

checkbit($key_chr, 32)*$fkey[3] + 

checkbit($key_chr, 2)*$fkey[4] + 

checkbit($key_chr, 8)*$fkey[5] + 

checkbit($key_chr, 128)*$fkey[7] + 

checkbit($key_chr, 4)*$fkey[6]; 


$k++; $thischr=$thischr+$key_chr; 

$prevchr = checkbit($thischr, 16) + 

checkbit($thischr, 64)*2 + 

checkbit($thischr, 1)*4 + 

checkbit($thischr, 32)*8 + 

checkbit($thischr, 2)*16 + 

checkbit($thischr, 8)*32 + 

checkbit($thischr, 128)*64 + 

checkbit($thischr, 4)*128; 


$answ .= chr($prevchr); 

} 

} 

return 
$answ; 

} 


// 

// decode function. decodes encoded data 

// 

function decrypt( &$ftext, $fkey='fenyxxxx' ){ 

$prevchr=0; 

$old_prevchr=0; 

$answ=''; 


if (
$im = strlen($ftext)) { 

$k=0; 

for(
$i=0;$i<$im;$i++){ 

$thischr = ord(substr($ftext,$i,1)); 

if(isset(
$fkey[$k])){$key_chr=ord($fkey[$k])+ord($fkey[$k+1])+ord($fkey[$k+2])-ord($fkey[$k+3]);}else{$k=0;$key_chr=ord($fkey[$k]);$fkey=substr($fkey,1).$fkey[0];}; 


$key_chr=$key_chr+$old_chr^$i; 

$old_chr = checkbit($key_chr, 7) + 

checkbit($key_chr, 64)*$fkey[1] + 

checkbit($key_chr, 1)*$fkey[2] + 

checkbit($key_chr, 32)*$fkey[3] + 

checkbit($key_chr, 2)*$fkey[4] + 

checkbit($key_chr, 8)*$fkey[5] + 

checkbit($key_chr, 128)*$fkey[7] + 

checkbit($key_chr, 4)*$fkey[6]; 


$k++; 


$prevchr = checkbit($thischr, 4) + 

checkbit($thischr, 16)*2 + 

checkbit($thischr, 128)*4 + 

checkbit($thischr, 32)*8 + 

checkbit($thischr, 1)*16 + 

checkbit($thischr, 8)*32 + 

checkbit($thischr, 2)*64 + 

checkbit($thischr, 64)*128; 

$prevchr=$prevchr-$key_chr; 

$answ .= chr($prevchr-$old_prevchr); 

$old_prevchr = $thischr; 

} 

} 

return 
$answ; 

} 


function 
checkbit( $num1, $num2 ) { 

return ( 
$num1 & $num2 ? 1 : 0 ); 

} 

Последний раз редактировалось Foster; 22.01.2007 в 04:14..
 
Ответить с цитированием