<?php class Sifreleyici{ private $_anahtar; public function __construct($anahtar = '', $md5 = true){ $anahtar = str_split($md5 ? md5($anahtar) : sha1($anahtar), 1); $sinyal = false; $toplam = 0; foreach($anahtar as $karakter){ if($sinyal){ $toplam -= ord($karakter); $sinyal = false; }else{ $toplam += ord($karakter); $sinyal = true; } } $this->_anahtar = abs($toplam); } public function sifrele($metin){ $metin = str_split($metin, 1); $sonuc = ''; foreach($metin as $karakter){ $sonuc .= sprintf("%03x", ord($karakter) + $this->_anahtar); } return $sonuc; } public function coz($metin){ $sonuc = ''; $metin = str_split($metin, 3); foreach($metin as $karakter){ $sonuc .= chr(hexdec($karakter) - $this->_anahtar); } return $sonuc; } } $anahtar = "asd"; $metin = "MerhabaDünya"; $s = new Sifreleyici($anahtar); echo $es = $s->sifrele($metin); echo "<br>"; echo $des = $s->coz($es); ?>
Çıktısı