c#

Stir Trek 2: Iron Man Edition

When: 
Friday, May 7, 2010 - 7:30am - 7:00pm

Stir Trek is an opportunity to learn about the newest advances in web and mobile development. There will be 20 sessions, in four tracks, so you’ll be able to pick the content that interests you the most. In addition, the day will include lunch, a raffle with some significant prizes, and a private screening of the new IronMan 2 movie, which opens in theaters the day of this event.

Visit http://www.stirtrek.com/ for more information.

Central Ohio Day of .NET 2010

When: 
Saturday, June 5, 2010 - 8:00am - 5:00pm

Central Ohio Day of .NET

The Central Ohio Day of .NET is a joint venture between the Dayton .NET Developers Group, Central Ohio .NET Developers Group, Cincinnati SQL Server Users Group and the Cincinnati .NET Users Group. The event originally was called the Cincinnati-Dayton Area Code camp and ran in 2006 and 2007 under that name. With the inclusion of the Columbus And CincySQL group the event has been renamed to the Central Ohio Day of .NET. The event is a FREE day of technology discussions devoted to helping the local development community grow. Please check back often for more information about Day of .NET events.

Day of .NET events are a series of mini-conferences organized by developers for developers. You can find out more about Day of .NET events, including seeing upcoming events, on the series website at http://www.dodn.org.
Central Ohio Day of .NET 2010!

The Cincinnati .Net Users Group, Central Ohio .NET Developers Group, Dayton .Net Developers Group and Cincinnati SQL Users Group will be hosting this year's Central Ohio Day of .NET on June 5th, 2010. The event will be held at the Roberts Centre in Wilmington, OH (off exit 50 on I-71).

899. Ws Cipher

https://www.spoj.pl/problems/WSCIPHER/

 

Weird Wally's Wireless Widgets, Inc. manufactures an eclectic assortment of small, wireless, network capable devices, ranging from dog collars, to pencils, to fishing bobbers. All these devices have very small memories. Encryption algorithms like Rijndael, the candidate for the Advanced Encryption Standard (AES) are demonstrably secure but they don't fit in such a tiny memory. In order to provide some security for transmissions to and from the devices, WWWW uses the following algorithm, which you are to implement.

Encrypting a message requires three integer keys, k1, k2, and k3. The letters [a-i] form one group, [j-r] a second group, and everything else ([s-z] and underscore) the third group. Within each group the letters are rotated left by ki positions in the message. Each group is rotated independently of the other two. Decrypting the message means doing a right rotation by ki positions within each group.

Consider the message the_quick_brown_fox encrypted with ki values of 2, 3 and 1. The encrypted string is _icuo_bfnwhoq_kxert. The figure below shows the decrypting right rotations for one character in each of the three character groups.

Looking at all the letters in the group [a-i] we see {i,c,b,f,h,e} appear at positions {2,3,7,8,11,17} within the encrypted message. After a right rotation of k1=2, these positions contain the letters {h,e,i,c,b,f}. The table below shows the intermediate strings that come from doing all the rotations in the first group, then all rotations in the second group, then all the rotations in the third group. Rotating letters in one group will not change any letters in any of the other groups.

  [a-i], k1= 2 [j-r], k2= 3 [s-z] and _, k3= 1
Encrypted: _icuo_bfnwhoq_kxert _heuo_icnwboq_kxfrt _heuq_ickwbro_nxfot
Decrypted: _heuo_icnwboq_kxfrt _heuq_ickwbro_nxfot the_quick_brown_fox
Changes:
 ^^   ^^  ^     ^  
    ^   ^  ^^ ^  ^  
^  ^ ^   ^   ^ ^  ^  

All input strings contain only lowercase letters and underscores(_). Each string will be at most 80 characters long. The ki are all positive integers in the range 1-100.

Input consists of information for one or more encrypted messages. Each problem begins with one line containing k1, k2, and k3 followed by a line containing the encrypted message. The end of the input is signalled by a line with all key values of 0.

