From 52b1ca3e7a4e8da580df693cf69129e832cea5e8 Mon Sep 17 00:00:00 2001 From: sushantfaujdar <112813616+sushantfaujdar@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:15:50 +0530 Subject: [PATCH 1/2] Create Ass2.cpp --- Assignment 2/211085_sushant/Ass2.cpp | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Assignment 2/211085_sushant/Ass2.cpp diff --git a/Assignment 2/211085_sushant/Ass2.cpp b/Assignment 2/211085_sushant/Ass2.cpp new file mode 100644 index 0000000..83927eb --- /dev/null +++ b/Assignment 2/211085_sushant/Ass2.cpp @@ -0,0 +1,80 @@ +#include +#include +#include + +using namespace std; + +int main() { + string cipherText = "qmnjvsa nv wewc flct vprj tj tvvplvl fv xja vqildhc " + "xmlnvc nacyclpa fc gyt vfvw. fv wgqyp, pqq pqcs y wsq " + "rx qmnjvafy cgv tlvhf cw tyl aeuq fv xja tkbv cqnsqs. " + "lhf avawnc cv eas fuqb qvq tc yllrqr xxwa cfy. psdc uqf " + "avrqc gefq pyat trac xwv taa wwd dv eas flcbq. vd trawm " + "vupq quw x decgqcwt, yq yafl vlqs yqklhq! snafq vml " + "lhvqpawr nqg_vfusr_ec_wawy qp fn wgawdgf."; + + string decryptedText; + int index = 0; + while (index < cipherText.length()) { + char characters[5]; + string interstitials[5]; + for (int curIndex = 0; curIndex < 5; curIndex++) { + if (isalpha(cipherText[index])) { + characters[curIndex] = cipherText[index]; + // Take all the non-letters with it too + while (!isalpha(cipherText[index + 1]) && index < cipherText.length() - 1) + interstitials[curIndex] += cipherText[++index]; + } + index++; + } + // Concatenate in new order + decryptedText += characters[3] + interstitials[0] + characters[2] + interstitials[1] + + characters[4] + interstitials[2] + characters[0] + interstitials[3] + characters[1] + interstitials[4]; + } + + cipherText = decryptedText; + string substitutionRules[] = { "Ow", "Aq", "Ta", "Sl", "Ph", "Ev", "Hf", "Gg", "Ud", "Rn", "Km", "Wr", "Dp", "Ic", "Ny", "Bj", + "Fs", "Ce", "Lt", "Yx", "Qi", "Mu", "Jk", "Vb" }; + + for (string rule : substitutionRules) { + size_t pos = cipherText.find(rule[1]); + while (pos != string::npos) { + cipherText.replace(pos, 1, string(1, rule[0])); + pos = cipherText.find(rule[1], pos + 1); + } + } + + // Print + int position = 0; + bool afterFullStop = false; + bool replaceSpaces = false; + for (char c : cipherText) { + if (!isalpha(c)) { + if (afterFullStop) { + cout << c; + } else { + if (c == '.') { + afterFullStop = true; + replaceSpaces = true; + } else if (c == '_') { + cout << ' '; + } else { + if (replaceSpaces) { + cout << " " << c; + replaceSpaces = false; + } else { + cout << c; + } + } + } + continue; + } + cout << c; + position++; + if (position == 5) { + position = 0; + } + } + + return 0; +} From 2285d2f36261592dd9be1d123162259a412c1ae9 Mon Sep 17 00:00:00 2001 From: sushantfaujdar <112813616+sushantfaujdar@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:16:12 +0530 Subject: [PATCH 2/2] Create README.md --- Assignment 2/211085_sushant/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Assignment 2/211085_sushant/README.md diff --git a/Assignment 2/211085_sushant/README.md b/Assignment 2/211085_sushant/README.md new file mode 100644 index 0000000..7af2dc2 --- /dev/null +++ b/Assignment 2/211085_sushant/README.md @@ -0,0 +1 @@ +BREAKER OF THIS CODE WILL BE BLESSED BY THE SQUEAKY SPIRIT RESIDING IN THE HOLE GO AHEAD, AND FIND A WAY OF BREAKING THE SPELL ON HIM CAST BY THE EVIL JAFFAR. THE SPIRIT OF THE CAVE MAN IS ALWAYS WITH YOU. FIND THE MAGIC WAND THAT WILL LET YOU OUT OF THE CAVES. IT WOULD MAKE YOU A MAGICIAN, NO LESS THAN JAFFAR! SPEAK THE PASSWORD THE_MAGIC_OF_WAND TO GO THRHGTO.U