Convert this C++ code to Java code this code is to encrypt and decrypt strings o
ID: 3863709 • Letter: C
Question
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 <iostream>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string>
#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 : ";
gets(input_str); // Getting the user to input the string to be encrypted!
cout<<" Original string: " << 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] !='') // 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]='';
cout << " Encrypted string is: " << 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] !='')
{
str = xyz[k];
if(str != ' ') str -= key;
{
if(str < 'A' && str !=' ') str += 26;
{
decrypted_str[k] = str;
k++;
}
}
}
decrypted_str[k]='';
cout << " Decrypted string is: " << decrypted_str;
}