Kendi yazdığım bir sınıf.
Bu sitede ve php.org.tr sitesinde yayınlamıştım.
Linkler:
http://www.turk-php.com/smf/index.php/topic,3709.0.htmlhttp://www.php.org.tr/index.php?option=com_simpleboard&Itemid=26&func=view&id=6280&catid=11Başlıklardan konuyu takip edebilirsiniz.
Çalışma mantığı veri girişi yapılır ve çıkışı şifrelenmiş halde olur. Sonradan eklediğim özellikle multi fonksiyonu ile verinin kaç kez şifreleneceğini belirtebiliyorsunuz. Tabi geri döndürebilmek için bu değeri kullanarak çözebilirsiniz.
<?php
/**
* Erdem YAVUZ
* E-mail : erdem@a1tradenetwork.com
* Sınıf yazım tarihi 17 Ağustos 2006
*/
//Global değişkeninde çağıralacak şekilde sınıf yaratılıyor.
$text2code = new text2code();
class text2code {
var $str;
var $specialchar = '?';
var $pregsplit = '/\?/';
var $outstr ='';
var $for = '1';
function cod2ord()
{
$str = nl2br($str);
$str = preg_split('//',$this->str);
$i = 1;
while ($i<count($str)-1) {
$outstr .= ((ord($str[$i])*15 / 3) ).$this->specialchar;
$i++;
}
$outstr = substr($outstr,0,strlen($outstr)-1);
$this->str = $outstr;
return $this->str;
}
function cod2dec($type='0')
{
$str = preg_split($this->pregsplit,$this->str);
$i = 0;
if ($type == 0) {
while ($i<count($str)) {
$outstr .= decoct($str[$i]).$this->specialchar;
$i++;
}
}
if ($type == 1) {
while ($i<count($str)) {
$outstr .= octdec($str[$i]).$this->specialchar;
$i++;
}
}
$this->str = $outstr;
return $this->str;
}
function cod2hex($type='0')
{
$str = preg_split($this->pregsplit,$this->str);
$i = 0;
if ($type == 0) {
while ($i<count($str)) {
$outstr .= dechex($str[$i]).$this->specialchar;
$i++;
}
}
if ($type == 1) {
while ($i<count($str)) {
$outstr .= hexdec($str[$i]).$this->specialchar;
$i++;
}
}
$this->str = $outstr;
return $this->str;
}
function code2base64encode()
{
$this->outstr = base64_encode(gzcompress($this->str,1));
$this->str = '';
return $this->outstr;
}
function code2base64decode()
{
$this->str = gzuncompress(base64_decode($this->str));
return $this->str;
}
function decoding()
{
//$this->str = gzuncompress($this->str);
$this->code2base64decode();
$this->cod2hex(1);
$this->cod2dec(1);
$codes = preg_split($this->pregsplit,$this->str);
$i = 0;
while ($i<count($codes)) {
$outstr .= chr((($codes[$i]*3))/15);
$i++;
}
$outstr = preg_replace('/\r\n/','<br />',$outstr);
$this->str = '';
return $this->outstr=$outstr;
}
function coding()
{
$i = 0;
while ($i<$this->for) {
$this->cod2ord();
$this->cod2dec();
$this->cod2hex();
$this->str = $this->code2base64encode();
$i++;
}
$sonuc = $this->str;
$this->str = '';
return $sonuc;
}
function multidecoding()
{
$i = 0;
while ($i<$this->for) {
$this->str = $this->decoding();
$i++;
}
$sonuc = $this->str;
$this->str= '';
return $this->outstr = $sonuc;
}
function prnt()
{
return print substr($this->outstr,0,strlen($this->outstr)-4);
}
}
function code($data,$kez = '1',$pr='')
{ global $text2code;
$text2code->str=$data;
$text2code->for=$kez;
$dir = $text2code->coding();
if (!empty($pr))
$text2code->prnt();
if (empty($pr))
return $dir;
}
function decode($code='',$pr='',$multi = '')
{ global $text2code;
if (!empty($code))
$text2code->str=$code;
if (!empty($multi)) {
$text2code->for = $multi;
}
if ($text2code->for == 1)
$sonuc = $text2code->decoding();
if ($text2code->for >1)
$sonuc = $text2code->multidecoding();
if (!empty($pr))
$text2code->prnt();
if (empty($pr))
return $sonuc;
}
$str = 'Turk-PHP.com';
?>
<table width="500" style="width:500px;" border="0">
<tr>
<td style="font-size:11px;width:500px;font-family:verdana;color:#333333;">
<?php
$donen = (code($str,3));
?>
</td>
</tr>
<tr>
<td style="font-size:11px;width:500px;font-family:verdana;color:#333333;">
<?php
decode($donen,1,3);
?>
</td>
</tr>
</table>
Kolay gelsin.