Miyerkules, Enero 11, 2012

C# ConApp 4: Encryption

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write(" enter a message ");
            string message = Console.ReadLine();


            Console.Write("Enter shift code: ");
            int code = int.Parse(Console.ReadLine());


            string alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
            string encrypted = "";
            for (int index = 0; index < message.Length; index++)
            {
                if (char.IsUpper(message, index))
                    encrypted +=
                    alphabet.Substring((alphabet.IndexOf(message.Substring(index, 1)) + code) % 26, 1);
                else
                {
                    if (char.IsLower(message, index))
                        encrypted +=
                        alphabet.ToLower().Substring(
                        (alphabet.ToLower().IndexOf(
                        message.Substring(index, 1))


                        + code) % 26, 1);


                }






            }
            Console.WriteLine("Encrypted :" + encrypted);


            Console.ReadLine();


        }
    }
}

Walang komento:

Mag-post ng isang Komento