currently I'm programming a chat with XOR-Encryption. But today i encountered a problem. The encryption is under Windows different as in Linux. Under Linux the chat runs normally, but under Windows not.
Here the class:
class XOR_c {
private boolean active = true;
private int key;
// Constructor
public XOR_c(int k){
if (System.getProperty("os.name").contains("Windows")) {
JOptionPane.showMessageDialog(null,"No encryption!","Client", JOptionPane.CANCEL_OPTION);
this.active = false;
}
key = k;
}
public String encode(String s) {
if (active == false) return s;
char[] c = s.toCharArray();
for (int i=0; i<c.length; i++)
c[i] = (char)(c[i]^key);
return new String(c);
}
public String decode(String s){
return encode(s);
}
}
This is tested with openSuse, Debian and Windows 7.
Now how to fix it (At this moment I made a bypass for the encryption but this is not my target, I want a encryption with both systems)? Is my source wrong?