Untitled

 avatar
unknown
plain_text
10 months ago
1.5 kB
4
Indexable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    internal class Program
    {

        private static List<string> letters = new List<string>() { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };

        static void Main(string[] args)
        {
            Console.Write("Podaj ciąg znaków do zaszyfrowania: ");
            string input = Console.ReadLine();

            Console.WriteLine(zaszyfruj(input));
            Console.ReadLine();
        }

        private static string zaszyfruj(string s)
        {
            string zaszyfrowany = "";

            foreach (char c in s)
            {
                if (letters.Contains(c.ToString())) {
                    if (letters.IndexOf(c.ToString())+3 >= letters.Count())
                    {
                        zaszyfrowany += letters.ElementAt(letters.IndexOf(c.ToString()) + 3 - letters.Count());
                    } else
                    {
                        zaszyfrowany += letters.ElementAt(letters.IndexOf(c.ToString()) + 3);
                    }
                } else
                {
                    zaszyfrowany += c.ToString();
                }
            }

            return zaszyfrowany;
        }

        private static string odszyfruj(string s)
        {
            return null;
        }
    }
}
Editor is loading...
Leave a Comment