Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN ANYONE TRANSLATE THIS CODE INTO JAVA? I believe it is C++ not sure. //source code for given problem #include using namespace std; //Key values

CAN ANYONE TRANSLATE THIS CODE INTO JAVA? I believe it is C++ not sure.

//source code for given problem #include using namespace std; //Key values of a and b const int a = 7; const int b = 3; 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) { //give your required string4 here to encrypt string msg = "FINAL STRING 4"; //Calling encryption function //here give your text to be decrypted string cipherText = "FIGSD RSFYHG ESXTSDJJHQT HQ ODUD HZ MNQ DQY TXXY MXS JP TSDYF"; cout << "Encrypted Message is : " << cipherText<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

ISBN: 1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

3. You can gain power by making others feel important.

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago