#! /usr/bin/env python # def s_to_rot13 ( s1 ): #*****************************************************************************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. # # Examples: # # Input: Output: # # abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm # Cher Pure # James Thurston Howell Wnzrf Guhefgba Ubjryy # 0123456789 56789012345 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 30 January 2016 # # Author: # # John Burkardt # # Parameters: # # Input, string S1, a string to be "rotated". # # Output, string S2, the rotated string. # from ch_to_rot13 import ch_to_rot13 s1_length = len ( s1 ) s2 = '' for i in range ( 0, s1_length ): s2 = s2 + ch_to_rot13 ( s1[i] ) return s2 def s_to_rot13_test ( ): #*****************************************************************************80 # ## S_TO_ROT13_TEST tests S_TO_ROT13. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 30 January 2016 # # Author: # # John Burkardt # import platform from s_quote import s_quote print ( '' ) print ( 'S_TO_ROT13_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' S_TO_ROT13 applies the ROT13 cipher to a string.' ) print ( '' ) print ( ' S2 = S_TO_ROT13 ( S1 ).' ) print ( '' ) print ( ' -------------------S1------------------- -------------------S2-------------------' ) print ( '' ) s1 = 'abcdefghijklmnopqrstuvwxyz' s2 = s_to_rot13 ( s1 ) s1 = s_quote ( s1, '"' ) s2 = s_quote ( s2, '"' ) print ( ' %-40s %-40s' % ( s1, s2 ) ) s1 = 'Cher' s2 = s_to_rot13 ( s1 ) s1 = s_quote ( s1, '"' ) s2 = s_quote ( s2, '"' ) print ( ' %-40s %-40s' % ( s1, s2 ) ) s1 = 'James Thurston Howell III' s2 = s_to_rot13 ( s1 ) s1 = s_quote ( s1, '"' ) s2 = s_quote ( s2, '"' ) print ( ' %-40s %-40s' % ( s1, s2 ) ) s1 = 'The bill is $1,205,837.49 so pay now!' s2 = s_to_rot13 ( s1 ) s1 = s_quote ( s1, '"' ) s2 = s_quote ( s2, '"' ) print ( ' %-40s %-40s' % ( s1, s2 ) ) print ( '' ) print ( ' S2 = S_TO_ROT13 ( S1 ).' ) print ( ' S3 = S_TO_ROT13 ( S2 ).' ) print ( '' ) print ( ' -------------------S1------------------- -------------------S3-------------------' ) print ( '' ) s1 = 'abcdefghijklmnopqrstuvwxyz' s2 = s_to_rot13 ( s1 ) s3 = s_to_rot13 ( s2 ) s1 = s_quote ( s1, '"' ) s3 = s_quote ( s3, '"' ) print ( ' %-40s %-40s' % ( s1, s3 ) ) s1 = 'Cher' s2 = s_to_rot13 ( s1 ) s3 = s_to_rot13 ( s2 ) s1 = s_quote ( s1, '"' ) s3 = s_quote ( s3, '"' ) print ( ' %-40s %-40s' % ( s1, s3 ) ) s1 = 'James Thurston Howell III' s2 = s_to_rot13 ( s1 ) s3 = s_to_rot13 ( s2 ) s1 = s_quote ( s1, '"' ) s3 = s_quote ( s3, '"' ) print ( ' %-40s %-40s' % ( s1, s3 ) ) s1 = 'The bill is $1,205,837.49 so pay now!' s2 = s_to_rot13 ( s1 ) s3 = s_to_rot13 ( s2 ) s1 = s_quote ( s1, '"' ) s3 = s_quote ( s3, '"' ) print ( ' %-40s %-40s' % ( s1, s3 ) ) # # Terminate. # print ( '' ) print ( 'S_TO_ROT13_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) s_to_rot13_test ( ) timestamp ( )