1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
goldenfox [79]
3 years ago
13

Write a function to compute the Affine cipher. The input parameters for the function will be a, b, m and the plaintext. The func

tion will return the ciphertext. This function should check to make sure that a and m are relatively prime (by calling the function above). If not, it should return a blank string.
Computers and Technology
1 answer:
Anettt [7]3 years ago
8 0

Answer:

//CPP program to illustate Affine Cipher  

 

#include<bits/stdc++.h>  

using namespace std;  

 

//Key values of a and b  

const int a = 17;  

const int b = 20;  

 

string encryptMessage(string msg)  

{  

   ///Cipher Text initially empty  

   string cipher = "";  

   for (int i = 0; i < msg.length(); i++)  

   {  

       // Avoid space to be encrypted  

       if(msg[i]!=' ')  

           /* applying encryption formula ( a x + b ) mod m  

           {here x is msg[i] and m is 26} and added 'A' to  

           bring it in range of ascii alphabet[ 65-90 | A-Z ] */

           cipher = cipher +  

                       (char) ((((a * (msg[i]-'A') ) + b) % 26) + 'A');  

       else

           //else simply append space character  

           cipher += msg[i];      

   }  

   return cipher;  

}  

 

string decryptCipher(string cipher)  

{  

   string msg = "";  

   int a_inv = 0;  

   int flag = 0;  

     

   //Find a^-1 (the multiplicative inverse of a  

       //in the group of integers modulo m.)  

   for (int i = 0; i < 26; i++)  

   {  

       flag = (a * i) % 26;  

         

       //Check if (a*i)%26 == 1,  

               //then i will be the multiplicative inverse of a  

       if (flag == 1)  

       {  

           a_inv = i;  

       }  

   }  

   for (int i = 0; i < cipher.length(); i++)  

   {  

       if(cipher[i]!=' ')  

           /*Applying decryption formula a^-1 ( x - b ) mod m  

           {here x is cipher[i] and m is 26} and added 'A'  

           to bring it in range of ASCII alphabet[ 65-90 | A-Z ] */

           msg = msg +  

                      (char) (((a_inv * ((cipher[i]+'A' - b)) % 26)) + 'A');  

       else

           //else simply append space characte  

           msg += cipher[i];  

   }  

 

   return msg;  

}  

 

//Driver Program  

int main(void)  

{  

   string msg = "AFFINE CIPHER";  

     

   //Calling encryption function  

   string cipherText = encryptMessage(msg);  

   cout << "Encrypted Message is : " << cipherText<<endl;  

     

   //Calling Decryption function  

   cout << "Decrypted Message is: " << decryptCipher(cipherText);  

 

   return 0;  

}  

You might be interested in
Write a program that passes an unspecified number of integers from command line and displays their total.
Svetradugi [14.3K]

Answer:

Explanation:

I will go straight to the code, and hope it didn't confuse you.

Here is it

public static void main(String[] args)

int [] x = new int [args.length]

for (int y = 0; y< args.length;yi++)

int[y] = (int) args [y]

5 0
3 years ago
n macOS, what launch point provides access to almost all the settings needed to administer a macOS system?
Fynjy0 [20]

Answer:

System preferences.

Explanation:

MacOS is the primary operating system designed and developed for Apple computers (MacBook).

In macOS, system preferences is a launch point that provides access to almost all the settings needed to administer a macOS system. The system preferences allow users to change various settings on their Mac computers such as changing the desktop layout, desktop picture (wallpaper), size and location of the dock, font size, appearance, energy saver etc.

5 0
3 years ago
Query: [mcdonalds Austin] Viewport: Fresh User Location: within Houston, TX Result Returned: McDonalds location in a neighboring
son4ous [18]

Answer:

The answer is "Option d"

Explanation:

Description to this query can be defined as follows:

  • All of the three (User location, Location modifier, and viewport) are used to identify range demotions.
  • The Viewport, the new user location in Houston, is a McDonald's address query, where the user looks for the exact location of McDonald's in the area of Austin.  
  • The location modifier and viewport are used to calculate the distance of the demotions Client position.
8 0
3 years ago
From the binary search algorithm, it follows that every iteration of the while loop cuts the size of the search list by half.
Colt1911 [192]

Answer:

True: In binary search algorithm, we follow the below steps sequentially:

Input: A sorted array  B[1,2,...n] of n items and one item x to be searched.

Output: The index of x in B if exists in B, 0 otherwise.

  1. low=1
  2. high=n
  3. while( low < high )
  4.  {      mid=low + (high-low)/2
  5.         if( B[mid]==x)
  6.          {
  7.             return(mid)  //returns mid as the index of x
  8.           }
  9.          else
  10.          {
  11.              if( B[mid] < x)      //takes only right half of the array
  12.               {
  13.                 low=mid+1
  14.               }
  15.              else               // takes only the left half of the array
  16.               {
  17.                high=mid-1
  18.               }
  19.           }
  20.  }
  21. return( 0 )

Explanation:

For each iteration the line number 11 or line number 15 will be executed.

Both lines, cut the array size to half of it and takes as the input for next iteration.

6 0
3 years ago
Laura is confused with the spelling of the word pronunciation. She types the word as pronounciation throughout a document. Which
Ivan

Not really is she wants the words that she's typing down sometimes it's not necessary to leave it to the auto correct It can always be bad when re-reading it again.

5 0
2 years ago
Other questions:
  • The number of credits awarded for the CLEP exam is determined by__<br> Help pls!
    15·1 answer
  • Write a program that converst the temperature from Celcius to Fahrenheit. The formula is: F (9/5)C+32
    12·2 answers
  • list six external parts or peripherals of a computer system and identify which are output and which are input devices
    8·1 answer
  • A corporation needs an operating system that allows the various teams in its office to network and collaborate on projects. Whic
    10·1 answer
  • HELP PLZ !!
    13·1 answer
  • Voice authentication requires speech to text capability Facial recognition may be used for authentication The human iris is uniq
    6·1 answer
  • How do you change your grade level
    10·1 answer
  • My phone takes forever to load the ads, does anyone else have this problem? Is there a way to fix it? I’ve tried getting another
    12·2 answers
  • HELLLLLLLLPPPPPPPPPPPP HHHHHHHHHEEEEEEEEELLLLLLPPPPPP MEEEEEEEE
    12·2 answers
  • What is the difference between PowerPoint and Outlook?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!