# include # include # include # include # include "atbash.h" /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: atbash_test() tests atbash_encrypt(). Licensing: This code is distributed under the MIT license. Modified: 20 March 2018 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "atbash_test():\n" ); printf ( " C version\n" ); printf ( " atbash_encrypt() encrypts a plain text using the atbash\n" ); printf ( " substitution cipher.\n" ); atbash_test01 ( ); atbash_test02 ( ); /* Terminate. */ printf ( "\n" ); printf ( "atbash_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void atbash_test01 ( ) /******************************************************************************/ /* Purpose: atbash_test01() tests atbash_encrypt() with a short phrase. Licensing: This code is distributed under the MIT license. Modified: 20 March 2018 Author: John Burkardt */ { char *crypt; char *decrypt; char *plain = "A man, a plan, a canal - Panama!"; printf ( "\n" ); printf ( "atbash_test01():\n" ); printf ( " Apply atbash_encrypt() to a short phrase.\n" ); crypt = atbash_encrypt ( plain ); decrypt = atbash_encrypt ( crypt ); printf ( "\n" ); printf ( " PLAIN: '%s'\n", plain ); printf ( " CRYPT: '%s'\n", crypt ); printf ( " DECRYPT: '%s'\n", decrypt ); /* Free memory. */ free ( crypt ); free ( decrypt ); return; } /******************************************************************************/ void atbash_test02 ( ) /******************************************************************************/ /* Purpose: atbash_test02() tests atbash_encrypt() with another phrase. Licensing: This code is distributed under the MIT license. Modified: 20 March 2018 Author: John Burkardt */ { char *crypt; char *decrypt; char *plain = "There are a thousand hacking at the branches of evil for every one who is striking at its root."; printf ( "\n" ); printf ( "atbash_test02():\n" ); printf ( " Apply atbash_encrypt() to a longer phrase.\n" ); crypt = atbash_encrypt ( plain ); decrypt = atbash_encrypt ( crypt ); printf ( "\n" ); printf ( " PLAIN: '%s'\n", plain ); printf ( " CRYPT: '%s'\n", crypt ); printf ( " DECRYPT: '%s'\n", decrypt ); /* Free memory. */ free ( crypt ); free ( decrypt ); return; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 17 June 2014 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }