How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »


RC4 cypher in C#

Main method:


Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

5 Responses to RC4 cypher in C#

  1. Brad says:

    Line “y = i % 256;” is incorrect based on RC4 examples. Should be “y = i + 1 % 256;” could we review this?

  2. Dana says:

    So, I really like your code because it is short and simple. Less is usually better. I am trying to use it to encrypt SQLAzure login info. All works fine. But when passing the encrypted field to a db using SQL, the apostrophe (char)(39) kills the SQL string (SQL requires a double apostrophe if used in a string).

    I’ve been able to cobble a crude fix that identifies the apostrophe and replaces it with another character, but this will not decrypt correctly.

    int w;
    w = (input[i] ^ box[(box[y] + box[j]) % 256]);
    string w1 = “append: ” + w;

    if (w1 != “append: 39”)
    result.Append((char)(input[i] ^ box[(box[y] + box[j]) % 256]));

    if (w1 == “append: 39”)

    Do you have a means of eliminating the apostrophe character in the random sequence?

    Thanks in advance.

    • CooLMinE says:

      Hello Dana,

      Have you tried replacing apostrophe (‘) with double apostrophe (”) before inserting the string in your database ?

      • Dana says:

        yes- using the replacement code that I sent previously. This works well for the encryption and send sql string steps, but then when I try to decrypt the changed encrypted string, the double apostrophe is interpreted differently from the original single apostrophe and so I do not get the original unencrypted string back.

        • CooLMinE says:

          You are altering the algorithm on the example you are mentioning above.

          What I suggesting was to replace the final result of the method before putting it in the database, as a method of escaping the apostrophes. That means that goes into your database is exactly the same output the method returns since ” will be replaced with ‘ when inserting.

Leave a Reply

Your email address will not be published. Required fields are marked *