For each encrypted message, the output is a single line containing the decrypted string.

Input:
2 3 1
_icuo_bfnwhoq_kxert
1 1 1
bcalmkyzx
3 7 4
wcb_mxfep_dorul_eov_qtkrhe_ozany_dgtoh_u_eji
2 4 3
cjvdksaltbmu
0 0 0
Output:
the_quick_brown_fox
abcklmxyz
the_quick_brown_fox_jumped_over_the_lazy_dog
ajsbktcludmv

Added by:Wanderley Guimarães
Date:2006-06-09
Time limit:1s
Source limit:50000B
Languages:All except: ERL TECS JS
Resource:ACM Mid Central Regionals 2001

 

My Solution

using System;
using System.Collections.Generic;
 
namespace www.spoj.pl._899_WSCIPHER
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.In.ReadLine();
                string[] nums = line.Split(new char[] { ' ' });
                if (nums.Length == 3)
                {
                    int k1 = 0;
                    int.TryParse(nums[0], out k1);
                    int k2 = 0;
                    int.TryParse(nums[1], out k2);
                    int k3 = 0;
                    int.TryParse(nums[2], out k3);
 
                    if (k1 == 0 && k2 == 0 && k3 == 0)
                        break;
 
                    string ciphertext = Console.In.ReadLine();
 
                    CipherGroup Group1 = new CipherGroup(k1);
                    CipherGroup Group2 = new CipherGroup(k2);
                    CipherGroup Group3 = new CipherGroup(k3);
                    int len = ciphertext.Length;
                    for (int i = 0; i < len; i++)
                    {
                        char c = ciphertext[i];
                        if (c >= 'a' && c <= 'i')
                        {
                            Group1.Add(c, i);
                        }
                        else if (c >= 'j' && c <= 'r')
                        {
                            Group2.Add(c, i);
                        }
                        else
                        {
                            Group3.Add(c, i);
                        }
                    }
 
                    Group1.Rotate();
                    Group2.Rotate();
                    Group3.Rotate();
 
                    string[] letters = new string[len];
                    Group1.AddToArray(letters);
                    Group2.AddToArray(letters);
                    Group3.AddToArray(letters);
 
                    Console.WriteLine(string.Join("", letters));
                }
            }
        }
    }
 
    public class CipherGroup
    {
        public int k { get; set; }
        public List<char> Letters { get; set; }
        public List<int> Positions { get; set; }
        public CipherGroup(int k1)
        {
            k = k1;
            Letters = new List<char>();
            Positions = new List<int>();
        }
        public void Add(char c, int p)
        {
            Letters.Add(c);
            Positions.Add(p);
        }
        public void Rotate()
        {
            int len = Letters.Count;
            if (len == 0) return;
            for (int i = 0; i < k; i++)
            {
                Letters.Insert(0, Letters[len - 1]);
                Letters.RemoveAt(len);
            }
        }
 
        public void AddToArray(string[] letters)
        {
            int len = Letters.Count;
            for (int i = 0; i < len; i++)
            {
                letters[Positions[i]] = Letters[i].ToString();
            }
        }
    }
}

1026. Questions and answers

http://acm.timus.ru/problem.aspx?space=1&num=1026
Time Limit: 2.0 second
Memory Limit: 16 MB

Background

The database of the Pentagon contains a top-secret information. We don’t know what the information is — you know, it’s top-secret, — but we know the format of its representation. It is extremely simple. We don’t know why, but all the data is coded by the natural numbers from 1 up to 5000. The size of the main base (we’ll denote it be N) is rather big — it may contain up to 100 000 those numbers. The database is to process quickly every query. The most often query is: "Which element is i-th by its value?"— with i being a natural number in a range from 1 to N.

Problem

Your program is to play a role of a controller of the database. In the other words, it should be able to process quickly queries like this.

