title: base64_encode() from php function to Java does not return same data
body: <p>I'm working on a java project that needs to have an authentication from accounts created on a local website. Those account's passwords are encrypted by a php function before inserted to the database : </p>
  
  <pre><code>public function crypter($mdp){
      $j = 0;
      $tmp = 0;
      $key = $mdp;
  
      $res = "";
  
      for($i = 0; $i &lt; strlen($mdp) ; $i++)
      {
          $tmp = ord($mdp[$i]) + ord($key[$i]);
          if($tmp &gt; 255){
              $tmp = $tmp - 256;
          }
  
          $res[$i] = chr($tmp);
  
          if($j == strlen($key)-1){
              $j = 0;
          }
          else{
              $j = (($j % (strlen($key))) +1 );
          }
      }
  
      $res = base64_encode($res);
  
      return $res;
  }
  </code></pre>
  
  <p>NOTE : This function has not been written by me, so if you guys figure out what the <code>$j</code> variable is used for let me know. I also (obviously) can not change this code.</p>
  
  <p>So I've tried to translate that function in Java which gave this : </p>
  
  <pre><code>public String cryptMdp(String mdp){
      String res = "";
      String key = mdp;
  
      int j = 0;
      int tmp = 0;
  
      for (int i = 0; i &lt; mdp.length(); i++) {
          char c = mdp.charAt(i);
          char c2 = key.charAt(i);
  
          tmp = (int) c + (int) c2;
          if (tmp &gt; 255) {
              tmp = tmp - 256;
          }
  
          res += (char) tmp;
  
          if (j == key.length() - 1){
              j = 0;
          }
          else{
              j = (j % key.length()) + 1;
          }
      }
      return Base64.getMimeEncoder().encodeToString(res.getBytes());
  }
  </code></pre>
  
  <p>Unfortunately, those do not return the same string (ex: For the string <code>a</code>, php returns <code>wg==</code> and Java returns <code>w4I=</code>.), even though according to <a href="https://stackoverflow.com/questions/49728951/is-base64-encode-in-php-equal-to-java-util-base64" title="this questionquot;">this question</a> this is supposed to be a standard.</p>
  
  <p>Can you guys see what I'm doing wrong ?</p>