C# Key Algorithm