CSCI 2342 Submission 06
Encrypting and Decrypting Textfiles
Supplied file(s) |
$sup06/demo_encrypt_decrypt (the demo executable)$sup06/encrypt_decrypt.txt (the TextItems file)
|
---|---|
Files to submit |
encrypt_decrypt.cpp (your source code)encrypt_decrypt (your executable)my_tests.sh (your testing script)
|
Where to put them |
Copy them to your u##/submissions/s06 directory.
|
When they're due | Sunday, March 10, 2025 @11:59pm |
This week you will design and write a program to encrypt and decrypt textfiles. Such programs are nice exercises because they always involve making good choices for the structures and algorithms you need to use, and they require you (or should require you) to think through your approach before starting, in a way that not all exercises do.
Also, because you now have quite a number of STL facilities at your
disposal, you have quite a variety of things to choose from when solving any
problem with a C++ program, including this one. So, feel free to choose and
use whatever works, from the STL and (of course) from the
utilities
package. In fact, think of this as another
opportunity to get your "STL chops" up to speed.
diff
command, and you should
have some diff
commands for file comparison in your testing
script. Also, don't forget to include in your testing some files that are
encrypted by your program and decrypted by the sample executable, and vice
versa. This is a kind of "acid test" that should give you reasonable
confidence that your program is working properly if it passes that test.
The encryption scheme used is a straightforward "substitution cipher". That is, each line of the encoded message contains exactly the same number of characters as the corresponding line in the original plain text, and once you have decoded each character of the encoded message you immediately have the original plain text. This also implies that blank lines in the plain text are preserved in the encrypted text, which is in fact the case.
The original plain text of any message may contain any or all of the printable characters in the Standard ASCII Character Set. That is, the original textfile may contain any or all of those characters with numerical codes from 32 (the blank space) through to 126 (the tilde, or '~', character).
The phrase to be used for both encrypting and decrypting is obtained from the user, as the last of the inputs on the command line, after which this happens:
This process results in a list containing all printable ASCII characters in some order. Let's call the resulting list of characters "the key".
If you now imagine a line consisting of all the printable ASCII characters in their natural order placed underneath the above line (that is, underneath "the key"), then the encryption of each character in a message of plain text would be performed by finding the character to be encrypted in the bottom line and using whatever character lies immediately above it in "the key" as the corresponding encrypted character.
Similarly, when decoding any given character, you would find the encrypted character in the top line (that is, in "the key"), and then the character immediately below it would be the corresponding plain text character.