note 112599 added to function.str-rot13

From: Date: Wed, 03 Jul 2013 09:37:37 +0000
Subject: note 112599 added to function.str-rot13
Groups: php.notes 
Request: Send a blank email to php-notes+get-195442@lists.php.net to get a copy of this message
Below is a short function that allows you to rotate a string which includes non alphabetic characters you choose. By running the code without the second argument you can both obfuscate then de-obfuscate. This isn't a safe form of encryption, just a quick way to hide stuff from the casual viewer. function str_rot($s, $n = -1) { //Rotate a string by a number. static $letters = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789.,!$*+-?@#'; //To be able to de-obfuscate your string the length of this needs to be a multiple of 4 AND no duplicate characters $letterLen=round(strlen($letters)/2); if($n==-1) $n=(int)($letterLen/2); //Find the "halfway rotate point" $n = (int)$n % ($letterLen); if (!$n) return $s; if ($n < 0) $n += ($letterLen); //if ($n == 13) return str_rot13($s); $rep = substr($letters, $n * 2) . substr($letters, 0, $n * 2); return strtr($s, $letters, $rep); } $input="ABC123"; $output=str_rot($input); echo $input." = ".$output." = ".str_rot($output)."<br>"; ---- Server IP: 69.147.83.199 Probable Submitter: 78.144.83.23 ---- Manual Page -- http://php.net/manual/en/function.str-rot13.php Edit -- https://master.php.net/note/edit/112599 Del: integrated -- https://master.php.net/note/delete/112599/integrated Del: useless -- https://master.php.net/note/delete/112599/useless Del: bad code -- https://master.php.net/note/delete/112599/bad+code Del: spam -- https://master.php.net/note/delete/112599/spam Del: non-english -- https://master.php.net/note/delete/112599/non-english Del: in docs -- https://master.php.net/note/delete/112599/in+docs Del: other reasons-- https://master.php.net/note/delete/112599 Reject -- https://master.php.net/note/reject/112599 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195442) next »