function ch_to_rot13 ( ch ) !*****************************************************************************80 ! !! ch_to_rot13() converts a character to its ROT13 equivalent. ! ! Discussion: ! ! Instead of CHAR and ICHAR, we now use the ACHAR and IACHAR functions, which ! guarantees the ASCII collating sequence. ! ! Two applications of CH_TO_ROT13 to a character will return the original. ! ! As a further scrambling, digits are similarly rotated using ! a "ROT5" scheme. ! ! Example: ! ! Input: Output: ! ! a n ! C P ! J W ! 1 6 ! 5 0 ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 22 March 2006 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character CH, the character to be converted. ! ! Output, character CH_TO_ROT13, the ROT13 equivalent of the character. ! implicit none character ch character ch_to_rot13 integer itemp itemp = iachar ( ch ) ! ! [0:4] -> [5:9] ! if ( 48 <= itemp .and. itemp <= 52 ) then itemp = itemp + 5 ! ! [5:9] -> [0:4] ! else if ( 53 <= itemp .and. itemp <= 57 ) then itemp = itemp - 5 ! ! [A:M] -> [N:Z] ! else if ( 65 <= itemp .and. itemp <= 77 ) then itemp = itemp + 13 ! ! [N:Z] -> [A:M] ! else if ( 78 <= itemp .and. itemp <= 90 ) then itemp = itemp - 13 ! ! [a:m] -> [n:z] ! else if ( 97 <= itemp .and. itemp <= 109 ) then itemp = itemp + 13 ! ! [n:z] -> [a:m] ! else if ( 110 <= itemp .and. itemp <= 122 ) then itemp = itemp - 13 end if ch_to_rot13 = achar ( itemp ) return end subroutine s_quote ( s1, mark, s2 ) !*****************************************************************************80 ! !! s_quote() "quotes" a string. ! ! Discussion: ! ! Actually, it simply puts the string MARK before and after the string S1. ! ! Sometimes, when you print a string, you want to put quote marks around it. ! This is one way to do that. ! ! Examples: ! ! S1 MARK S2 ! -------- ---- ---------- ! Hi, Bob! " "Hi, Bob!" ! De Loop LoopDeLoop ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 30 January 2016 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S1, a string to be "quoted". ! ! Input, character ( len = * ) MARK, the "quote mark". ! ! Output, character ( len = * ) S2, the "quoted" string. ! implicit none character ( len = * ) mark character ( len = * ) s1 character ( len = * ) s2 s2 = trim ( mark ) // trim ( s1 ) // trim ( mark ) return end subroutine s_to_rot13 ( s1, s2 ) !*****************************************************************************80 ! !! s_to_rot13() "rotates" the alphabetical characters in a string by 13 positions. ! ! Discussion: ! ! Two applications of the routine will return the original string. ! ! Example: ! ! Input: Output: ! ! abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm ! Cher Pure ! James Thurston Howell Wnzrf Guhefgba Ubjryy ! 0123456789 5678901234 ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 30 January 2016 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S1, a string to be "rotated". ! ! Output, character ( len = * ) S2, the rotated string. ! implicit none character ch_to_rot13 integer i character ( len = * ) s1 integer s1_length character ( len = * ) s2 s1_length = len_trim ( s1 ) s2 = '' do i = 1, s1_length s2(i:i) = ch_to_rot13 ( s1(i:i) ) end do return end