Skip to content

Instantly share code, notes, and snippets.

@ezekielbaniaga
Last active August 1, 2017 03:04
Show Gist options
  • Save ezekielbaniaga/428deb718e3074310bb05075331cf2b3 to your computer and use it in GitHub Desktop.
Save ezekielbaniaga/428deb718e3074310bb05075331cf2b3 to your computer and use it in GitHub Desktop.
Simple XOR applied to first 512 bytes
import java.io.*;
public class ImageCrypto {
private static final int XOR_KEY = 345;
private static final int BYTE_LENGTH = 512;
public static void applyXor( File file ) throws IOException {
RandomAccessFile rac = new RandomAccessFile(file, "rw");
byte[] data = new byte[BYTE_LENGTH];
rac.read( data );
byte[] newData = xor( data );
rac.seek(0);
rac.write(newData);
rac.close();
}
public static byte[] xor( byte[] data ) {
byte[] newData = new byte[data.length];
for (int i = 0; i < data.length; i++) {
newData[i] = xor(data[i]);
}
return newData;
}
public static byte xor(byte b) {
return (byte) (0xFF & ((int) b ^ XOR_KEY));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment