Your country is at war and your enemies are using a secret code to communicate with each other.You have managed to intercept a message that reads asfollows:
:mmZdxZmx]Zpgy
The message is obviously encrypted using the enemy's secret code.You have just learned that their encryption method is based upon the ASCII code.Appendix 3 of your book shows the ACII character set.Individual characters in a string are encoded using this system. For example, the letter "A" isencoded using the number 65 and "B" is encoded using the number 66.
Your enemy's secret code takes each letter of the message and encrypts it as follows:
If(OriginalChar + Key > 126) then EncryptedChar = 32 + ((OriginalChar + Key ) - 127)
else EncryptedChar = (OriginalChar + Key)
For example, if the enemy used Key=10 then the message "Hey" would be encrypted as:
Character | ASCII Code |
H | 72 |
e | 101 |
y | 121 |
Encrypted H = (72 + 10) = 82 = R in ASCII
Encrypted e = (101 + 10) = 111 = o in ASCII
Encrypted y = (121 + 10) - 127 = 36 = $ in ASCII
Consequently, "Hey" would be transmitted as "Ro$".
Write a program that decrypts the intercepted message.You only know that the key used is a number between 1 and 100.Your program should try to decodethe message using all possible keys between 1 and 100.When you try the valid key, the message will make sense.For all other keys the message willappear as gibberish.
Use C++-Strings for this assignment.
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char * argv[])
{
string decryptedString(const string&secret, int key);
string secretMsg = ":mmZ\dxZmx]Zpgy";
for (int key = 1; key < 101; ++key)
{
cout << "Key " << key << " - "
<< decryptedString(secretMsg, key)
<< endl;
}
//if none were decrypted sucessfully or no decrypted string have meaning, update the filter
//FOUND @key88: "Attack at dawn!"
cout << endl;
cin.get();
return 0;
}
//---------------------------------------------------------
bool filter(const char &chr)
{
return (toupper(chr) >= 'A' &&toupper(chr) <= 'Z') || //a-z A-Z
(chr >= '0' &&chr <= '9')|| //0-9
(chr == ' ' || chr == 't' || chr == 'n') || //white spaces
(chr == ',' || chr == '.'|| //punctuations
chr == ':' || chr == ';' ||
chr == ''' || chr == '"' ||
chr == '?' || chr == '!');
}
//---------------------------------------------------------
string decryptedString(const string&secret, int key)
{
string decoder = "";
for (int i = 0; i < secret.length(); i++)
{
if (filter(secret[i] - key))
decoder += secret[i] - key;
else if (filter(secret[i] - key + 127 - 32))
decoder += secret[i] - key + 127 - 32;
}
if (decoder.length() == secret.length()) //All encrypted chars must be decrypted
return decoder;
return decoder = "";
}
//------------------------OUTPUT-----------------------
Key 1 -
Key 2 -
Key 3 - 7jjWYauWjuZWmdv
Key 4 -
Key 5 -
Key 6 -
Key 7 -
Key 8 -
Key 9 -
Key 10 -
Key 11 -
Key 12 -
Key 13 -
Key 14 -
Key 15 -
Key 16 -
Key 17 -
Key 18 -
Key 19 -
Key 20 -
Key 21 -
Key 22 -
Key 23 -
Key 24 -
Key 25 -
Key 26 -
Key 27 -
Key 28 -
Key 29 -
Key 30 -
Key 31 -
Key 32 -
Key 33 -
Key 34 - wKK8:BV8KV;8NEW
Key 35 - vJJ79AU7JU:7MDV
Key 36 -
Key 37 - tHH57?S5HS85KBT
Key 38 -
Key 39 -
Key 40 -
Key 41 -
Key 42 -
Key 43 -
Key 44 - mAA.08L.AL1.D;M
Key 45 -
Key 46 -
Key 47 -
Key 48 -
Key 49 -
Key 50 -
Key 51 -
Key 52 -
Key 53 -
Key 54 -
Key 55 -
Key 56 -
Key 57 -
Key 58 -
Key 59 -
Key 60 -
Key 61 -
Key 62 -
Key 63 -
Key 64 -
Key 65 -
Key 66 -
Key 67 -
Key 68 -
Key 69 -
Key 70 -
Key 71 -
Key 72 -
Key 73 -
Key 74 -
Key 75 -
Key 76 -
Key 77 -
Key 78 -
Key 79 -
Key 80 -
Key 81 -
Key 82 -
Key 83 -
Key 84 -
Key 85 -
Key 86 -
Key 87 - Buubdl!bu!ebxo"
Key 88 - Attack at dawn!
Key 89 -
Key 90 -
Key 91 -
Key 92 -
Key 93 -
Key 94 -
Key 95 -
Key 96 -
Key 97 -
Key 98 - 7jjWYauWjuZWmdv
Key 99 -
Key 100 -
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...
Q16-Decoder (0.5 points) Write a code block to decode strings from secret encodings back to readable messages. To do so: Initialize a variable called decoded as an empty string . Use a for loop to loop across all characters of a presumed string variable called encoded Inside the loop, convert the character to another character o Get the unicode code point for the character (using ord o Subtract the value of key to that code point (which should be an...
Use C++
forehand e receiver creates a public key and a secret key as follows. Generate two distinct primes, p andq. Since they can be used to generate the secret key, they must be kept hidden. Let n-pg, phi(n) ((p-1)*(q-1) Select an integer e such that gcd(e, (p-100g-1))-1. The public key is the pair (e,n). This should be distributed widely. Compute d such that d-l(mod (p-1)(q-1). This can be done using the pulverizer. The secret key is the pair (d.n)....
1. Write a C++ program called Password that handles encrypting a
password.
2. The program must perform encryption as follows:
a. main method
i. Ask the user for a password.
ii. Sends the password to a boolean function called
isValidPassword to check validity.
1. Returns true if password is at least 8 characters long
2. Returns false if it is not at least 8 characters long
iii. If isValidPassword functions returns false
1. Print the following error message “The password...
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...
Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...
C++ please
Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....
Lab #10 C++ Write a C++ program that reads text from a file and encrypts the file by adding an encryption factor (EF) to the ASCII value of each character. The encryption factor is 1 for the first line and increases by 1 for each line up to 4 and then starts over at 1. So, for the 4 th line the EF is 4, for the 5th line it is 1, for the 10th line it is 2. In...
"For two thousand years, codemakers have fought to preserve secrets while codebreakers have tried their best to reveal them." - taken from Code Book, The Evolution of Secrecy from Mary, Queen of Scots to Quantum Cryptography by Simon Singh.The idea for this machine problem came from this book.You will encrypt and decrypt some messages using a simplified version of a code in the book. The convention in cryptography is to write the plain text in lower case letters and the encrypted text in upper case...
Cipher Program Specifications: You are to write a program called, "Cipher123" that reads in an encoded message using the 1-2-3 cipher and returns the decoded message. The program should continue prompting for additional encoded messages until the user chooses to quit the program. When decoding a message, we take the first letter of the first word, the second letter of the second word and the third letter of the third word and concatenate them. We repeat this same process 1-2-3...