I'm bored today, so I present to you a simple encryption algorithm that I came up with a while back.
What the algorithm does is it splits each byte into 2 bytes, the first being the byte AND the mask, the second being the byte NOR the mask.
- Code: Select all
Given mask M and byte array A,
Encrypt a new array B
for i = 1 -> A.length * 2
B[i * 2] = A[i] AND M
B[i * 2 + 1] = A[i] NOR M
This way, to decrypt it, you know where the byte definitely has 1's and where it definitely has 0's, any spots that you aren't defined in the AND or NOR, will be the inverse bits of the mask.
Now this by itself is unsafe because you can easily pin point where the mask has what bits. So, to make it more secure, the algorithm randomly salts any bits in the AND that will always be 0's, and any bits in the NOR that will always be 0's.
This is the Java code that encrypts a byte array according to this algorithm, given byte mXORMask = mask
- Code: Select all
public byte [] transformBytes(byte [] vByteArray) {
byte [] nByteArray = new byte [vByteArray.length * 2];
nByteArray[0] = mXORMask;
for(int i = 0; i < vByteArray.length; i++) {
nByteArray[i * 2] = (byte)(mXORMask & vByteArray[i]);
nByteArray[i * 2 + 1] = (byte)(0xFF ^ (mXORMask | vByteArray[i]));
}
return nByteArray;
}
This is the Java code that salts the bytes given byte [] aSalterMask = {mXORMask ^ 0xFF, mXORMask};
- Code: Select all
public byte[] transformBytes(byte[] vByteArray) {
byte [] nByteArray = new byte [vByteArray.length];
int tIndex = 0;
for(int i = 0; i < vByteArray.length; i++) {
nByteArray[i] = (byte)(((aSalterMask[tIndex] ^ 0xFF) & vByteArray[i]) | (aSalterMask[tIndex] & ByteLib.getRandomByte()));
tIndex++;
if(tIndex == mNumMasks) {
tIndex = 0;
}
}
return nByteArray;
}
The challenge to everyone is to find a way to crack this encryption without the mask available. Or possibly find the mask. A cookie to the first person to crack it without brute forcing.
Here's some encrypted 'hello world's for you:
- Code: Select all
51 B3 04 9A 5C 91 0D 95 5E B2 69 DF 0F AE 17 14 1A AF 14 11 15 B9 29 DC 68 5E 39 78 78 5E 45 52 4A D3 39 17 7C 98 65 31 24 B7 3F 36 60 7B 66 2E 2E 30 63 AB 24 33 75 1B 60 58 68 5A 68 F8 05 D2 1A D5 5D 50 12 55 70 35 61 17 2D 1C 2D 1A 2D 91 25 13 2D 91 2C 15 67 B0 77 96 69 FB 3E 88 66 AC 3F 16 7E 14 7B 2F 2B 0B 35 31 74 35 75 9F 6C BB 28 5E 20 DA 29 F8 69 DC 31 5E 78 FC 79 5E 20 DE 04 F4 42 55 15 F4 5A 71 59 B1 3D 3C 15 37 6D 13 46 10 38 DF 17 A8 2E B4 02 2D 7D 13 4C 39 31 DC 39 6E 38 58 79 EC
-WallShadow <3
-- Thu Jul 19, 2012 11:51 pm --
Does no one have a solution for this?