Jump to content

Dúvida sobre adivinha nº de caracteres


raquelmontalvao

Recommended Posts

O enunciado é este:

<Hacking Task #2>

Congratulations, you now know the *very* basics of the JavaScript language!

To proceed on your mad journey from programming n00b to full-fledged <Code Cadet>, you must now work alongside fSociety's ultra dope hacking crew and show them your awesome recently acquired skills in a series of <Hacking Tasks>.

For this task you'll need to gain access to a target's account, which is password protected. We know the password is only four characters long, but we have no idea of what it looks like.

With today's computing power, brute-forcing weak passwords is not that hard and, as in any brute-force technique, it only requires time and luck.

Instructions

You know that your target's password is 4 characters long, so you'll just have to brute force 1 character at a time. We already declared the variable correctGuesses which you should use to keep track of how many characters you have guessed so far.

Bear in mind that your program does not need to guess the password, that is not your goal!

You need to create a loop that only stops when all 4 characters have been guessed. On each loop iteration you need to calculate a random number between 1 and 3, which will correspond to each of the bellow scenarios:

1. You guessed one character correctly, which increases correctGuesses by 1 and prints the message 'Found X characters' (where X is replaced with the current number of correct guesses).

2. You guessed incorrectly and your target's terminal has detected too many attempts, which resets correctGuesses to 0 and prints the message 'Starting over' to the console.

3. You guessed incorrectly, but have not been detected yet, correctGuesses is kept with the same value.

Once the password is cracked (that is, correctGuesses has a value of 4) you should print the message 'Terminal hacked!'.

Make sure all the messages in your code are in the correct format in order to advance!

 

Fiz o código várias vezes mas dá sempre erro.

O que tenho atualmente é este:

var correctGuesses = 0;
var password= 4;

while (correctGuesses <4) { 
    var guess = Math.ceil (Math.random()*3);
    
    if (guess===1) {
    correctGuesses++;
    console.log('Found'+'' + correctGuesses +''+'characters');
 }      
        
    else if (guess===2) {
    correctGuesses=0;
    console.log('Starting over');
 }
    
    else if (guess===3) {
    correctGuesses= correctGuesses;
    
}

if (correctGuesses === password) {
    console.log ('Terminal hacked'); 
 
}
}

Resposta: 

>>>>Code is incorrect

You guessed some characters correctly, but failed to do the right thing!

Alguém me consegue ajudar?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.