/* * Filename: caesarcrypt.c * Authors(s): Roland (r.weirhowell@gmail.com) * Description: Encrypt and decrypt text using the Caesar Cipher algorithm * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "crypt.h" #include "dyninput.h" #include #include #include int main() { fputs( "1. Encrypt message\n" "2. Decrypt message\n" "Pick operation mode: " ,stdout ); char buf[4]; int64_t maxsize = INT64_MAX; fgets(buf, 3, stdin); int choice = strtol(buf, NULL, 10); fputs("Enter your message text: ", stdout); char* msg = dyninput_str(maxsize); if (!msg) { puts("ERROR: String input failed! Exiting..."); return -1; } fputs("Enter your key (shift value): ", stdout); fgets(buf, 4, stdin); int key = strtol(buf, NULL, 10); if (choice == 1) { caesar_encrypt(msg, maxsize, key); puts("\nYour encrypted message is:"); for (int i = 0; i < maxsize && msg[i]; i++) { putchar(msg[i]); } } else if (choice == 2) { caesar_decrypt(msg, maxsize, key); puts("\nYour decrypted message is:"); for (int i = 0; i < maxsize && msg[i]; i++) { putchar(msg[i]); } } free(msg); msg = NULL; return 0; }