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 accepts two integers from the user and perform one of the four arithmetic operations based on user’s choice
madam [21]

Answer:

am i to late or do you still need the answer?

Explanation:

3 0
2 years ago
What is malware? What are some signs that malware may be impacting the performance of your computer? How can you avoid malware?
Anni [7]

Answer:

Malware is a type of software that is specifically designed to disrupt, damage, or gain unauthorized access to a computer system. Malware can be spread through email attachments, online advertisements, websites, and other methods.

Some signs that malware may be impacting the performance of your computer include:

  • Your computer is running more slowly than usual
  • Your computer crashes frequently
  • Your computer has pop-up ads or other unwanted behavior
  • Your default homepage or search engine has changed without your permission
  • You see new icons or programs on your desktop that you didn't install

To avoid malware, you should be cautious when browsing the internet and avoid visiting suspicious websites. You should also avoid opening email attachments from unknown senders, and be wary of online advertisements. You can also protect your computer by using antivirus software and keeping it up to date.

3 0
1 year ago
What is a sensitive compartmented information program
Dahasolnce [82]

Answer:

cpu

Explanation:

4 0
3 years ago
which of the following peripheral does not belong to a group: A) Monitor B) Printer C) Hardware D) Keyboard​
nikdorinn [45]
C hardware is the correct answer
5 0
3 years ago
Microsoft word is an example of utility software? <br><br>A.true <br>B.false​
monitta

Answer:

false

Explanation:

Ms word is only an application software

7 0
2 years ago
Read 2 more answers
Other questions:
  • Please helpp!! I need it quickly!
    6·1 answer
  • Your friend sees an error message during Windows startup about a corrupted bootmgr file. He has another computer with a matching
    12·1 answer
  • According to the author, there are five hedging strategies organizations can pursue. One of them is: Select one: a. commit with
    5·1 answer
  • Computer is created by aliens?!
    14·1 answer
  • What will be the output of the following code? &lt;?php $foo = 'Bob'; $bar = $foo; $bar = "My name is $bar"; print $bar; print $
    8·2 answers
  • A model is replica that?
    11·2 answers
  • Plzz help.... <br><br>i will mark u as brainliest if u answer correct
    10·1 answer
  • Briefly explain how Riboflavin deficiency lead to disease state.​
    15·1 answer
  • Question 1 (1 point)
    9·1 answer
  • Different the policies and protocols in the industry
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!