January 2011

You are browsing the site archives by month.

Fixing NetBeans 6.9 else Indentation

It’s annoying when IDE didn’t make coding process easier. For this case is NetBeans 6.9, this netbeans version annoy me when i type “else” word. After typing “else”, the word become at the most left of the editor (without indentation) like code below. What’s wrong, NetBeans 6.8 still okay with this case.

public class Class {

    public void method()
    {

        if (foo)
        {
            doSomething();
        }
 else
        {
            doSomethingElse();
        }
    }

}

Read More →

Rail-Fence Cipher C# Source Code

The rail-fence cipher algorithm has been posted before so this post just show how to implement the algorithm to programming language in C#. First of all always the encryption method:

public static string Encrypt(int rail, string plainText)
{
    List<string> railFence = new List<string>();
    for (int i = 0; i < rail; i++)
    {
        railFence.Add("");
    }

    int number = 0;
    int increment = 1;
    foreach (char c in plainText)
    {
        if (number + increment == rail)
        {
            increment = -1;
        }
        else if (number + increment == -1)
        {
            increment = 1;
        }
        railFence[number] += c;
        number += increment;
    }

    string buffer = "";
    foreach (string s in railFence)
    {
        buffer += s;
    }
    return buffer;
}

Read More →