Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Can you tell me what this code do ?

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can you tell me what this code do ?

    Hey guys, first off i'm new here and i'm also new at java programming, i know the basics so far but to me it is just super complicated compared to the language i used before (Visual Basic) but i'm actually trying to learn Java since everybody told me it is way better than VB so i thought i'd give it a try, i've bought the book "Java programming for dummies" and to be perfectly honest it's not what i expected, i mean it does teach you the basic stuff of Java programming such as operators, statements and etc but when trying to "read" a source code and try to understand it, i tend to get headaches more than anything else for example, i am trying to make an encryption/decryption program as my first Java program so i've downloaded a few source codes demonstrating encryption algorythms and i'm trying to get what exactly the code do and how do i use it

    Here's the actual code:



    P.S Sorry if i didn't post this in the right section

     
    import java.io.*;
     
    public final class qb extends FilterOutputStream
        implements DataOutput
    {
     
        public qb(OutputStream outputstream)
        {
            super(outputstream);
            b = 0;
            c = new byte[8];
        }
     
        public final synchronized void write(int i)
            throws IOException
        {
            if(a != null && a.length > 0)
                i ^= a[q()];
            super.out.write(i);
        }
     
        public final void q(byte abyte0[])
        {
            a = abyte0;
            b = 0;
        }
     
        private int q()
        {
            b = (b + 1) % a.length;
            return b;
        }
     
        public final void flush()
            throws IOException
        {
            super.out.flush();
        }
     
        public final void writeDouble(double d)
            throws IOException
        {
            writeLong(Double.doubleToLongBits(d));
        }
     
        public final void writeFloat(float f)
            throws IOException
        {
            writeInt(Float.floatToIntBits(f));
        }
     
        public final void writeByte(int i)
            throws IOException
        {
            write(i);
        }
     
        public final void writeChar(int i)
            throws IOException
        {
            write(i >>> 8 & 0xff);
            write(i >>> 0 & 0xff);
        }
     
        public final void writeInt(int i)
            throws IOException
        {
            write(i >>> 24 & 0xff);
            write(i >>> 16 & 0xff);
            write(i >>> 8 & 0xff);
            write(i >>> 0 & 0xff);
        }
     
        public final void writeShort(int i)
            throws IOException
        {
            write(i >>> 8 & 0xff);
            write(i >>> 0 & 0xff);
        }
     
        public final void writeLong(long l)
            throws IOException
        {
            c[0] = (byte)(int)(l >>> 56);
            c[1] = (byte)(int)(l >>> 48);
            c[2] = (byte)(int)(l >>> 40);
            c[3] = (byte)(int)(l >>> 32);
            c[4] = (byte)(int)(l >>> 24);
            c[5] = (byte)(int)(l >>> 16);
            c[6] = (byte)(int)(l >>> 8);
            c[7] = (byte)(int)(l >>> 0);
            write(c, 0, 8);
        }
     
        public final void writeBoolean(boolean flag)
            throws IOException
        {
            write(flag ? 1 : 0);
        }
     
        public final synchronized void write(byte abyte0[], int i, int j)
            throws IOException
        {
            if((i | j | abyte0.length - (j + i) | i + j) < 0)
                throw new IndexOutOfBoundsException();
            for(int k = 0; k < j; k++)
                write(abyte0[i + k]);
     
        }
     
        public final void write(byte abyte0[])
            throws IOException
        {
            write(abyte0, 0, abyte0.length);
        }
     
        public final void writeBytes(String s)
            throws IOException
        {
            int i = s.length();
            for(int j = 0; j < i; j++)
                write((byte)s.charAt(j));
     
        }
     
        public final void writeChars(String s)
            throws IOException
        {
            int i = s.length();
            for(int j = 0; j < i; j++)
            {
                char c1 = s.charAt(j);
                write(c1 >>> 8 & 0xff);
                write(c1 >>> 0 & 0xff);
            }
     
        }
     
        public final void writeUTF(String s)
            throws IOException
        {
            q(s, this);
        }
     
        private static int q(String s, DataOutput dataoutput)
            throws IOException
        {
            int i = s.length();
            int j = 0;
            char ac[] = new char[i];
            int k = 0;
            s.getChars(0, i, ac, 0);
            for(int l = 0; l < i; l++)
            {
                char c1;
                if((c1 = ac[l]) >= '\001' && c1 <= '\177')
                {
                    j++;
                    continue;
                }
                if(c1 > '\u07FF')
                    j += 3;
                else
                    j += 2;
            }
     
            if(j > 65535)
                throw new UTFDataFormatException();
            k++;
            byte abyte0[];
            (abyte0 = new byte[j + 2])[0] = (byte)(j >>> 8 & 0xff);
            k++;
            abyte0[1] = (byte)(j >>> 0 & 0xff);
            for(int i1 = 0; i1 < i; i1++)
            {
                char c2;
                if((c2 = ac[i1]) >= '\001' && c2 <= '\177')
                {
                    abyte0[k++] = (byte)c2;
                    continue;
                }
                if(c2 > '\u07FF')
                {
                    abyte0[k++] = (byte)(0xe0 | c2 >> 12 & 0xf);
                    abyte0[k++] = (byte)(0x80 | c2 >> 6 & 0x3f);
                    abyte0[k++] = (byte)(0x80 | c2 >> 0 & 0x3f);
                } else
                {
                    abyte0[k++] = (byte)(0xc0 | c2 >> 6 & 0x1f);
                    abyte0[k++] = (byte)(0x80 | c2 >> 0 & 0x3f);
                }
            }
     
            dataoutput.write(abyte0);
            return j + 2;
        }
     
        private byte a[];
        private int b;
        private byte c[];
    }


    Apparently, this is supposed to encrypt data, but the problem is i don't know how to call the main function of that code

    If any of you guys, understand what this code do, could you please explain to me how i can use it

    Your help is very appreciated, thank you

    - John


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Can you tell me what this code do ?

    I suggest you start out with a simpler program to learn. Try reading through the basic tutorials first. Work through those examples. Start small and work your way up.

    The Java™ Tutorials
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!