Input

Input of the problem consists of two parts. At first, a database is written, and then there’s a sequence of queries. The format of database is very simple: in the first line there’s a number N, in the next N lines there are numbers of the database one in each line in an arbitrary order. A sequence of queries is written simply as well: in the first line of the sequence a number of queries K (1 ≤ K ≤ 100) is written, and in the next K lines there are queries one in each line. The query "Which element is i-th by its value?" is coded by the number i. A database is separated from a sequence of queries by the string of three symbols "#".

Output

The output should consist of K lines. In each line there should be an answer to the corresponding query. The answer to the query "i" is an element from the database, which is i-th by its value (in the order from the least up to the greatest element).

Sample

inputoutput
5
7
121
123
7
121
###
4
3
3
2
5

121
121
7
123
Problem Author: Leonid Volkov
Problem Source: Ural State University Internal Contest October'2000 Junior Session

My Solution

using System;
using System.Collections;
using System.Globalization;
 
namespace acm.timus.ru_p1026
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList list = new ArrayList(100000);
            NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;
            string[] input = Console.In.ReadToEnd().Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            int i = 0;
            int len1 = Int32.Parse(input[0]);
            for (i = 1; i <= len1; i++)
            {
                int n = Int32.Parse(input[i]);               
                list.Add(n);
            }
            int len2 = Int32.Parse(input[len1+2]) + len1 + 3;
            list.Sort();
            for (int j = len1 + 3; j < len2; j++)
            {
                int n = Int32.Parse(input[j])-1;
                Console.WriteLine(list[n]);
            }
        }
    }
}

Asp.net: File Download Handler

Recently I had the need to make a file download page where statistics could be collected and saved on each individual download. After a little research I found a nice way to get this task done easily.

Because it is only collecting stats about the download and then sending the file to the browser, I decided to use an Asp.net Generic Handler.


Download.ashx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
 
namespace WriteFileTest
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Download : IHttpHandler
    {
 
        private string FilesPath
        {
            get
            {
                return @"C:\Users\John Boker\Documents\Visual Studio 2008\Projects\WriteFileTest\Files\";
            }
        }
 
        public void ProcessRequest(HttpContext context)
        {
            string filename = context.Request.QueryString["file"];
            if (!string.IsNullOrEmpty(filename) && File.Exists(FilesPath + filename))
            {
                context.Response.ContentType = "application/octet-stream";
                context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", filename));
                context.Response.WriteFile(FilesPath + filename);
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Invalid filename");
            }
        }
 
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

One advantage to this method is the files do not have to be in the website directories and public, extra authentication can be done and the download can be disallowed if necessary.


To test this i created a small Default.aspx page containing:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WriteFileTest._Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <a href="Download.ashx?file=FileZilla_3.3.0.1_win32-setup.exe&d=<%= DateTime.Now.Ticks %>">FileZilla_3.3.0.1_win32-setup.exe</a>
        <br />
        <a href="Download.ashx?file=gimp-2.6.7-i686-setup.exe&d=<%= DateTime.Now.Ticks %>">gimp-2.6.7-i686-setup.exe</a>
        <br />
        <a href="Download.ashx?file=jdk-6u17-windows-x64.exe&d=<%= DateTime.Now.Ticks %>">jdk-6u17-windows-x64.exe</a>
        <br />
        <a href="Download.ashx?file=WampServer2.0i.exe&d=<%= DateTime.Now.Ticks %>">WampServer2.0i.exe</a>
    </div>
    </form>
</body>
</html>

As you can see i added another argument to the QueryString; this is to keep the browser from caching files with the same link and filename.

WriteFile Default Page Image

The results after clicking the filezilla link:

WriteFile Save Dialog

This was a very simple method to take care of multiple issues including:

  1. Download Tracking
  2. Alternate File Locations
  3. Browser Caching Issues
  4. Extra Authentication

Syndicate content