From b79c763c27e4c4a0c380d8a03b1d54633ae6006e Mon Sep 17 00:00:00 2001 From: Jyotiraditya Barsain Date: Thu, 13 Jul 2023 21:52:53 +0530 Subject: [PATCH] Files Added --- Assignment 1/210479/code.cpp | 29 ++++++++++++ Assignment 1/210479/readme.md | 8 ++++ Assignment 2/210479/code1.cpp | 83 ++++++++++++++++++++++++++++++++++ Assignment 2/210479/readme1.md | 3 ++ 4 files changed, 123 insertions(+) create mode 100644 Assignment 1/210479/code.cpp create mode 100644 Assignment 1/210479/readme.md create mode 100644 Assignment 2/210479/code1.cpp create mode 100644 Assignment 2/210479/readme1.md diff --git a/Assignment 1/210479/code.cpp b/Assignment 1/210479/code.cpp new file mode 100644 index 0000000..0f363d6 --- /dev/null +++ b/Assignment 1/210479/code.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +string encrypt(string text, string key) { + string encryptedText = ""; + int keyIndex = 0; + for (int i = 0; i < text.length(); i++) { + if (isalpha(text[i])) { + char base = isupper(text[i]) ? 'A' : 'a'; + char encryptedChar = (text[i] - base + key[keyIndex % key.length()] - 'a' + 1) % 26 + base; + encryptedText += encryptedChar; + keyIndex++; + } + else { + encryptedText += text[i]; + } + } + return encryptedText; +} + +int main() { + string input = "tbzvoclymifqef, kdr jriq ioklzbwbf, vzqgdgu iurqqivajp, fvsqpqket fwb wesmieqdnnab hfeotp qw rzroaggudk. afhd hhkcye, nlwi eqabpkyqhp rleejfv fs wclycrpvb, ceq kdrt laipsgivzv agkrdbfprgudk jriq abf pbg il vyve blovaf, iekj txdokfhe blovaf dc vivgbmj. pbgg hgp ga hrevfe pkf kuq exujjaga kj gtt_cwe_umh_lpcl_ntdwe."; + string key = "imnkcx"; + + string encryptedText = encrypt(input, key); + cout << encryptedText << endl; + +    return 0; +} \ No newline at end of file diff --git a/Assignment 1/210479/readme.md b/Assignment 1/210479/readme.md new file mode 100644 index 0000000..b1a0656 --- /dev/null +++ b/Assignment 1/210479/readme.md @@ -0,0 +1,8 @@ +**Title:** Vigenère Cipher Triumph + +--- + +**Description:** +In this example, we encounter a Vigenère cipher, a polyalphabetic substitution cipher that employs a varying shift for each character. Our task is to decipher the encoded message and uncover the key used for encryption. To accomplish this, we investigate the website google.com, specifically focusing on the "I'm Feeling Lucky" button. After several attempts, we discover the key "rnmpx" within the division class of this button. + +After unraveling the encryption, we unveil the final password: "congratulations, you have triumphed, emerged victorious, defeating the unfathomable forces of encryption. your skills, your relentless pursuit of knowledge, and your unwavering determination have led you to this moment, this glorious moment of triumph. your key to success and the password is the_fun_has_only_begun." \ No newline at end of file diff --git a/Assignment 2/210479/code1.cpp b/Assignment 2/210479/code1.cpp new file mode 100644 index 0000000..6512fdb --- /dev/null +++ b/Assignment 2/210479/code1.cpp @@ -0,0 +1,83 @@ +#include +#include + +using namespace std; + +string decryptText(const string& cipherText) { + 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]; + } + + 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 = decryptedText.find(rule[1]); + while (pos != string::npos) { + decryptedText.replace(pos, 1, string(1, rule[0])); + pos = decryptedText.find(rule[1], pos + 1); + } + } + + return decryptedText; +} + +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 = decryptText(cipherText); + + int position = 0; + bool afterFullStop = false; + bool replaceSpaces = false; + for (char c : decryptedText) { + 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; +} \ No newline at end of file diff --git a/Assignment 2/210479/readme1.md b/Assignment 2/210479/readme1.md new file mode 100644 index 0000000..e910a63 --- /dev/null +++ b/Assignment 2/210479/readme1.md @@ -0,0 +1,3 @@ +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 + +