<?php header('Content-Type: text/html; charset=utf-8'); mb_internal_encoding('UTF-8'); class Sifre{ public $bundan=['1','2','3','4','5','6','7','8','9','0', 'a','b','c','ç','d','e','f','g','ğ','h','ı','i','j','k','l', 'm','n','o','ö','p','r','s','ş','t','u','ü','v','w','x','y','z', 'A','B','C','Ç','D','E','F','G','Ğ','H','I','İ','J','K','L', 'M','N','O','Ö','P','R','S','Ş','T','U','Ü','V','W','X','Y','Z']; public $buna=['v','B','i','Y','V','T','K','0','İ','7','n', 'Ç','x','ğ','b','f','o','Ü','J','z','Ğ','u','9','O','r','W', 'ş','A','g','ü','4','P','R','5','6','Z','w','s','E','3','y','F', 'd','I','D','t','ç','L','8','m','C','e','ö','ı','a','1','G','H', 'M','l','p','2','X','h','j','k','Ö','U','N','Ş','S','c']; function mb_chars_replace($from, $to, $subj, $delSymb='_') { $nsubj=''; preg_match_all('/(.)/u', $subj, $subj);$subj=$subj[1]; if (!is_array($from)) {preg_match_all('/(.)/u', $from, $from);$from=$from[1];} if (!is_array($to)) {preg_match_all('/(.)/u', $to, $to);$to=$to[1];} if (count($from)!==count($to)) return false; foreach($subj as $s) { foreach($from as $k=>$f) { if($s===$f) { $s=$to[$k]; break; } } if($s!==$delSymb) $nsubj.=$s; } return $nsubj; } function Sifrele($metin,$dosya){ $metin=$this->mb_chars_replace($this->bundan,$this->buna,$metin); file_put_contents($dosya,$metin); return $metin; } function Coz($dosya) { return $this->mb_chars_replace($this->buna,$this->bundan, file_get_contents($dosya)); } } $foo = new Sifre; echo $foo->Sifrele('Merhaba dünya, bu şifreli bir metin!','test.txt'); echo "<br>"; echo $foo->Coz('test.txt'); ?>
Çıktısı
Gf4znÇn bZş3n, Ç6 Ruo4fru Çu4 Wf5uş! Merhaba dünya, bu şifreli bir metin!