I'm trying to encrypt a bmp image with RC4 but the encrypted image is not much different from The original one att all
public static void main(String[] args) throws FileNotFoundException, IOException{
try{
File bmpFile = new File("C:\\Users\\acer\\Desktop\\py\\6.bmp");
BufferedImage image = ImageIO.read(bmpFile);
int width = image.getWidth();
int height = image.getHeight();
int[][] pixels = new int[width][height];
for( int i = 0; i < width; i++ )
for( int j = 0; j < height; j++ )
pixels[i][j] = image.getRGB( i, j );
int []key ={100,70,600,878};
int []t =new int[256];
int []s =new int[256];
for(int i=0;i<s.length;i++)
s[i]=i;
for(int i=0;i<t.length;i++)
t[i]=key[i%key.length];
int j=0;
for(int i=0;i<s.length;i++){
j=(j+s[i]+t[i])%s.length;
int temp=s[i];
s[i]=s[j];
s[j]=temp;
}
int tt;
int k;
j=0;
int i=0;
for(int c=0;c<width;c++){
for(int cc=0;cc<height;cc++){
i = (i + 1) % s.length;
j = (j + s[i]) % s.length;
int temp=s[i];
s[i]=s[j];
s[j]=temp;
tt = (s[i] + s[j]) % 256;
k = s[tt];
pixels [c][cc]=pixels[c][cc] ^ k;
}
}
for( i = 0; i < width; i++ )
for( j = 0; j < height; j++ )
image.setRGB(i, j, pixels[i][j]);
bmpFile = new File("C:\\Users\\acer\\Desktop\\py\\66.bmp");
ImageIO.write(image, "bmp", bmpFile);
}
catch (IOException e){
System.out.println(e.getMessage());
}
}
i dont know what the problem,i looked for some codes but didn't found a lot of differences