Question
create a Ruby program that will take a key word and a text file then print out the encrypted text message. For instance, here is
create a Ruby program that will take a key word and a text file then print out the encrypted text message. For instance, here is a run of the program:
> encrypt
Enter the cipher key > honey
Enter the text file > mythoughts.txt
Enter the encrypted file > mysecret.txt
> encrypt -d
Enter the cipher key > honey
Enter the encrypted file > mysecret.txt
Enter the text file > mythoughts.txt
In the above examples of execution, the first encrypts the file 'mythoughts.txt' to 'mysecret.txt' using the key 'honey' to create the cipher. The second execution decrypts the message in 'mysecrets.txt' using the key 'honey' to create the cipher then writing the deciphered text in 'mythoughts.txt'. Realize that when decrypting, we are reversing the roles of the cipher and the alphabet in substitution for the text. When we encrypt the message, the alphabet character in the text is substituted using the cipher character, but when we decrypt the message, the cipher character in the encrypted text is substituted using the alphabet character.
Step 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