title: Why do these PHP and Java password generators produce different output?
body: <p>I' m writting a password generator for a script in PHP and I want it to be compatible with a class I wrote in Java, so that they can share resources.  </p>
  
  <p>PHP code: </p>
  
  <pre><code>public function PasswordGen($password, $rounds) { 
      for($i = 0; $i &lt; $rounds; $i++) { 
          $password = substr(base64_encode(md5($password)), 0, 16); 
          echo $i . " " . $password . PHP_EOL; // debugging //
      }
      return $password;
  }
  </code></pre>
  
  <p>Java code: </p>
  
  <pre><code>public static String PasswordGen(String password, int rounds) {
      try { 
          for(int i = 0; i &lt; rounds; i++) { 
              byte[] md5 = MessageDigest.getInstance("MD5").digest(password.getBytes("UTF-8"));
              String md5h = (new BigInteger(1, md5)).toString(16);
              password = Base64.getEncoder().encodeToString(md5h.getBytes()).substring(0, 16);
              System.out.println(Integer.toString(i) + " " + password); // debugging //
          }
      } catch(Exception ex) {
          ex.printStackTrace();
          return null;
      }
      return password;
  }
  </code></pre>
  
  <p>PHP debug output:  </p>
  
  <pre><code>0 MWExZGM5MWM5MDcz  
  1 NDVkZmMxNWVjNWZi  
  2 ODY5YzVkODBhNTRh  
  3 ZGE2OTNiOWMxOWM1  
  4 OTcxMTY3MzgxMmRk  
  5 NWNjNDI2N2IzMDlj  
  6 NGVkYzY0YjVkMWUy  
  7 MjdhMGU4NjhhNmU3  
  8 OWY5OGE3ZGZiODZl  
  9 Y2I1ZjBkNjRmMjkx  
  10 YTk5NDA1MGI1OWY1  
  11 YzRmYWE5ZTk0ZDdl  
  12 NDBiZWZkNmQ5Yjhj  
  13 MzQyNzcwNGRjMTYw  
  14 N2U4ZmUxOGMyNWYx  
  15 MjBjOTZhNGE4ZDQ1  
  16 MjdmMzkwMzI0NDdj  
  17 YjM4NDI0YWU0YzUw  
  18 NDRiNjA1MWUwOGZi  
  19 MGI1YmIyMDViMGYz  
  </code></pre>
  
  <p>Java debug output:  </p>
  
  <pre><code>0 MWExZGM5MWM5MDcz  
  1 NDVkZmMxNWVjNWZi  
  2 ODY5YzVkODBhNTRh  
  3 ZGE2OTNiOWMxOWM1  
  4 OTcxMTY3MzgxMmRk  
  5 NWNjNDI2N2IzMDlj  
  6 NGVkYzY0YjVkMWUy  
  7 MjdhMGU4NjhhNmU3  
  8 OWY5OGE3ZGZiODZl  
  9 Y2I1ZjBkNjRmMjkx  
  10 YTk5NDA1MGI1OWY1  
  11 YzRmYWE5ZTk0ZDdl  
  12 NDBiZWZkNmQ5Yjhj  
  13 MzQyNzcwNGRjMTYw  
  14 N2U4ZmUxOGMyNWYx  
  15 MjBjOTZhNGE4ZDQ1  
  16 MjdmMzkwMzI0NDdj  
  17 YjM4NDI0YWU0YzUw  
  18 NDRiNjA1MWUwOGZi  
  19 YjViYjIwNWIwZjMy  
  </code></pre>
  
  <p>It works as expected until the 19th loop. Why does it produce different output after that?</p>