0% found this document useful (0 votes)
7 views3 pages

C++ Password Guessing Solution

The document presents a C++ program that prompts the user to enter a 3-letter password and attempts to guess it by generating all possible combinations of uppercase letters. It uses nested loops to create each combination, counts the trials, and displays the successful guess along with the number of attempts. The program concludes by returning to the main function after executing the password guessing function.

Uploaded by

soumaaloui18
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

C++ Password Guessing Solution

The document presents a C++ program that prompts the user to enter a 3-letter password and attempts to guess it by generating all possible combinations of uppercase letters. It uses nested loops to create each combination, counts the trials, and displays the successful guess along with the number of attempts. The program concludes by returning to the main function after executing the password guessing function.

Uploaded by

soumaaloui18
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Problem # 17/2 Solution Using C++

#include <iostream>
#include <string>

using namespace std;


string ReadPassword()
{
string Password;
cout << "Please enter a 3-Letter Password (all capital)?\n";
cin >> Password;
return Password;
}

bool GuessPassword(string OriginalPassword)


{

string word = "";


int Counter = 0;
cout << "\n";
for (int i = 65; i <= 90; i++)
{
for (int j = 65; j <= 90; j++)
{
for (int k = 65; k <= 90; k++)
{
word = word + char(i);
word = word + char(j);
word = word + char(k);
Counter++;
cout << "Trial [" << Counter << "] : ";
cout << word << endl;

if (word == OriginalPassword)
{

cout << "\nPassword is " << word << "\n";


cout << "Found after ";
cout << Counter << " Trial(s)\n";

return true;
}
word = "";
}

}
}
return false;
}

[Link]
© Copyright 2022
Problem # 17/2 Solution Using C++

int main()
{
GuessPassword(ReadPassword());
return 0;
}

[Link]
© Copyright 2022

You might also like