title: gdb - Find the password
body: <p>Let's say I have the following functions:</p>
  
  <pre><code>void personalData()
  {
      char password[30];
      puts("Please enter your password");
      fgets(password, 6, stdin);
  
      if(correctPassword(password) != 0) {
          puts("Try again later !");
      }
      else {
          puts("Hello master");
      }
  }
  
  int correctPassword(char password[5])
  {
      int i = 0;
      char desiredPassword[5] = {0x12, 0x13, 0x14, 0x15, 0x16};
      char hash[5] = {0x22, 0x23, 0x24, 0x25, 0x26};
  
      for(i = 0; i &lt; 5; ++i) {
          password[i] ^= hash[i];
      }
      return strncmp(password, desiredPassword, 5);
  }
  
  int main() {
      personalData();
      return 0;
  }
  </code></pre>
  
  <p>My goal is to use <strong>gdb</strong> to find what password I should choose for <code>password</code> in order for the function personalData to print <strong>Hello master</strong>. I tried using breakpoints, many dissemble for every portion but I have no clue where to look for the actual result. I also tried to look in strncmp but with no result.
  <em>I am not supposed to change the source code.</em></p>