Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function RotThirteen($input)
- {
- $allowed_chars = array_merge(range('a','z'), range('A','Z'));
- array_push($allowed_chars, " ");
- $output = "";
- for($i = 0; $i < strlen($input); $i++) {
- $current_character = $input[$i];
- if ( !in_array($current_character, $allowed_chars) ) {
- continue;
- }
- $ascii_code = ord($current_character);
- $rot13_code = $ascii_code + 13;
- $substitute_character = "";
- if ( $current_character == " " ) {
- $substitute_character = $current_character;
- } else {
- if ( $rot13_code > 122 ) {
- $rot13_code = 97 + ($rot13_code - 123);
- } else if ( $rot13_code > 90 && $rot13_code < 104) {
- $rot13_code = 65 + ($rot13_code - 91);
- }
- $substitute_character = chr($rot13_code);
- }
- $output .= $substitute_character;
- }
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement