Fortran Wiki
spoiler

A trifling program called “spoiler” for reading punchlines that are encoded using the ROT-13 rotation encryption.

It contains the routine rotate13(3f), which shows a decent example of a Fortran SELECT.


NAME

rotate13(3f) - [M_strings] apply trivial ROT13 encryption to a string

SYNOPSIS

rotate13(input) result(output)

character(len=*),intent(in) :: input
character(len=len(input))   :: output

DESCRIPTION

ROT13 (“rotate by 13 places”, sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it in the alphabet; wrapping around if necessary.

The transformation can be done using a lookup table, such as the following:

  Input  ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
  Output NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm

ROT13 is used in online forums as a means of hiding spoilers, punchlines, puzzle solutions, and offensive materials from the casual glance. It has inspired a variety of letter and word games on-line, and is frequently mentioned in newsgroup conversations.

The algorithm provides virtually no cryptographic security, and is often cited as a canonical example of weak encryption.

ROT13 is a special case of the Caesar cipher which was developed in ancient Rome.

REFERENCES

Wikipedia, the free encyclopedia

EXAMPLE

spoiler 
United we stand, divided we fall.
Havgrq jr fgnaq, qvivqrq jr snyy.
program spoiler
implicit none
character(len=256) :: line
integer            :: ios
   do
      read(*,'(a)',iostat=ios)line
      if(ios.ne.0)exit
      write(*,'(a)')rotate13(line)
   enddo
contains
function rotate13 (input)
implicit none

!@(#) M_strings::rotate13(3f): converts a character to its ROT13 equivalent, which is a trivial rotation encryption - JSU 20190827

character(len=*),intent(in) :: input
character(len=len(input))   :: rotate13
integer                     :: itemp
integer                     :: i
  rotate13=' '
  do i=1,len_trim(input)
     itemp = ichar (input(i:i))
     select case(itemp)
      case(65:77,97:109)
        itemp = itemp + 13
      case(78:90,110:122)
        itemp = itemp - 13
     end select
     rotate13(i:i) = char ( itemp )
  enddo

end function rotate13
end program spoiler

category: code