Skip to content

Instantly share code, notes, and snippets.

@maurostorch
Last active March 14, 2018 20:40
Show Gist options
  • Save maurostorch/80d2c6aec54d5e9a4aa5b764b39ce448 to your computer and use it in GitHub Desktop.
Save maurostorch/80d2c6aec54d5e9a4aa5b764b39ce448 to your computer and use it in GitHub Desktop.
ShiftCrypt: 2 bit shift.
public class BitShitCrypt {
public static byte[] encrypt(byte[] data) {
if (data == null) return null;
byte r=(byte)0x00;
for (int i=0;i<data.length;i++) {
byte lr = (byte)(data[i]&0x03);
data[i]=(byte)(data[i]>>2 | r);
r=(byte)(lr<<6);
if (i+1==data.length) {
data[0] = (byte)(data[0]|r);
}
}
return data;
}
public static byte[] decrypt(byte[] data) {
if (data == null) return null;
int mask = 0xc0;
int r=0x00;
for (int i=data.length-1;i>=0;i--) {
int lr = data[i] & mask;
data[i]=(byte)(data[i]<<2 | r);
r=lr >> 6;
if (i==0) {
data[data.length-1] = (byte)(data[data.length-1]|r);
}
}
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment