Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ Program: Introduction Hiding the meaning of messages by putting them in some kind of code is something we have all done, from

Write a C++ Program: Introduction Hiding the meaning of messages by putting them in some kind of code is something we have all done, from the coding rings and secret symbols of childhood to the top secrecy of military and commercial establishments secret data. In fact, some of the earliest uses of computers were for coding messages and for breaking the enemys coded messages. Newer coding methods are among the most interesting research areas in computer science today. The Caesar Cipher One of the simplest examples of a substitution cipher is the Caesar Cipher, which is said to have been used by Julius Caesar to communicate with his army. Caesar is considered to be one of the first persons to have ever employed encryption for the sake of securing messages. Caesar decided that shifting each letter in the message would be his standard algorithm, and so he informed all of his generals of his decision, and was then able to send them secured messages. Using the Caesar Shift (3 to the right), the message, RETURNTOROME \Rightarrow would be encrypted as \Rightarrow UHWXUQWRURPH In this example, 'R' \Rightarrow 'U', 'E' \Rightarrow 'H', and so on. Now, even if the enemy did intercept the message, it would be useless, since only Caesars generals could read it.

The Assignment

Write a program to implement the Caesar Cipher Problem

Write a program that will ask the user to enter the name of a file.

Your program should then ask the user to enter 'encrypt' or 'decrypt'.

If the user enters anything else your program should print an error message and exit.

If they entered 'encrypt' your program should open the file and encrypt it by shifting each character (including white space) 3 values to the right.

If they entered 'decrypt' your program should open the file and decrypt it by shifting each character (including white space) 3 values to the left.

If the file fails to open your program should print an error message and exit.

The decrypted or encrypted message should be displayed on the screen and also written to an output file named message. [edit]Sample Solution Output Enter File Name: This_is_a_bad_file_name Enter encrypt or decrypt: decrypt Error: File did NOT open.

No Functions Please... example below.

____________________________________________________________________________________________________________ Enter File Name: plainText.txt Enter encrypt or decrypt: openFile Error: Bad Command. ____________________________________________________________________________________________________________ Enter File Name: plainText.txt Enter encrypt or decrypt: encrypt Vhg#xw#shuvslfldwlv#xqgh#rpqlv#lvwh#qdwxv#huuru#vlw#yroxswdwhp#dffxvdqwlxp#groruhptxh#odxgdqwlxp/# wrwdp#uhp#dshuldp/#hdtxh#lsvd#txdh#de#loor#lqyhqwruh#yhulwdwlv#hw#txdvl#dufklwhfwr#ehdwdh#ylwdh# glfwd#vxqw#h{solfder1#Qhpr#hqlp#lsvdp#yroxswdwhp#txld#yroxswdv#vlw#dvshuqdwxu#dxw#rglw#dxw#ixjlw/# vhg#txld#frqvhtxxqwxu#pdjql#groruhv#hrv#txl#udwlrqh#yroxswdwhp#vhtxl#qhvflxqw1#Qhtxh#sruur#txlvtxdp# hvw/#txl#groruhp#lsvxp#txld#groru#vlw#dphw/#frqvhfwhwxu/#dglslvfl#yholw/#vhg#txld#qrq#qxptxdp#hlxv# prgl#whpsrud#lqflgxqw#xw#oderuh#hw#groruh#pdjqdp#doltxdp#txdhudw#yroxswdwhp1#Xw#hqlp#dg#plqlpd# yhqldp/#txlv#qrvwuxp#h{huflwdwlrqhp#xoodp#frusrulv#vxvflslw#oderulrvdp/#qlvl#xw#doltxlg#h{#hd# frpprgl#frqvhtxdwxuB# Txlv#dxwhp#yho#hxp#lxuh#uhsuhkhqghulw#txl#lq#hd#yroxswdwh#yholw#hvvh#txdp#qlklo#prohvwldh#frqvhtxdwxu/# yho#looxp#txl#groruhp#hxp#ixjldw#txr#yroxswdv#qxood#sduldwxuB ____________________________________________________________________________________________________________ OUTPUT FILE: message Vhg#xw#shuvslfldwlv#xqgh#rpqlv#lvwh#qdwxv#huuru#vlw#yroxswdwhp#dffxvdqwlxp#groruhptxh#odxgdqwlxp/# wrwdp#uhp#dshuldp/#hdtxh#lsvd#txdh#de#loor#lqyhqwruh#yhulwdwlv#hw#txdvl#dufklwhfwr#ehdwdh#ylwdh# glfwd#vxqw#h{solfder1#Qhpr#hqlp#lsvdp#yroxswdwhp#txld#yroxswdv#vlw#dvshuqdwxu#dxw#rglw#dxw#ixjlw/# vhg#txld#frqvhtxxqwxu#pdjql#groruhv#hrv#txl#udwlrqh#yroxswdwhp#vhtxl#qhvflxqw1#Qhtxh#sruur#txlvtxdp# hvw/#txl#groruhp#lsvxp#txld#groru#vlw#dphw/#frqvhfwhwxu/#dglslvfl#yholw/#vhg#txld#qrq#qxptxdp#hlxv# prgl#whpsrud#lqflgxqw#xw#oderuh#hw#groruh#pdjqdp#doltxdp#txdhudw#yroxswdwhp1#Xw#hqlp#dg#plqlpd# yhqldp/#txlv#qrvwuxp#h{huflwdwlrqhp#xoodp#frusrulv#vxvflslw#oderulrvdp/#qlvl#xw#doltxlg#h{#hd# frpprgl#frqvhtxdwxuB# Txlv#dxwhp#yho#hxp#lxuh#uhsuhkhqghulw#txl#lq#hd#yroxswdwh#yholw#hvvh#txdp#qlklo#prohvwldh#frqvhtxdwxu/# yho#looxp#txl#groruhp#hxp#ixjldw#txr#yroxswdv#qxood#sduldwxuB ____________________________________________________________________________________________________________ Enter File Name: encrypted.txt Enter encrypt or decrypt: decrypt Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? ____________________________________________________________________________________________________________ OUTPUT FILE: message Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions