/*
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 tk.teutoburgo.otp4u.io.*;
import tk.teutoburgo.otp4u.util.*;
/**
* Title: OTP4U
* Description:
* Copyright: Copyright (c) 2002
* Company: Teutoburgo
* @author Pierre Blanc
* @version 1.0
*/
public class KeyPermutator {
Xor xor = new Xor();
public KeyPermutator() {
}
public byte[][] recurrence(byte[] p, byte[] k){
int n, b=0, v=0, kf=0, c, I, l=p.length, kLen=k.length, i=0, tot=l-kLen,
aRes=100, pf=0;
byte[] r=new byte[tot], xorArr=new byte[kLen], pPos=new byte[l];
byte[][] rAndK = new byte[2][];
// System.out.println("inizio b="+b+" kf"+kf+"r[0]="+r[0]+" "+(char)r[0]);
for(n=0; n<tot; n++){
c=128+p[b%l]+(128+k[b%kLen])*256+
(128+p[(b+1)%l])*65536+(128+k[(b+1)%kLen])*123456;
v=128+p[c%l]+(128+k[c%kLen])*256+
(128+p[(c+1)%l])*65536+(128+k[(c+1)%kLen])*123456;
// System.out.println("v="+v);
b=((b+v)%l+l)%l;
r[n]=p[b];
l--;
p[b]=p[l];
/*if(n%10000==0)
System.out.println("\nn "+n+" b="+b+"r[n]="+r[n]+" "+(char)r[n]+
" p[l-1]="+p[l-1]+" l="+l+"\nv="+v);*/
}
//System.out.print("size "+p.length+" rl="+r.length+" kl="+kLen+"\nv="+v);
System.
arraycopy(p, 0, k, 0, kLen
);
rAndK[0] = r;
rAndK[1] = k;
return rAndK;
}
public static void main
(String args
[]) {
Io io = new Io();
KeyPermutator it = new KeyPermutator();
MessagesPrinter pm = new MessagesPrinter();
pm.printCopyright();
int argsLen = args.length;
String badParameter
="Bad parameter.. type: java Sysepub -h";
try{
byte[] file=io.readFile(SSP_HOME+"prova.rnd");
byte[] k=io.readFile(SSP_HOME+"k.rnd");
byte[][] prova=it.recurrence(file, k);
//System.out.print("adesso size "+file.size());
io.writeFile(SSP_HOME+"out.rnd",prova[0]);
io.writeFile(SSP_HOME+"k1.rnd",prova[1]);
e.printStackTrace();
}
}
}