*Below is a project I have been assigned (in which I am struggling to understand) in my Computer Science 150 class*
It must be done in:
- C++
- void functions
Here is the project: Write a Program the Decodes a Secret Message
The secret message will be encoded using an affine cipher. The cipher works by replacing the letter represented by the numeric value p (‘a’ = 0, ‘b’ = 1,…) with the letter represented by the numeric value (a*p + k) % 26, where a and k are constants (note, gcd(a, 26) = 1). The encoded message can then be decoded by replacing the encoded letters q with the expression (A*q + A*K) % 26, where A is the multiplicative inverse of a modulo 26 and K is the additive inverse of k modulo 26; i.e. (a*A) % 26 = 1 (k + K) % 26 = 0.
When a = 1 this type of cipher is known as a Caeser cipher which is simply a shift of the alphabet. Input will consist of a file with a and k on the first line (space separated) and an affine encoded message (only lowercase letters and spaces) on the second line with an added ‘0’ to denote the end of the message (note, the included input file is just one example, a and k are not fixed). Do not use features of C++ (like arrays & classes) covered after this program’s assignment date.
Write a C++ program that includes functions for each of the following tasks (use reference and value parameters appropriately based on the conventions of our class):
- Prompts user for file name
-reads in for the file name
-associates the input file (with validation) to an ifstream variable
-Reads in a and k from file line 1
-Computes and prints A and K Using A and K from (3.)
-decodes and prints the message from file line 2 (character by character)
-Example: Input File (input.txt): 3 1 erojd urzogd zq vrja uartabl buunokd b dnhang lnddbtn gr gwn zoujg qzin0
-Program Output: What is the name of the file? input 9 225 bonus points if your program appends a secret message to the input file.
*I am honestly very confused and don't know where to start with this program, than you so much for your help*
PROGRAM
#include<bits/stdc++.h>
using namespace std;
const int a = 17;
const int b = 20;
string encryptMessage(string msg)
{
string cipher = "";
for (int i = 0; i < msg.length(); i++)
{
if(msg[i]!=' ')
cipher = cipher +
(char) ((((a * (msg[i]-'A') ) + b) % 26) + 'A');
else
cipher += msg[i];
}
return cipher;
}
string decryptCipher(string cipher)
{
string msg = "";
int a_inv = 0;
int flag = 0;
(int i = 0; i < 26; i++)
{
flag = (a * i) % 26;
if (flag == 1)
{
a_inv = i;
}
}
for (int i = 0; i < cipher.length(); i++)
{
if(cipher[i]!=' ')
msg = msg +
(char) (((a_inv * ((cipher[i]+'A' - b)) % 26)) + 'A');
else
msg += cipher[i];
}
return msg;
}
int main(void)
{
string msg = "AFFINE CIPHER";
string cipherText = encryptMessage(msg);
cout << "Encrypted Message is : " << cipherText<<endl;
cout << "Decrypted Message is: " << decryptCipher(cipherText);
return 0;
}
OUTPUT:
Encode Message is : UBBAHK CAPJKX
Decode Message is : AFFINE CIPHER
*Below is a project I have been assigned (in which I am struggling to understand) in...
in c++ The science of writing secret codes is called cryptography. For thousands of years cryptography has made secret messages that only the sender and recipient could read, even if someone captured the messenger and read the coded message. A secret code system is called a cipher. In cryptography, we call the message that we want to be secret the plaintext. The plaintext could look like this: Hello there! The keys to the house are hidden under the flower pot. Converting...
Please can I have a UML Class diagram for the Python program below: def main(): print() print("Welcome to Caesar Encryption and Viginere Decryption Cipher") print() print("Please select an option") option = "c" while option == "c": hello = input('Choose Caesar Cipher encrypt 1:\n' 'Choose Viginere Cipher Decrypt 2:\n') message = input('Enter a message: ') password = input('Enter a password: ') if hello == '1': viginere_cipher(message, password) elif hello == '2': viginere_cipher_decrypt(message, password) print() print("Choose an option") option = input('Enter c...
Background: The first step towards helping someone 'decode' a message is often to count how many times each letter of the alphabet appears in the message. Then divide each count by the total number of letters to compute the relative 'frequency'. From these frequencies, it may be easier to recognize which letters are assigned to the vowels. For your own reference, here is a table of standard letter frequencies from typical English text. (You do NOT need to display this...
Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...
cs55(java) please
Part 1: You are a programming intern at the student transfer counselor's office. Having heard you are taking CS 55, your boss has come to ask for your help with a task. Students often come to ask her whether their GPA is good enough to transfer to some college to study some major and she has to look up the GPA requirements for a school and its majors in a spreadsheet to answer their question. She would like...
You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...
C programming (not c++) This programs input is a series of words. All words consist of only lowercase letters(a-z), no uppercase letters or digits or punctuation or other special symbols. The program reads until end-of-file, and then prints out the lowercase letters that were not seen in the input. Enter your input: the quick brown fox jumps over the lazy old dog Missing letters: enter your input: roll tide missing letters: a b c f g h j k m...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...
Some cryptography and a little computer security. You find an odd DeLorean parked around the corner. Realizing that Doc Brown has left the keys in the ignition, you decide that a quick trip back to Rome in 40 BC is in order. A few mint condition coins, and possibly a picture of Vincengetorix will be highly remunerative. As usual, the car fails and you are stranded. All is not lost, Julius Caesar recruits you for his secret service as a...
PLEASE DO THIS IN PYTHON!! 1.) Goal: Become familiar with The Python Interpreter and IDLE. Use IDLE to type, compile, and run (execute) the following programs. Name and save each program using the class name. Save all programs in one folder, call it Lab1-Practices. Save all programs for future reference as they illustrate some programming features and syntax that you may use in other labs and assignments. ================================== Program CountDown.py =================================== # Program CountDown.py # Demonstrate how to print to...