# include # include # include # include # include using namespace std; # include "caesar.hpp" int main ( ); void s_to_caesar_test ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // CAESAR_TEST tests CAESAR. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 31 January 2016 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "CAESAR_TEST:\n"; cout << " C++ version\n"; cout << " Test CAESAR().\n"; s_to_caesar_test ( ); // // Terminate. // cout << "\n"; cout << "CAESAR_TEST:\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void s_to_caesar_test ( ) //****************************************************************************80 // // Purpose: // // S_TO_CAESAR_TEST tests the S_TO_CAESAR library. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 31 January 2016 // // Author: // // John Burkardt // { int k; string s1; string s2; string s3; cout << "\n"; cout << "S_TO_CAESAR_TEST\n"; cout << " S_TO_CAESAR applies a Caesar Shift cipher to a string.\n"; cout << "\n"; cout << " S2 = S_TO_CAESAR ( S1, K ), varying K.\n"; cout << "\n"; cout << " K ---------------S1---------------- ---------------S2----------------\n"; cout << "\n"; for ( k = -5; k <= 5; k++ ) { s1 = "A man, a plan, a canal: Panama!"; s2 = s_to_caesar ( s1, k ); cout << " " << setw(2) << k << " '" << s1 << "' '" << s2 << "'\n"; } cout << "\n"; cout << " S2 = S_TO_CAESAR ( S1, K ).\n"; cout << " S3 = S_TO_CAESAR ( S2, -K )\n"; cout << "\n"; cout << " K ------------S1------------ ------------S2------------ ------------S3------------\n"; cout << "\n"; for ( k = -5; k <= 5; k++ ) { s1 = "The key is under the mat"; s2 = s_to_caesar ( s1, k ); s3 = s_to_caesar ( s2, -k ); cout << " " << setw(2) << k << " '" << s1 << "' '" << s2 << "' '" << s3 << "'\n"; } return; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // TIMESTAMP prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 08 July 2009 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }