Question

Explaination on how the decryption of the vignere cipher works.        String d_result = "";...

Explaination on how the decryption of the vignere cipher works.

       String d_result = "";

       str = str.toUpperCase();

       for(int i = 0, j = 0; i < str.length(); i++)

       {

           char c = str.charAt(i);

           if(c < 'A' || c >'Z')

               continue;

           result += (char)((c - k.charAt(j)+ 26)% 26 + 'A');

           j = ++j % k.length();

       }

       return d_result;

   }

0 0
Add a comment Improve this question Transcribed image text
Answer #1


       String d_result = "";

       str = str.toUpperCase();//String value is converted into upper case
//here loop converts takes encrypted text and converts it into original text using key value.

       for(int i = 0, j = 0; i < str.length(); i++)
//The below defined for loop process each and every character in the encrypted text
//until the entire string is converted to its original form.
       {
//These lines takes each character of the encrypted text at a time and check if it lies between the ascii
//range of character 'A' and 'Z'. Characters are only processed if the character lies in the range,
//else we move on to process next character of the encrypted text.
           char c = str.charAt(i);

           if(c < 'A' || c >'Z')

               continue;
//The encrypted character is converted to the original character using the formula that uses the key value.
// The next character of the key value is obtained by using modulus operator that repeats the characters of
//the key so that its total length is equal to that of the original text.

           result += (char)((c - k.charAt(j)+ 26)% 26 + 'A');

           j = ++j % k.length();

       }
//returns the plain text.
       return d_result;

   }

Add a comment
Know the answer?
Add Answer to:
Explaination on how the decryption of the vignere cipher works.        String d_result = "";...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two...

    Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two functions: encryption and decryption. 2. Use any key you like. (Don't use deceptive in the slides) 3. choose a sentence or a paragraph you like as the plaintext. I have the code I just need the implementation in a different way // C++ code to implement Vigenere Cipher #include<bits/stdc++.h> using namespace std; // This function generates the key in // a cyclic manner until...

  • ​​​​​​public static int countCharacter(String str, char c) { // This recursive method takes a String and...

    ​​​​​​public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...

  • USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is...

    USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...

  • Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void...

    Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void messageAndKey(){ string msg; cout << "Enter message: "; getline(cin, msg); cin.ignore(); //message to uppercase for(int i = 0; i < msg.length(); i++){ msg[i] = toupper(msg[i]); } string key; cout << "Enter key: "; getline(cin, key); cin.ignore(); //key to uppercase for(int i = 0; i < key.length(); i++){ key[i] = toupper(key[i]); } //mapping key to message string keyMap = ""; for (int i = 0,j...

  • In C++ Write a program that will read a string, call 2 functions to modify the...

    In C++ Write a program that will read a string, call 2 functions to modify the string, and then print the final result. The first function should take a string parameter and return the string without any vowels. The second function should take a string and double every letter (which should be all consonants at this point). Be sure to: You must use more than [ ] and at You must use erase, insert, replace, find, and/or substr to make...

  • Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message...

    Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message The code: #include<stdio.h> #include <stdlib.h> char arr[26][26]; char message[22], key[22], emessage[22], retMessage[22]; int findRow(char); int findColumn(char); int findDecRow(char, int); int main() { int i = 0, j, k, r, c; k = 96; for (i = 0; i<26; i++) { k++; for (j = 0; j<26; j++) { arr[i][j] = k++; if (k == 123) k = 97; } } printf("\nEnter message\n"); fgets(message, 22,...

  • ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName)...

    ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...

  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • Explain in detail what the code below does: public class MyClass {       public static void...

    Explain in detail what the code below does: public class MyClass {       public static void main(String args[]) {              System.out.println(isUniqueChars("something"));       }       public static boolean isUniqueChars(String str) {             int checker = 0;                                                                                               for (int i = 0; i < str.length(); ++i) {                         int val = str.charAt(i) - 'a';                         if ((checker & (1 << val)) > 0) return false;                         checker |= (1 << val);             }             return true;...

  • Write a program that replace repeated three characters in a string by the character followed by 3...

    Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT