Last active
August 1, 2017 03:04
-
-
Save ezekielbaniaga/428deb718e3074310bb05075331cf2b3 to your computer and use it in GitHub Desktop.
Simple XOR applied to first 512 bytes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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