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
An app builder wants to show groups as the last navigation menu item in the Salesforce1 mobile app. However, the app builder is
tatyana61 [14]

Answer:

Option B is the correct answer.

Explanation:

Because of an app builder and they need to display the groups as the final menu items of the navigation in the software of the mobile. Then, they unable to select those groups in which the items list on the menu. So, that's why the following groups are not in the list of the selected navigation menu.

Other option is not true because they are not according to the following statement.

8 0
2 years ago
Which way do you swipe in ios to get to the control center
Korvikt [17]

Answer:

Swipe down in the right corner or for older versions swipe from bottom

Explanation:

6 0
2 years ago
Which of the following is a type of monitor port?
Soloha48 [4]
B. all of those.

just to clarify,
HDMI is the port for monitor and sound.

VGA is for video/monitor port
and display port.... I don't know, but it's a type of monitor port.
7 0
3 years ago
2.1 Changes in which factors could cause aggregate demand to shift from AD to AD1? What could happen to the unemployment rate? W
katrin [286]

Answer:

There are many factors that cause aggregate demand to shift from AD to AD1. The unemployment rate will fall and inflation will increase.

<u>Explanation:</u>

A Shift in aggregate demand from AD to AD1 means there has been a  fall in demand. Various factors that cause demand to decrease are:

  1. Increase in price of a good itself
  2. Increase in the price of complimentary goods-This will lead to a fall in demand. Like ink and pen are complementary goods. if the Price of ink increases then demand for pen will decrease.
  3. A Decrease in the price of substitute goods-Like tea and coffee.
  4. Expectation regarding future fall in price

So due to the decrease in demand finally the unemployment will increase and with that, the inflation rate will increase making  things dearer.

3 0
3 years ago
The following equations estimate the calories burned when exercising (source): Men: Calories = ( (Age x 0.2017) — (Weight x 0.09
sammy [17]

In python:

age = float(input("How old are you? "))

weight = float(input("How much do you weigh? "))

heart_rate = float(input("What's your heart rate? "))

time = float(input("What's the time? "))

print("The calories burned for men is {}, and the calories burned for women is {}.".format(

   ((age * 0.2017) - (weight * 0.09036) + (heart_rate * 0.6309) - 55.0969) * (time / 4.184),

   ((age * 0.074) - (weight * 0.05741) + (heart_rate * 0.4472) - 20.4022) * (time / 4.184)))

This is the program.

When you enter 49 155 148 60, the output is:

The calories burned for men is 489.77724665391963, and the calories burned for women is 580.939531548757.

Round to whatever you desire.

6 0
3 years ago
Other questions:
  • WHAT SHOULD YOU DO IF AN ONCOMING CAR AT NIGHT APPROACHES WITH ITS HIGH-BEAMS ON?
    6·1 answer
  • The _______ has shortcuts to commonly used commands
    8·2 answers
  • The section called Breaking Substitution Ciphers (p. 166) describes a "random substitution cipher," in which each letter of the
    11·1 answer
  • Design and implement your own simple class to represent any household item of your choice (toaster, fan, hair dryer, piano ...)
    11·1 answer
  • __________ involves determining what qualities are to beused to perform project activities.
    9·1 answer
  • What is displayed on the console when running the following program? class Test { public static void main(String[] args) { try {
    10·1 answer
  • The road is closed a head
    9·1 answer
  • What are the services offered by web-based email?​
    12·1 answer
  • Direction: Read each item carefully and choose the letter of the correct answer. Write your answers on a separate sheet of paper
    12·1 answer
  • The function that overloads the ____ operator for a class must be declared as a member of the class.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!