note 75469 added to function.str-rot13

From: Date: Thu, 31 May 2007 19:21:42 +0000
Subject: note 75469 added to function.str-rot13
Groups: php.notes 
Request: Send a blank email to php-notes+get-127087@lists.php.net to get a copy of this message
<?php /** * Rotate each string characters by n positions in ASCII table * To encode use positive n, to decode - negative. * With n = 13 (ROT13), encode and decode n can be positive. * * @param string $string * @param integer $n * @return string */ function rotate($string, $n) { $length = strlen($string); $result = ''; for($i = 0; $i < $length; $i++) { $ascii = ord($string{$i}); $rotated = $ascii; if ($ascii > 64 && $ascii < 91) { $rotated += $n; $rotated > 90 && $rotated += -90 + 64; $rotated < 65 && $rotated += -64 + 90; } elseif ($ascii > 96 && $ascii < 123) { $rotated += $n; $rotated > 122 && $rotated += -122 + 96; $rotated < 97 && $rotated += -96 + 122; } $result .= chr($rotated); } return $result; } $enc = rotate('string', 6); echo "Encoded: $enc<br/>\n"; echo 'Decoded: ' . rotate($enc, -6); ?> ---- Server IP: 193.219.81.76 Probable Submitter: 88.119.34.152 ---- Manual Page -- http://www.php.net/manual/en/function.str-rot13.php Edit -- https://master.php.net/note/edit/75469 Del: integrated -- https://master.php.net/note/delete/75469/integrated Del: useless -- https://master.php.net/note/delete/75469/useless Del: bad code -- https://master.php.net/note/delete/75469/bad+code Del: spam -- https://master.php.net/note/delete/75469/spam Del: non-english -- https://master.php.net/note/delete/75469/non-english Del: in docs -- https://master.php.net/note/delete/75469/in+docs Del: other reasons-- https://master.php.net/note/delete/75469 Reject -- https://master.php.net/note/reject/75469 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127087) next »