Cassimus

szyfr

Nov 14th, 2025
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. private static void Main(string[] args)
  2.     {
  3.         // Szyfr cezara
  4.         // 4 -klucz
  5.         // abcdefghijklmnopqrstuvwxyz - alfabet
  6.         // ada - tekst do zakodowania
  7.         // eie - zakodowany tekst
  8.  
  9.         System.Console.WriteLine("Podaj tekst do zakodowania:");
  10.         string haslo = Console.ReadLine();
  11.         System.Console.WriteLine("Podaj klucz kodowania:");
  12.         int klucz = int.Parse(Console.ReadLine());
  13.        
  14.         string zakodowana = Zakoduj(haslo, klucz);
  15.  
  16.         System.Console.WriteLine(zakodowana);
  17.     }
  18.  
  19.  
  20.     private static string Zakoduj(string haslo, int klucz)
  21.     {
  22.         string zakodowana ="";
  23.         const string alfabet = "abcdefghijklmnopqrstuvwxyz";
  24.         int znaki = alfabet.Length;
  25.  
  26.         for (int i = 0; i < haslo.Length; i++)
  27.         {
  28.             if (alfabet.Contains(haslo[i]))
  29.             {
  30.                 int znakAlfabetu = (i + klucz) % alfabet.Length;
  31.                 zakodowana += alfabet[znakAlfabetu];
  32.             }
  33.             else
  34.             {
  35.                 zakodowana+= haslo[i];
  36.             }
  37.         }
  38.         return zakodowana;
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment