Posts Tagged ‘C#’

/r/dailyprogrammer – Stream Cipher

Thursday, July 16th, 2015

This time around I thought the stream cipher programming challenge sounded like fun. The program encodes a character string and then decodes it back to the original text using the RC4 method. Below is an example input/output, followed by the code.

CipherOutput

class Program
{
    static void Main(string[] args)
    {
        const int KEY = 31337;
        string message = "High five, bro";

        Console.WriteLine("----Stream Cipher----\n");
        Console.WriteLine("Original Message: " + message + "\n");

        var cipherText = encrypt(message, KEY);
        Console.WriteLine("Cipher Text: " + cipherText + "\n");

        var plainText = decrypt(cipherText, KEY);
        Console.WriteLine("Plain Text: " + plainText);

        Console.ReadLine();
    }

    static string encrypt( string msg, int key )
    {
        int seed = key;
        int m = 255;
        int a = 124;
        int c = 32;
        byte[] bytes = Encoding.Default.GetBytes(msg);
        var value = ((seed * a) + c) % m;

        for (var b = 0; b < bytes.Length; ++b )
        {
            bytes[b] ^= (byte)value;
        }

        return Encoding.Default.GetString(bytes);
    }

    static string decrypt(string cipher, int key)
    {
        return encrypt(cipher, key);
    }
}

/r/dailyprogrammer – Poetry in a Haystack

Sunday, July 5th, 2015

I decided to start participating in some of the programming challenges in the dailyprogrammer subreddit. I'm not saying I'm going to do them every day, but maybe one a week; we'll see! The challenge from July 3 is the first one I've attempted. The challenge is to find 3 lines from a famous poem given a text file with 50000 lines in it. Of those 50000 lines, 49997 of them are gibberish. I will be solving the challenges in C# unless otherwise noted. (more…)

MediaNamer – Easily Organize Your TV Shows

Tuesday, February 17th, 2015

Well, I'm not dead, but I have been MIA here for quite some time. Without going into too much detail, the last few months I've been very busy and haven't had as much time for personal projects as I would like. Luckily this last weekend I had some free time and found a problem to solve. (more…)

Flash: Direct Memory Access via Native Extension

Sunday, April 28th, 2013

A couple weeks before the Flash Gaming Summit I found an interesting blog post from Colin Northway about managing texture memory in Starling applications. In this post he describes how he forces an error in ActionScript to receive an object's memory address which he then uses as a unique id. I thought this was a pretty cool trick and was discussing it with our engine developer at the office when we suddenly had a thought: if you can get the memory address of an object in ActionScript, what's to stop you from passing that address into native code and doing whatever you want with it? (more…)

Tutorial: Debugging Native Extensions

Sunday, April 7th, 2013

I've written before about how to create your own native extensions for Adobe AIR, but what if you need to debug your extension? If you're doing anything but the simplest of projects, you're going to want to be able to debug the code on the native side, in addition to your AS3 code. The ActionScript side is (hopefully!) already taken care of by your IDE so this tutorial will focus on the native code. It's a pretty short tutorial, but also incredibly useful! (more…)

Tutorial: Flash and C++ Native Extension

Monday, April 30th, 2012

Last week I decided to look into building a native extension for AIR and was very surprised by the lack of quality resources and tutorials for doing so. I was able to find examples for Android using Java and for iOS using Objective-C, but pretty much nothing for a standard Windows C++ project. I was eventually able to get things up and running by piecing together bits of information from various sources, but I thought I'd take the time to write a step-by-step tutorial on how to do this so that perhaps others will have an easier time. In this tutorial you will create a native extension that simply adds two numbers together and returns the sum. (more…)

Finally! No betas! Flash and Kinect using the version 1 SDK

Sunday, February 19th, 2012

Out of all the articles and tutorials I've written, by far the most popular have been the Flash and Kinect pieces. Since the February 1st release of the version 1 Kinect SDK, I've gotten quite a few questions about how to get Flash working with Kinect again. Many readers were having trouble with the old tutorials which no longer work as they were based on the beta release of the SDK. I decided to take a break from my current project this weekend and throw together a quick Kinect to Flash demonstration with the new SDK. This isn't a tutorial, but you can download the source files and see how it was made! (more…)

Flash + Kinect = Success!

Friday, July 1st, 2011

If you've read my previous posts then you know I have been working with Microsoft's Kinect SDK for Windows. One of my goals from the start was to integrate Kinect with Flash and earlier this week I was successful in doing just that! I used a technique similar to what the Blitz Agency had done when the Prime Sense Kinect drivers were released earlier this year.

The concept is pretty simple: Kinect tracks the user's hand, sends the position data to a server and that server sends the data to Flash. I started by writing a very simple server with Node.js and then modified the skeletal tracking demo from the channel9 site to send data to the server using a standard socket. The only thing left to do then was set up an swf file to accept data from the server and use that data to move around a cursor. I'll post something more in-depth on this later, but for now you can check out the video below to see it in action!

Subscribe to RSS feed FGS5 Badge