Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 00:43

  • Please register to post and access all features, it's quick, easy and FREE!


[Intermediate] Creating a strong but simple cipher

Discussion on [Intermediate] Creating a strong but simple cipher within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,877
[Intermediate] Creating a strong but simple cipher

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;


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



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;
        }



InfamousNoone is offline  
Thanks
4 Users
Old 08/23/2008, 00:16   #2
 
elite*gold: 0
Join Date: Nov 2007
Posts: 4
Received Thanks: 0
Great work.


shmeh101 is offline  
Old 08/23/2008, 23:44   #3
 
elite*gold: 0
Join Date: May 2008
Posts: 49
Received Thanks: 3
Hey I saw ur video on cihpers but i dont get them
...

What are they used for ??
QuakeZ is offline  
Old 08/24/2008, 03:03   #4
 
elite*gold: 20
Join Date: Mar 2007
Posts: 2,444
Received Thanks: 1,064
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:~


Hiyoal is offline  
Thanks
2 Users
Old 08/25/2008, 01:12   #5
 
elite*gold: 0
Join Date: May 2008
Posts: 49
Received Thanks: 3
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?
QuakeZ is offline  
Old 08/25/2008, 01:35   #6
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,877
They decrypt it with the recrusive method to the encrypt method.
InfamousNoone is offline  
Old 08/25/2008, 20:00   #7
 
elite*gold: 0
Join Date: May 2008
Posts: 49
Received Thanks: 3
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
QuakeZ is offline  
Old 08/26/2008, 03:13   #8
 
elite*gold: 0
Join Date: Feb 2008
Posts: 1,590
Received Thanks: 153
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.)
tao4229 is offline  
Old 08/28/2008, 18:03   #9
 
elite*gold: 0
Join Date: Jan 2008
Posts: 303
Received Thanks: 155
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...
NovaCygni is offline  
Old 08/31/2008, 03:15   #10
 
elite*gold: 0
Join Date: May 2008
Posts: 49
Received Thanks: 3
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


QuakeZ is offline  
Reply



« Scripting / Packet Encryption. | [Intermediate] - C# AsyncSockets(Client) »

Similar Threads
[TUTORIAL] Creating a simple DLL Cheat/Hack
11/06/2018 - Kal Hacks, Bots, Cheats & Exploits - 160 Replies
HOW TO CREATE YOUR OWN DLL HACK Hello guys, In recent days, I recieved many questions about how to use the pointers posted in one specific thread. So here is guide for creating the basic Proxy-DLL skeleton + hack. I will try to explain it to details. Requirements 1] Some C++ and UCE (memory and such stuff) knowladge 2] Some Time
[Guide] Creating a Simple Loader with Injected DLL for Silkroad
02/02/2016 - SRO Coding Corner - 37 Replies
This next article in my series is a very important one for anyone wanting to get started with client modifications or understanding the client itself. This is the base article that will be used for all my future articles that explain various Silkroad development concepts. Like my previous article, there is nothing terribly exciting with this one as we have to get through the necessary boring stuff first before we can have any real fun. Unfortunately, this article is very heavy text wise and...
[Intermediate] Creating a picture cipher
08/27/2008 - CO2 Programming - 0 Replies
This cipher relies on the 'hybrid cipher' which can be found here; http://www.elitepvpers.com/forum/co2-programming/160922-intermediate-creating-strong-but-simple-cipher.html Include the library (dll) attached as a reference to a .NET project and then add "using PictureCryptLibrary;" or whatever it is to use a namespace in the .NET language of your choice. // enc PictureCrypt.Encrypt(encfile, outputfile, cipherkey);



All times are GMT +2. The time now is 00:43.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

BTC: 3KeUpz52VCbhmLwuwydqxu6U1xsgbT8YT5
ETH: 0xc6ec801B7563A4376751F33b0573308aDa611E05

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2019 elitepvpers All Rights Reserved.