/*
OTP4U 0.8.0 - One Time Pad for you
Copyright (C) 2003 Pierre Blanc
Pierre Blanc: blanc_teutoburgo@yahoo.it
http://www.teutoburgo.tk
http://it.geocities.com/teutoburgo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or go to http://www.gnu.org/copyleft/gpl.html
*/
package tk.teutoburgo.otp4u.crypt;
import java.io.IOException;
public class Xor {
/**
* Xor constructor comment.
*/
public Xor() {
super();
}
public byte[] decrypt(byte[] encrypted, byte[] key) {
int i=0;
int length= encrypted.length;
int keyLength=key.length;
byte[] message = new byte[length];
for (i = 0; i < length && i<keyLength ; i++) {
message[i]=(byte)(encrypted[i]^key[i]);
}
return message;
}
public byte[] encrypt(byte[] message, byte[] key) {
int length=message.length;
byte[] encrypted = new byte[length];
for (int i = 0; i < length && i<key.length; i++) {
encrypted[i]=(byte)(message[i]^key[i]);
}
return encrypted;
}
public static void main
(String args
[]){
Xor s= new Xor();
tk.teutoburgo.otp4u.application.OTP4U o =
new tk.teutoburgo.otp4u.application.OTP4U();
/* byte[] x = {2,6,4,6,0,6,4,6};
byte[] y = {11,3,1,7,1,3,1,15};
byte[] a = s.encrypt(x,y);
// byte[] a = o.autoKey(x);
/* byte[] mng = new byte[10];*/
/* for (int i = 0; i < a.length; i++) {
System.out.print("i="+i+" a[i]="+a[i]+" ");
}
/*byte [] test=s.encrypt(x, mng);
byte [] testd=s.decrypt(test, mng);
try{
System.out.write(x);
System.out.println();
System.out.write(mng);
System.out.println("result");
System.out.write(test);
System.out.println("result2");
System.out.write(testd);
} catch (IOException ioe){
ioe.printStackTrace();
}
*/
}
}