Hi all,
I have implemented some code for simple columnar encryption. The algorithm is encrypting properly as I want. But during decryption it's giving me some errors. Please go through and suggest me if any idea
public static void encrypt(RandomAccessFile f,RandomAccessFile d,int columns) throws Exception
{
d.seek(10); // SEEK IS USED FOR INTERNAL PURPOSE
for(int i=0;i<columns && flag;i++)
for(int j=0;(j*columns+i)<f.length() && flag;j++)
{
f.seek(j*columns+i);
p.setValue((int)d.getFilePointer());
d.write(f.read());
}
}
//DECRYPTION FUNCTION
public static void decrypt(RandomAccessFile f,RandomAccessFile d,int columns) throws Exception
{
f.seek(10);
int rows;
long temp;
int cache=(int)((f.length()-10)%columns);
int buffer=(int)((f.length()-10)/columns);
if(cache==0)
rows=buffer;
else
rows=(buffer+1);
for(int i=0;i<rows && flag;i++)
{
temp=i;
for(int j=0;j<columns && flag;j++)
{
f.seek(temp+10);
p.setValue((int)d.getFilePointer());
d.write(f.read());
temp+=buffer;
if(j<cache)
temp++;
}
}
}
Please help me out!! thanks in advance!