Tokenization, Vigenere, and Pointers in C++, Assignments of Advanced Computer Programming

Programming code in C++ to solve tokenization of vigenere with pointers merging information into an encryption and decryption paragraph.

Typology: Assignments

2022/2023

Uploaded on 09/29/2023

crystal-morell
crystal-morell 🇺🇸

2 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
/*Tokenization assignment--use of pointers, passing into functions,
using them as return data types, and leveraging them in traversig arrays.
CSIS 112<B02> (Crystal Morell)
DR. Williams (2023) personal communication (email, Pointers Assignment Instructions
Cplusplus (2023) www.cplusplus.com */
#include <iostream>
#include<fstream>
#include<string>
#include "MyText.h"
//Introducing menu and key
int displayMenu();
int main()
{
cout << "Crystal Morell -- Lab 5 -- Tokenization" << endl;
string key, filename, line;
char buff[1000];
char* token = NULL;
//Prompt for key
cout << "Enter an encryption/decryption key:\n";
getline(cin, key);
cout << endl;
//Create message object
MyText msg(key);
//Get choice
int opt = displayMenu();
//Loop until quit
while (opt != 3) {
if (opt == 1) {
cout << "\nEnter the name of the file to encrypt: ";
getline(cin, filename);
ifstream in("Poet.txt");
if (!in) {
cout << "File not found!!!\n";
}
else {
while (!in.eof()) {
in.getline(buff, 1000);
const char* delim = " ";
char* next_token;
token = strtok_s(buff, delim, &next_token);
while (token) {
msg.encryptWord(token);
token = strtok_s(NULL, delim, &next_token);
}
}
in.close();
cout << "\nA new file will be created that contains the encrypted
message.\n\n";
cout << "Please enter the name of the new file to create: ";
getline(cin, filename);
pf2

Partial preview of the text

Download Tokenization, Vigenere, and Pointers in C++ and more Assignments Advanced Computer Programming in PDF only on Docsity!

/Tokenization assignment--use of pointers, passing into functions, using them as return data types, and leveraging them in traversig arrays. CSIS 112 (Crystal Morell) DR. Williams (2023) personal communication (email, Pointers Assignment Instructions Cplusplus (2023) www.cplusplus.com / #include #include #include #include "MyText.h" //Introducing menu and key int displayMenu(); int main() { cout << "Crystal Morell -- Lab 5 -- Tokenization" << endl; string key, filename, line; char buff[1000]; char token = NULL; //Prompt for key cout << "Enter an encryption/decryption key:\n"; getline(cin, key); cout << endl; //Create message object MyText msg(key); //Get choice int opt = displayMenu(); //Loop until quit while (opt != 3) { if (opt == 1) { cout << "\nEnter the name of the file to encrypt: "; getline(cin, filename); ifstream in("Poet.txt"); if (!in) { cout << "File not found!!!\n"; } else { while (!in.eof()) { in.getline(buff, 1000); const char delim = " "; char* next_token; token = strtok_s(buff, delim, &next_token); while (token) { msg.encryptWord(token); token = strtok_s(NULL, delim, &next_token); } } in.close(); cout << "\nA new file will be created that contains the encrypted message.\n\n"; cout << "Please enter the name of the new file to create: "; getline(cin, filename);

msg.makeFile(filename); cout << "\n\nEncrypted file:\n"; msg.showWords(); } } else if (opt == 2) { cout << "\nEnter the name of the file to decrypt: "; getline(cin, filename); ifstream in("Invictus"); if (!in) { cout << "File not found!!!\n"; } else { while (!in.eof()) { in.getline(buff, 1000); const char* delim = " "; char* next_token; token = strtok_s(buff, delim, &next_token); while (token) { msg.decryptWord(token); token = strtok_s(NULL, delim, &next_token); } } in.close(); cout << "\nA new file will be created that contains the decrypted message.\n\n"; cout << "Enter the name of the new file to create: "; getline(cin, filename); msg.makeFile(filename); cout << "\n\nDecrypted file:\n"; msg.showWords(); } } cout << endl; opt = displayMenu(); } cout << "\n\nThank You!!\n"; return 0; 6; } //Implementation of menu unction int displayMenu() { int opt; cout << "\tVigenre Cypher\n\n Main Menu\n\n1 - Encrypt File\n2 - Decrypt File\n3 - Quit\n
n"; cout << "Selection: "; cin >> opt; while (opt < 1 || opt>3) { cout << "\nWrong choice!!!\n\nSelection: "; cin >> opt; } cin.ignore(); return opt; }