Scrambling

Scrambling Moving square sections of an image requires some organization. You need to think of this image as being divided into sixteen equal sized squares (more or less equal anyways). You simply swap postions of squares.


Here's the code to perform the scramble. This is a fixed scramble algorithm. What do you think it would take to do a random scramble? public void doScramble(){ int test=0; int z=0; try{ int pixel[] = new int[w*h]; int hold[] = new int[w*h]; PixelGrabber pg = new PixelGrabber(c, 0, 0, w, h, pixel, 0, w); if(pg.grabPixels() &&((pg.status() & ImageObserver.ALLBITS) != 0)){ for(int x=0; x<w; x++){ for(int y=0; y<h; y++){ z=y*65+x; if(x<16 && y<13) hold[z+26*65+32]=pixel[z]; else if(x<16 && y<26) hold[z+26*65+32]=pixel[z]; else if(x<16 && y<39) hold[z-26*65+48]=pixel[z]; else if(x<16) hold[z-39*65+16]=pixel[z]; else if(x<32 && y<13) hold[z+39*65-16]=pixel[z]; else if(x<32 && y<26) hold[z+32]=pixel[z]; else if(x<32 && y<39) hold[z-26*65+16]=pixel[z]; else if(x<32) hold[z+32]=pixel[z]; else if(x<48 && y<13) hold[z+26*65-32]=pixel[z]; else if(x<48 && y<26) hold[z+13*65+16]=pixel[z]; else if(x<48 && y<39) hold[z-26*65-32]=pixel[z]; else if(x<48) hold[z-26*65-32]=pixel[z]; else if(y<13) hold[z+26*65-32]=pixel[z]; else if(y<26) hold[z-32]=pixel[z]; else if(y<39) hold[z-13*65-16]=pixel[z]; else hold[z-32]=pixel[z]; } } s=createImage(new MemoryImageSource(w, h, hold, 0, w)); } }catch(InterruptedException e) { } }