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
Net Worth is equal to assets minus liabilities. Which event will have the greatest impact (positive or negative) on one's net wo
kolezko [41]
The answer would be: Go on a vacation that costs $3,500 

Paying off money for buying a car will not decrease your net worth as you get the car as assets for the money you use. But the depreciates 20% will cause you to lose $3,000 assets. Assuming you are not buying assets at all, go on a vacation that costs $3,500 will increase liability without any effect on assets. Paying up bills will decrease your asset but it also decreases your liability so the net worth wouldn't change. 
7 0
3 years ago
Durante 10s, la velocidad de rotación y el momento de giro de las ruedas de un coche eléctrico son 100 rpm y 1405,92 Nm, respect
Akimi4 [234]

Answer:

c

Explanation:

hope this helps

6 0
3 years ago
What happens if part of an ftp message is not delivered to the destination?
Oliga [24]

The message is lost when an FTP message is not delivered to its destination because FTP doesn't use a reliable delivery method.

<h3>What is FTP?</h3>

FTP is an abbreviation for file transfer protocol and it can be defined as a type of server that's designed and developed to store and provide files for download, as well as sharing between two or more users on an active computer network.

Generally, the message is lost when an FTP message is not delivered to its destination because FTP doesn't use a reliable delivery method.

Read more on FTP here: brainly.com/question/20602197

#SPJ12

4 0
2 years ago
What is incorrect about the following code? Suggest a possible revision of the code to correct the error.
Ad libitum [116K]
This is really cool but no one cares
5 0
2 years ago
Which of the following activities are performed by computer programmers? Choose all that apply.
AleksAgata [21]

Answer:

- They write step by step instructions for a computer to follow.

- They create a logic problem that the computer program can solve.

3 0
3 years ago
Other questions:
  • Which of the following can be sources of sediment? A. fragments of other rocks B. chemicals and minerals dissolved in water C. s
    11·1 answer
  • What are multiple worksheets
    7·1 answer
  • Can a computer will work more efficiently if you perform disk optimization
    9·1 answer
  • If the base-10 system stops with the<br> number 9, then why isn't it called<br> base-9?
    15·1 answer
  • My speaker on my phone is not working, when I try and play music and videos the sound dosen't work. However my alarm works. Can
    9·2 answers
  • List the components of a typical operating system and summarize the role of each in a single phrase.
    6·1 answer
  • Simple interest will always pay more interest than compound interest.
    14·1 answer
  • 2. Which of the following is a shortcut key to Exit from any operation?
    10·2 answers
  • Magnetic video tape in a plastic casing is a?
    13·1 answer
  • WILL GIVE BRAINLIEST!! NO LINKS!!!
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!