Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace bsk1
  8. {
  9.     class Program
  10.     {
  11.         public static String deszyfrowanie(int n = 3, String word = "CRYPTOGRAPHY")
  12.         {
  13.             List<List<Char>> list = new List<List<char>>();
  14.             for(int i=0;i<n; i++)
  15.             {
  16.                 list.Add(new List<char>());
  17.             }
  18.  
  19.             int iterator =
  20.             String result = "";
  21.             //gorna linia
  22.             for(int i=0; 2*(n-1)*i < word.Length ; i++)
  23.             {
  24.                 int twojastara = 2 * (n - 1) * i;
  25.                 list[0].Add(word[twojastara]);
  26.                 //srodki
  27.                 for(int j=1; j<n-1; j++)
  28.                 {
  29.                     if(twojastara-j > 0)
  30.                         list[j].Add(word[twojastara - j]);
  31.  
  32.                     if (twojastara+j < word.Length)
  33.                         list[j].Add(word[twojastara + j]);
  34.                 }
  35.             }
  36.             // dolna linia
  37.             for (int i = 0; 2 * (n - 1) * i + n -1 < word.Length; i++)
  38.             {
  39.                 result += word[2 * (n - 1) * i + n -1];
  40.             }
  41.            
  42.             Console.WriteLine(result);
  43.             return result;
  44.         }
  45.  
  46.         static void Main(string[] args)
  47.         {
  48.             deszyfrowanie();
  49.             Console.ReadKey();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement