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

please use c++ to solve question James Bond is sitting in his office, trying to

ID: 3852183 • Letter: P

Question

please use c++ to solve question

James Bond is sitting in his office, trying to get into an agent's official account that he suspects to be a double agent. The agent's file is encrypted with a 10 character alpha-neumeric password (for example: Dz7KV34qY0). He has 10 minutes to solve it or the account information is self-destructed. Bond decides to write a code to do the job and he hires you. Can you help him? Write a password cracking code that does the following: 1. At first it will ask the user to set his password and user will give password input. 2. Then the program should try to crack the password that has been set. 3. Tip: Start from the first character and try to find it using loop. 4. Once you got it right, you should be able to see a welcome message.

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
class Encrypt
{
public:
char enymessage[100], ch;
char original[100];
void EncryptPass()
{
  
int i, key;
  
cout<<"Enter a message to encrypt:";
cin>>enymessage;
cout<<"Enter key to encrypt:";
cin>>key;
  
for(i = 0; enymessage[i] != ''; ++i)
{
original[i]=enymessage[i];
}
for(i = 0; enymessage[i] != ''; ++i){
ch = enymessage[i];
  
if(ch >= 'a' && ch <= 'z'){
ch = ch + key;
  
if(ch > 'z'){
ch = ch - 'z' + 'a' - 1;
}
  
enymessage[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch + key;
  
if(ch > 'Z'){
ch = ch - 'Z' + 'A' - 1;
}
  
enymessage[i] = ch;
}
}
cout<<"Encrpypted password is "<<enymessage;
}
void DecryptPass()
{
int i, key;

cout<<" Enter key to decrypt ";
cin>>key;
  
for(i = 0; enymessage[i] != ''; ++i){
ch = enymessage[i];
  
if(ch >= 'a' && ch <= 'z'){
ch = ch - key;
  
if(ch < 'a'){
ch = ch + 'z' - 'a' + 1;
}
  
enymessage[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch - key;
  
if(ch < 'A'){
ch = ch + 'Z' - 'A' + 1;
}
  
enymessage[i] = ch;
}
}
cout<<"The decrypted password is "<<enymessage;
  
for (i = 0; enymessage[i] == original[i] && enymessage[i]!= '' && original[i] != ''; i++);

if(enymessage[i] - original[i] == 0)
cout << " Welcome you are authorized";
else
cout<< " You are not authorized";
  
}
};
int main()
{
Encrypt obj;
obj.EncryptPass();
obj.DecryptPass();
  
  
return 0;
}

Output:

Enter a message to encrypt:hemanth

Enter key to encrypt:4

Encrpypted password is liqerxl

Enter key to decrypt 4

The decrypted password is hemanth

Welcome you are authorized

Enter a message to encrypt:hemanth

Enter key to encrypt:5

Encrpypted password is mjrfsym

Enter key to decrypt 4

The decrypted password is ifnboui

You are not authorized