четверг, 23 сентября 2010 г.

Урок №3 Шифр Цезаря

Шифровка:
        public static string coding(string text,string key)
        {
            string cod=null;
            for (int i = 0,j = 0; i < text.Length; i++, j++)
            {
                cod+=Convert.ToChar((int)text[i] + (int)key[j]);
                if (j == key.Length-1) { j = 0; }               
            }
            return cod;           
        }
Дешифровка:

        public static string acoding(string text, string key)
        {
            string cod = null;
            for (int i = 0, j = 0; i < text.Length; i++, j++)
            {
                cod += Convert.ToChar((int)text[i] - (int)key[j]);
                if (j == key.Length - 1) { j = 0; }
            }
            return cod;
        }
              
            

Комментариев нет: