title: Excel function xorc in java
body: <p>I received a passwordsave made in a excel file. 
  The passwords are "encrypted" with the Excel xorc function. </p>
  
  <p>Now I'm trying to build up the same in a java program. </p>
  
  <p>When I use the xor ^ function I do not receive the same result as in excel. </p>
  
  <p>Does any one know how I can create a java xor function witch provides the same result like the excel xorc? </p>
  
  <p><strong>Result Excel:</strong> <br>
  Key: lock <br>
  input: 650827-25 <br>
  xorc output: xxx[[TT_YOZZ <br></p>
  
  <p>=xorc("650827-25";"lock")<br></p>
  
  <p><strong>result of my Java Application:</strong> <br>
  Key: lock <br> 
  input: 650827-25 <br> 
  xorc output: ZZSS^XNYY <br> </p>
  
  <p><strong>XOR_Codierer</strong></p>
  
  <pre><code>public class XOR_Codierer extends Encoder {
  
  private char[] key;
  private char[] password;
  
  public XOR_Codierer(String k){
      key = k.toCharArray();
  }
  
  public String encode(String s){
      password = s.toCharArray();
  
      int pl=password.length;
      int kl=key.length;
      char[] newmsg=new char[pl];
  
     for (int i=0; i&lt;pl; i++){
            newmsg[i]=(char)(password[i]^key[i%kl]);
      }       
  
  
  return new String(newmsg);
  }
  
  public String decode(String s){
      return encode(s);
  }
  }
  </code></pre>
  
  <p><strong>Demo</strong></p>
  
  <pre><code>public class Demo{
  
  public static void demo(Encoder enc, String text) {
      String encoded = ((XOR_Codierer) enc).encode(text);
      System.out.println("codiert : " + encoded);
      String decoded = ((XOR_Codierer) enc).decode(encoded);
      System.out.println("decodiert: " + decoded);
  
      if (text.equals(decoded))
          System.out.println("Verschluesselung erfolgreich!");
      else
          System.out.println("PROGRAMMFEHLER!");
  }
  
  public static void main(String[] args){
  String key = "lock";
  String text = "650827-25";
  Encoder enc = new XOR_Codierer(key);
  demo(enc, text);
  }
  }
  </code></pre>