Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Covert this python code to C++ code import random import copy import argparse import sys argument parsing parserargparse.ArgumentParser (description- Encrypt and Decrypt text files using
Covert this python code to C++ code
import random import copy import argparse import sys argument parsing parserargparse.ArgumentParser (description- "Encrypt and Decrypt text files using simple substitution cipher") parser.add_argument("-m", type-int, metavar-'Mode', help- "MODE: 1 - Encrypt, 2 Decrypt (REQUIRED) ") parser.add_argument ("-", type-str, metavar InputFile', help-"TEXTFILE: Path to ciphertext or plaintext file (REQUIRED) ") parser.add_argument ("-k", type-str, metavar-'KeyFile', default-"cipher.txt", help "KEYFILE: Path to the key file Where to save the key if encrypting, where to read the key if decrypting. (Default-cipher.txt for mode 1, REOUIRED for mode 2) ") parser.add_argument ("-d", type-str, metavar- "OutputFile', default-"output.txt", help"DSTFILE: Path to output the encrypted/decrypted file (Default-output.txt)") args-parser.parse args ( mode - args.m -m arg saved as mode inPath-args.f f arg saved as input ile path keyPath - args. k # -k arg saved as key file path (Default is cipher .txt ?n current dir) Out Path - args.a # -a arg saved as output file path (default is output.txt in current dir) def ReadFile (path) try: file - open (path, 'r') #open file, read only text - file. read() #read file into text var file.close) close file to free up memory except IOError as details: #file 10 error details) Print exception details print ("ERROR:", sys.exit) return text #re turn the text as a string def WriteFile (text, path) try: import random import copy import argparse import sys argument parsing parserargparse.ArgumentParser (description- "Encrypt and Decrypt text files using simple substitution cipher") parser.add_argument("-m", type-int, metavar-'Mode', help- "MODE: 1 - Encrypt, 2 Decrypt (REQUIRED) ") parser.add_argument ("-", type-str, metavar InputFile', help-"TEXTFILE: Path to ciphertext or plaintext file (REQUIRED) ") parser.add_argument ("-k", type-str, metavar-'KeyFile', default-"cipher.txt", help "KEYFILE: Path to the key file Where to save the key if encrypting, where to read the key if decrypting. (Default-cipher.txt for mode 1, REOUIRED for mode 2) ") parser.add_argument ("-d", type-str, metavar- "OutputFile', default-"output.txt", help"DSTFILE: Path to output the encrypted/decrypted file (Default-output.txt)") args-parser.parse args ( mode - args.m -m arg saved as mode inPath-args.f f arg saved as input ile path keyPath - args. k # -k arg saved as key file path (Default is cipher .txt ?n current dir) Out Path - args.a # -a arg saved as output file path (default is output.txt in current dir) def ReadFile (path) try: file - open (path, 'r') #open file, read only text - file. read() #read file into text var file.close) close file to free up memory except IOError as details: #file 10 error details) Print exception details print ("ERROR:", sys.exit) return text #re turn the text as a string def WriteFile (text, path) tryStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started