Example 94: Encryption and Decryption of a File

Learn how to encrypt and decrypt the given file.


Write a program to encrypt/decrypt a file using a substitution cipher. The file sample.txt has already been written for you.

In this cipher, each character read from the source file is substituted by a corresponding predetermined character, and this character is written to the target file.

For example, if the character A is read from the source file, and if we have decided that every A is to be substituted by !, then a ! would be written to the target file in place of every A.

Similarly, every B would be substituted by 5, and so on.


Level up your interview prep. Join Educative to access 70+ hands-on prep courses.