Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert this C++ code to Java code this code is to encrypt and decrypt strings of characters using Caesar cipher please attach samples run of

Convert this C++ code to Java code

this code is to encrypt and decrypt strings of characters using Caesar cipher

please attach samples run of the code

#include #include #include #include #include

#define MAX_SIZE 200

void encrypt_str(char xyz[], int key); // Function prototype for the function to encrypt the input string. void decrypt_str(char xyz[], int key); // Function prototype for the function to decrypt the encrypted string.

using namespace std;

int main() { char input_str[MAX_SIZE]; int shift = 6; // This is the Caesar encryption key... You can change it to whatever value you wish!

system("cls"); // System call to clear the console screen!

cout<<" Enter the string to be encrypted :\t"; gets(input_str); // Getting the user to input the string to be encrypted!

cout<<" Original string:\t" << input_str;

// Function call to encrypt the input string encrypt_str(input_str, shift);

return 0; }

// Function Definition for the function to encrypt the input string

void encrypt_str(char xyz[], int key){ char crypted_str[MAX_SIZE]; // To store the resulting string int k=0; // For indexing purpose char str;

while(xyz[k] !='\0') // Processing each character of the string until the "end of line" character is met { str = toupper(xyz[k]); // Remove "toupper" from this line if you don't wish to see the // result string in Uppercase... if(str != ' ') str += key; { if(str > 'z') str -=26; { crypted_str[k] = str; k++; } } } crypted_str[k]='\0'; cout << " Encrypted string is:\t" << crypted_str; // Displaying the Crypted String

// Function call to decrypt the encrypted string decrypt_str(crypted_str, key); }

// Function Definition for the function to decrypt the encrypted string. void decrypt_str(char xyz[], int key){ char decrypted_str[MAX_SIZE]; char str; int k=0; while(xyz[k] !='\0') { str = xyz[k]; if(str != ' ') str -= key; { if(str < 'A' && str !=' ') str += 26; { decrypted_str[k] = str; k++; } } } decrypted_str[k]='\0'; cout << " Decrypted string is:\t" << decrypted_str; }

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

Students also viewed these Databases questions