代做c++ | assignment | lab代写 – C++ Programming Sections 1776, 1777 & 4086

C++ Programming Sections 1776, 1777 & 4086

代做c++ | assignment | lab代写 – 这道题目是利用c++进行的编程代写任务, 包括了c++等方面, 这个项目是lab代写的代写题目

ass代做 assignment代写 代写assignment

Deadline Mar 21, 2022 by 10:00 PM PST

Programming assignment 2 (100 Points):

Simple Cipher: c++ Strings, References & Functions (updated March 18, 2022)

Assignment Introduction: Write a program to encrypt and decrypt a plaintext (p) string of characters, the digits 0-9 and two special characters, a square bracket]and a question mark?. The plaintext will not contain spaces or other characters (e.g.,etc.). The program will have at least two user-defined functionsencryptanddecrypt.

Your program will accept command line arguments to allow the user to enter in a key valuek, a plaintext string of characters just described (p) or a ciphertext (C) and exactly one of the options to encrypt (E) or decrypt (D). Refer to the example usage on page 3 for how to run the program using the command line arguments and the skeleton code on page 4 for a general outline of the code.

Program Description and Functionality: Provide the following in your source file:

  1. Comments at the top of your.cpp file.
  2. A main function with command line argumentsmain(int argc, char* argv[])
3.Use only C++ headersthat place all standard-library routines innamespace std. For C++
strings use#include <string>; for standard input and output use#include <iostream>to
access std::cout;std::cin; and use #include <cstring>for C-style string functions like
std::strcmp andstd::strlen and if needed #include<cstdlib> for helper functions like
std::atoi, etc.
  1. The use of command line arguments (int argc, char* argv[]) to get the plaintext (-p SoMet]Xt?) or cipher text (-C pKjAPxuPW), the shift amountk 7 and the options to encrypt (-E) or decrypt (-D).
  2. The program needs to work for upper-case & lower-case letters, digits 0-9, & the symbols ] and ?. Refer to the declaration ofcodebookbelow for the supported character-set: char codebook [] = { Z,z,Y,y,X,x,W,w,V,v,U,u,T,t,S,s,R,r,Q,q, P,p,O,o,N,n,M,m,L,l,K,k,J,j,I,i,H,h,G,g, F,f,E,e,D,d,C,c,B,b,A,a,9,8,7,6,5,4,3,2, 1,0,],? };
  3. Write at least two functions,encrypt()&decrypt()with the following function prototypes: // plaintext and k are the values parsed from the command line void encrypt(std:: string& plaintext , int k);
// ciphertext and k are the values parsed from the command line
void decrypt(std:: string& ciphertext , int k);
  1. To encrypt a plaintext string use the following formula to compute an indexiinto thecodebook with length#define CBL 64 //Code Book Length:
Ci=E(p, k) = (p+k) modCBL,
wheremodis the modulus operator %, C is the ciphertext,Eis the encryption function,pis the
index of the plaintext character,kis the key shift, andCBLis the length of thecodebookarray.
  1. To decrypt a ciphertext string use the following formula to compute an indexiinto thecodebook array:
pi=D(C, k) = (Ck) modCBL, (Ck)>= 0
pi=D(C, k) = (((Ck) modCBL) +CBL) modCBL, (Ck)< 0
wheremod is the modulus operator %, C is the index of the ciphertext character,Dis the de-
cryption function,pis the plaintext,kis the key shift, andCBLis the length of thecodebookarray.
In C & C++, mod, or remainder of division, is the % symbol. For negative Ck numbers
refer to the references on page 4 for more details about the modulus operator in C++ with nega-
tive numbers.

Where to do the assignment You can do this assignment on your own computer, or using the SMC Virtual labs with Citrix. In either case, ensure the code compiles and runs on Windows. Submit one.cppfile namedA02.cpp. Do not use any other name or else points will be deducted.

