[Intermediate] Creating a strong but simple cipher

08/22/2008 18:19 InfamousNoone#1
Basically, here's the idea, we have a 'key' that contains every value a byte supports (0 to 255). When you encrypt a byte for instance 171 (0xAB) it creates an "x" using the first 4 bits of the byte, and "y" using the last for bits of the byte

Value = 171 (0xAB)
X = 10 (0xA)
Y = 11 (0xB)

Then in the output of the encrypt routine, it it'll fill that index as Key[X, Y]

Here's an illustration to make it simpler;
[Only registered and activated users can see links. Click Here To Register...]

Now, when an encryption (or decryption) has been completed, the key is rolled, here's an example of what rolling a key looks like

[Only registered and activated users can see links. Click Here To Register...]

Now, lets get down to our code;

Code:
    public class HybridCipher
    {
        private byte[,] pEncryptionKey;
        private byte[,] pDecryptionKey;
        private void RollHorizontal(ref byte[,] Key, byte rVertical, ref byte[] Buffer)
        private void RollVertical(ref byte[,] Key, byte rHorizontal, ref byte[] Buffer)
        private void RollKey(ref byte[,] Key)
        private void FindValue(ref byte[,] Key, byte Value, out byte rVertical, out byte rHorizontal)

        public HybridCipher(byte CipherKey)
        public byte[] Encrypt(byte[] Data)
        public byte[] Decrypt(byte[] Data)
        public byte[,] EncryptionKey
        public byte[,] DecryptionKey
    }
Code:
// Our roll key methods
        private void RollHorizontal(ref byte[,] Key, byte rVertical, ref byte[] Buffer)
        {
            byte rHorizontal = 1;
            byte i;
            for (i = 0; i < 16; i++)
            {
                Buffer[rHorizontal] = Key[rVertical, (rHorizontal + 1) % 16];
                rHorizontal = (byte)((rHorizontal + 1) % 16);
            }
            for (i = 0; i < 16; i++)
            {
                Key[rVertical, i] = Buffer[i];
            }
        }
        private void RollVertical(ref byte[,] Key, byte rHorizontal, ref byte[] Buffer)
        {
            byte rVertical = 1;
            byte i;
            for (i = 0; i < 16; i++)
            {
                Buffer[rVertical] = Key[(rVertical + 1) % 16, rHorizontal];
                rVertical = (byte)((rVertical + 1) % 16);
            }
            for (i = 0; i < 16; i++)
            {
                Key[i, rHorizontal] = Buffer[i];
            }
        }
Code:
// Our function to completely roll a key
        private void RollKey(ref byte[,] Key)
        {
            byte rHorizontal = 0;
            byte rVertical = 0;
            byte[] Buffer = new byte[16];
            for (byte i = 0; i < 16; i++)
            {
                RollHorizontal(ref Key, rVertical++, ref Buffer);
                RollVertical(ref Key, rHorizontal++, ref Buffer);
            }
        }
Code:
// Our function to find a value inside a key
        private void FindValue(ref byte[,] Key, byte Value, out byte rVertical, out byte rHorizontal)
        {
            bool Found = false;
            byte x, y;
            rVertical = 0;
            rHorizontal = 0;
            for (x = 0; x < 16; x++)
            {
                for (y = 0; y < 16; y++)
                {
                    if (Key[x, y] == Value)
                    {
                        rVertical = x;
                        rHorizontal = y;
                        Found = true;
                        break;
                    }
                }
                if (Found)
                    break;
            }
        }
Code:
// constructor to initialize our cipher
        public HybridCipher(byte CipherKey)
        {
            byte c = 0;
            pEncryptionKey = new byte[16, 16];
            pDecryptionKey = new byte[16, 16];
            for (byte x = 0; x < 16; x++)
            {
                for (byte y = 0; y < 16; y++)
                {
                    pEncryptionKey[x, y] = (byte)(c++ ^ CipherKey);
                    pDecryptionKey[x, y] = pEncryptionKey[x, y];
                }
            }
        }
Code:
        public byte[] Encrypt(byte[] Data)
        {
            byte[] Output = new byte[Data.Length];
            byte x, y;
            for (int i = 0; i < Data.Length; i++)
            {
                x = (byte)(Data[i] >> 4);
                y = (byte)(Data[i] & 0xF);
                Output[i] = pEncryptionKey[x, y];
            }
            RollKey(ref pEncryptionKey);
            return Output;
        }
        public byte[] Decrypt(byte[] Data)
        {
            byte[] Output = new byte[Data.Length];
            byte x, y;
            for (int i = 0; i < Data.Length; i++)
            {
                FindValue(ref pDecryptionKey, Data[i], out x, out y);
                Output[i] = (byte)((x << 4) + y);
            }
            RollKey(ref pDecryptionKey);
            return Output;
        }
08/23/2008 00:16 shmeh101#2
Great work. :D
08/23/2008 23:44 QuakeZ#3
Hey I saw ur video on cihpers but i dont get them
...

What are they used for ??
08/24/2008 03:03 Hiyoal#4
They are used for encrypting data. So say I had the word "Hello" and I used a cypher on it...It would be encrypted into something which a Human Cannot Read and therefore Not Understand.

So in short, Cyphers are used to protect information which you dont want others to read, or other programs.

~:Hiyoal:~ :)
08/25/2008 01:12 QuakeZ#5
Quote:
Originally Posted by ~:Hiyoal:~ View Post
They are used for encrypting data. So say I had the word "Hello" and I used a cypher on it...It would be encrypted into something which a Human Cannot Read and therefore Not Understand.

So in short, Cyphers are used to protect information which you dont want others to read, or other programs.

~:Hiyoal:~ :)
Oh..

Then....

Wat about like how would u read then if u wanted to send this message to someone but how would they be able to read it?
08/25/2008 01:35 InfamousNoone#6
They decrypt it with the recrusive method to the encrypt method.
08/25/2008 20:00 QuakeZ#7
Quote:
Originally Posted by InfamousNoone View Post
They decrypt it with the recrusive method to the encrypt method.
ummmm...

how would u do that? lol
08/26/2008 03:13 tao4229#8
Quote:
Originally Posted by QuakeZ View Post
ummmm...

how would u do that? lol
Do all the steps of the Encryption in Reverse.(In idiots terms.)
08/28/2008 18:03 NovaCygni#9
Also for anyone with the patience to learn how the Encryption Ciphers are implemented, they required changes can be made to the few public source-codes still available for Proxys...
08/31/2008 03:15 QuakeZ#10
Quote:
Originally Posted by tao4229 View Post
Do all the steps of the Encryption in Reverse.(In idiots terms.)
ohhh haha i c much easier then i thought it was lol