# include # include # include # include # include using namespace std; # include "atbash.hpp" int main ( ); void atbash_test01 ( ); void atbash_test02 ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // atbash_test() tests atbash(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 20 March 2018 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "atbash_test():\n"; cout << " C++ version\n"; cout << " atbash() encrypts or decrypts a plain text using the Atbash\n"; cout << " substitution cipher.\n"; atbash_test01 ( ); atbash_test02 ( ); // // Terminate. // cout << "\n"; cout << "atbash_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void atbash_test01 ( ) //****************************************************************************80 // // Purpose: // // atbash_test01() tests atbash() with a short phrase. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 20 March 2018 // // Author: // // John Burkardt // { string crypt; string decrypt; string plain = "A man, a plan, a canal - Panama!"; cout << "\n"; cout << "atbash_test01():\n"; cout << " atbash() encrypts and decrypts a short phrase.\n"; crypt = atbash ( plain ); decrypt = atbash ( crypt ); cout << "\n"; cout << "PLAIN: '" << plain << "'\n"; cout << "CRYPT: '" << crypt << "'\n"; cout << "DECRYPT: '" << decrypt << "'\n"; return; } //****************************************************************************80 void atbash_test02 ( ) //****************************************************************************80 // // Purpose: // // atbash_test02() tests atbash() with another phrase. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 20 March 2018 // // Author: // // John Burkardt // { string crypt; string decrypt; string plain = "There are a thousand hacking at the branches of evil for every one who is striking at its root."; cout << "\n"; cout << "atbash_test02():\n"; cout << " atbash() encrypts and decrypts a longer phrase.\n"; crypt = atbash ( plain ); decrypt = atbash ( crypt ); cout << "\n"; cout << "PLAIN: '" << plain << "'\n"; cout << "CRYPT: '" << crypt << "'\n"; cout << "DECRYPT: '" << decrypt << "'\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 }