<?php class Sifreleyici{ var $anahtar; function Sifreleyici($anahtar){ $this->anahtar = $anahtar; } function anahtardegistir($anahtar){ $this->anahtar = $anahtar; } function anahtarED($metin) { $sifrele_anahtar = md5($this->anahtar); $ctr=0; $topla = ""; for ($i=0;$i<strlen($metin);$i++) { if ($ctr==strlen($sifrele_anahtar)) $ctr=0; $topla.= substr($metin,$i,1) ^ substr($sifrele_anahtar,$ctr,1); $ctr++; } return $topla; } function sifrele($metin){ srand((double)microtime()*1000000); $sifrele_anahtar = md5(rand(0,32000)); $ctr=0; $topla = ""; for ($i=0;$i<strlen($metin);$i++){ if ($ctr==strlen($sifrele_anahtar)) $ctr=0; $topla.= substr($sifrele_anahtar,$ctr,1) . (substr($metin,$i,1) ^ substr($sifrele_anahtar,$ctr,1)); $ctr++; } return base64_encode($this->anahtarED($topla)); } function coz($metin) { $metin = $this->anahtarED(base64_decode($metin)); $topla = ""; for ($i=0;$i<strlen($metin);$i++){ $md5 = substr($metin,$i,1); $i++; $topla.= (substr($metin,$i,1) ^ $md5); } return $topla; } } $c=new Sifreleyici("asd"); echo $c->sifrele("12345678"); echo $c->coz("VGoJPwM/B2ACNl8+BWhSOQ=="); ?>
Çıktısı
VGoJPwM/B2ACNl8+BWhSOQ== 12345678