CODING IN C++ Type of Cipher is Simple Substitution Write a script to apply the
ID: 3746828 • Letter: C
Question
CODING IN C++
Type of Cipher is Simple Substitution
Write a script to apply the right form of cryptoanalysis able to disclose the plaintext of the text below. Hint: it's the lyrics of a song. FCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKF CGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFC GUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCG UNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGU NKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUN KBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNK BHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKB HEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBH EJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHEJGCLKFCGUNKBHE JGCLKFCGUNKBHEJGCLKExplanation / Answer
#include <cctype>
#include <string>
#include <iostream>
using namespace std;
void decrypt(char * input, unsigned int offset) {
for (int i = 0; input[i] != 0; i++) {
// Skip spaces...
if (input[i] == ' ')
continue;
char firstLetter = islower(input[i]) ? 'a' : 'A';
unsigned int alphaOffset = input[i] - firstLetter;
int newAlphaOffset = alphaOffset - offset;
if (newAlphaOffset < 0) {
newAlphaOffset += 26;
}
input[i] = firstLetter + (newAlphaOffset % 26);
}
}
int main()
{
std::string alphabeticalString = "acbdefghijklmnopqrstuvwxyz";
unsigned int encryptionOffset;
cout << "Please enter a Text to Decrypt : ";
cin >> alphabeticalString;
cout << "Please enter a offset level of decryption: range from 1 to 25 ";
cin >> encryptionOffset;
decrypt(const_cast<char*>(alphabeticalString.c_str()), encryptionOffset);
cout << "" in: "" << alphabeticalString << """ << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.