Submitting the Assignment Include your name, your student id, the assignment number, the submission date, and a program description in comments at the top of your files, and use the CS52 Programming Guide for coding style guidance. Submit the assignment on Canvas (https://online.smc.edu) byuploading your .cpp fileto the Assignment 2 entry as an attachment. Do not cut-and-paste your program into a text window. Do not hand in a screenshot of your programs output. Do not hand in a text file containing the output of your program.

Saving your work Save your work often on a flash-drive or to the cloud (e.g., GoogleDrive, Microsoft OneDrive, Canvas, etc.). Always save a personal copy of your files (e.g. .cpp, .h, etc.). Do not store files on the virtual lab computers.

References:

 Microsoft C++ Language Reference
 ISO C++ Standard Library and other refs
 The modulus operator yields the remainder given by the following expression, whereeis the first operand
ande 2 is the second: e 1 (e 1 /e2)e 2 , where both operands are of integral types. Microsoft C++
Modulus & Multiplication Operators

Example usage:

A02.exe -p ]Bc?? -k 3 -E //encrypt the string ]Bc?? The plaintext was: ]Bc?? The ciphertext is: zaAYY enter any key to exit

A02.exe -C zaAYY -k 3 -D //decrypt the string zaAYY The ciphertext was: zaAYY The plaintext is: ]Bc?? enter any key to exit

A02.exe -k 5 -p 01?]z?7]?9] -E //encrypt the string 01?]z?7]?9] The plaintext was: 01?]z?7]?9] The ciphertext is: YzXyWX2yX4y enter any key to exit

A02.exe -C YzXyWX2yX4y -k 5 -D //decrypt the string YzXyWX2yX4y The ciphertext was: YzXyWX2yX4y The plaintext is: 01?]z?7]?9] enter any key to exit

A02.exe -p ?]some]]text]? -k 7 -E //encrypt the string ?]some]]text]? The plaintext was: ?]some]]text]? The ciphertext is: WxOKIAxxPATPxW enter any key to exit

A02.exe -C WxOKIAxxPATPxW -k 7 -D //decrypt the string WxOKIAxxPATPxW The ciphertext was: WxOKIAxxPATPxW The plaintext is: ?]some]]text]? enter any key to exit

A02.exe -k 9 -E -p ]tH?s]sv3ryYc00l] //encrypt the string ]tH?s]sv3ryYc00l] The plaintext was: ]tH?s]sv3ryYc00l] The ciphertext is: wOdVNwNQyMTu5WWGw enter any key to exit

A02.exe -C wOdVNwNQyMTu5WWGw -k 9 -D //decrypt the string wOdVNwNQyMTu5WWGw The ciphertext was: wOdVNwNQyMTu5WWGw The plaintext is: ]tH?s]sv3ryYc00l] enter any key to exit

Skeleton code

// Name: Your First Name & Last Name
// SSID: Student ID Number
// Assignment #: 2
// Submission Date: 3/19/
//
// Description: A program to encrypt and decrypt a message using a shift cipher
// The plaintext message must only contain the codebook characters
//
// command line arguments
// -p ThePla?Nt]xTM]ss2ge1? - the plaintext (p) message to be encrypted
// -C pC9lG1VjOwSpiwNNXB9xV - the cipher (C) text to be decrypted
// -k 9 - the key (k) shift value
// -E - the option to encrypt (E)
// -D - the option to decrypt (D)
//

#include //std::cout , std::cin , etc. #include //C++ version of stdlib.h #include //C++ version of string.h #include

// Todo A2: encrypt using std:: string
void encrypt(std:: string& plaintext , int k);
// Todo A2: decrypt using std:: string
void decrypt(std:: string& ciphertext , int k);

int main(int argc , char *argv []) { // Example variables for A int k = 0; // k shift int msg_index = 0; // msg_index of plaintext or ciphertext in argv std:: string msg; // string to hold the plaintext or ciphertext; bool do_encrypt = false; // True for encrypt or False for decrypt

// Todo A2: process the command line arguments
for (int i = 1; i < argc; i++){
// use strcmp to compare command line switches to argv[i]
// .... your code goes here
}
//
// Todo A2: call encrypt or decrypt functions
//
if (do_encrypt) // encrypt plaintext
encrypt(msg , k);
else
decrypt(msg , k);// decrypt ciphertext
//
// Todo A2: print the original message and the plaintext | ciphertext
//

return 0; }//main

//Todo A2: function definitions go here