[C#]ASCIIM

04/30/2011 00:16 Syst3m_W1z4rd#1
This is the class.
Code:
public class ASCIIM
    {
        public byte[] Bytes;
        public byte[] Keys;
        public int KeyLength
        {
            get { return Keys.Length - 2; }
        }

        public void GetBytes(string String)
        {
            byte[] bytes = new byte[String.Length];
            bytes = Encoding.ASCII.GetBytes(String);

            for (int i = 0; i < bytes.Length; i++)
            {
                for (int u = 0; u < Keys.Length; u++)
                {
                    if (u < KeyLength)
                    {
                        int key = (int)Keys[u] ^ (int)Keys[u + 1] + ((int)Keys[u + 1] ^ (int)Keys[u]);
                        bytes[i] += (byte)key;
                    }
                    else
                        u = Keys.Length + 1;
                }
            }

            Bytes = bytes;
        }
        public string Decode()
        {
            byte[] bytes = Bytes;
            for (int i = 0; i < Bytes.Length; i++)
            {
                for (int u = 0; u < Keys.Length; u++)
                {
                    if (u < KeyLength)
                    {
                        int key = (int)Keys[u] ^ (int)Keys[u + 1] + ((int)Keys[u + 1] ^ (int)Keys[u]);
                        bytes[i] -= (byte)key;
                    }
                    else
                        u = Keys.Length + 1;
                }
            }

            return Encoding.ASCII.GetString(Bytes);
        }
        public string GetString()
        {
            string retstring = "";
            for (int i = 0; i < Bytes.Length; i++)
            {
                retstring += Bytes[i] + " ";
            }

            return retstring;
        }
    }
All it does is changing the bytes. If the keys are invalid or not entered at decoding, then you will get a wrong value back. It can be very useful. I was just playing around with it for fun and thought I would try see if it works and it did. It took maybe 5-10minutes.

Example:
Code:
ASCIIM ascii = new ASCIIM();
            ascii.Keys = new byte[]
            {
                1, 2, 1, 2, 1, 2
            };
            ascii.GetBytes("Hello World!");
            Console.WriteLine(ascii.GetString());//Writing our bytes.
Console.WriteLine(Encoding.ASCII.GetString(ascii.Bytes));//Writing decoding bytes without keys.
            Console.WriteLine(ascii.Decode());//Decoding and writing the decoded bytes.
Output:
Code:
92 121 128 128 131 52 107 131 134 128 20 53
\y???4k???x5
Hello World!
Oh and I'm unbanned :bandit:
05/01/2011 23:57 OELABOELA#2
This actually comes in handy you know? I want to make a name spoofed in my proxy, but i didn't know how to convert an string to byte[]. Thank you :)
05/02/2011 00:26 KraHen#3
@OELABOELA:

No offense but you could always do
for(i=0; i<strlen(myString); ++i) { myArray[i]=(BYTE)myString[i]; }
05/02/2011 00:33 w00tare#4
Quote:
Originally Posted by KraHen View Post
@OELABOELA:

No offense but you could always do
for(i=0; i<strlen(myString); ++i) { myArray[i]=(BYTE)myString[i]; }
Code:
Encoding.ASCII.GetBytes(str());
05/02/2011 14:54 KraHen#5
Which does the same thing afaik.
05/02/2011 16:33 w00tare#6
Quote:
Originally Posted by KraHen View Post
Which does the same thing afaik.
But its faster :)
05/02/2011 22:39 KraHen#7
Quote:
Originally Posted by w00tare View Post
But its faster :)
Why would it be faster?
05/02/2011 22:52 |NeoX#8
Quote:
Originally Posted by w00tare View Post
But its faster :)
Bullshit
05/02/2011 23:14 w00tare#9
Quote:
Originally Posted by |NeoX View Post
Bullshit
I meant faster to typ. >.>
05/03/2011 15:07 Korvacs#10
Encoding.ASCII.GetBytes();

This is marginally slower (you wouldnt even notice) than the other method, but its safer. So you should be using this method, the method in the original post is going to be much slower for seemingly little gain of anything.....
05/03/2011 22:17 Syst3m_W1z4rd#11
Well the one in OP is not efficient really, but I improved it and made something else from it, but that's most likely why I was about to share it. Peoples can either improve it or don't :)