Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Check what is wrong with my Affine Function Encryption c++ program? (im very clo

ID: 3763840 • Letter: C

Question

Check what is wrong with my Affine Function Encryption c++ program? (im very close)

ok so for some reason it keeps giving me encryptions that ignore the adding by 2 part

for example i enter "hello" and it encrypts to "xojjs" but the answer should be "zqllu" hence the letters are two positions behind

cout << "You chose Affine Cipher " << endl;
       string message, encryption;
       int a = 3;
       int b = 2;
       cout << "Enter a message and press enter to encrypt it(no spaces)" << endl;
       cin >> message;
       cout<<"***Encrypting with a key of 3x+2***" << endl;
       for(int i = 0; i < message.length(); i++) {
           message[i]= message[i]-97;
           message[i] = (char)((a*message[i]+b) % 26) +97;
       }
       cout << " The encrypted message is: ";
       for (int i=0; i<message.length(); i++) {
           encryption += message[i];
   }
       cout << encryption << endl;

Explanation / Answer

Program is completely correct. The output that you are getting with 3x + 2 is correct, the output that you are talking about ("zqllu") will come from eqn 3x + 4.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote