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
Earthquakes _____.
rosijanka [135]
<span>B: can be caused by volcanic eruptions</span>
7 0
3 years ago
Read 2 more answers
What are the responsibilities of the DBA and the database designers?
Ratling [72]

Answer:

Explanation:

DBA's main responsibility is making sure that there is enough CPU, disk, memory, and network bandwidth available, as well as making backups every so often. Meanwhile, the database designers/developers are responsible for investigating and implementing what the end-user needs and making sure that the database holds all of the information that the end-user will be using.

3 0
3 years ago
You can use any font when creating your website as all users can see the same fonts.
Anastaziya [24]
False, think about the people with low vision. Think about the font and what size it would have to be,the color (ex. yellow would not be good), Spacing, tracking etc. Just a few things to consider.
3 0
3 years ago
What does it NOT mean for something to be open source?
Readme [11.4K]

Answer:

Free to use but you have to pay a fee to modify

Explanation:

You NEVER have to pay for OPEN SOURCE

5 0
3 years ago
Which of the following is your personal record of payments and bill-paying?
oksian1 [2.3K]

Answer:

I believe its a statement

Explanation:

4 0
3 years ago
Other questions:
  • One main advantage of CD-ROMs is that
    14·1 answer
  • When you “listen” to evaluate an online message, which question should you ask?
    11·1 answer
  • As an ICT student teacher using convincing and cogent reasons explain why you think operating system is pivotal in teaching and
    7·1 answer
  • What are the examples of personal computers ?
    8·1 answer
  • What manages and control the speed of a motherboards buses
    5·1 answer
  • What is the atomic number of neonWhat do the following results from the TEST FOR LIFE tab indicate about the sample
    15·1 answer
  • What is a header row?
    8·1 answer
  • How to install an older version of prettier on yarn
    9·1 answer
  • Q) Look at the code sequence and select the correct output
    14·1 answer
  • How do I delete my Brainly account?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!