Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Szyfr
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             LinearFeedbackShiftRegister linearFeedbackShiftRegister = new LinearFeedbackShiftRegister(4);
  11.  
  12.             while(true)
  13.             {
  14.                 Console.WriteLine(linearFeedbackShiftRegister.Generate().ToString());
  15.                 Console.ReadLine();
  16.             }
  17.            
  18.         }
  19.     }
  20.  
  21.     public class LinearFeedbackShiftRegister
  22.     {
  23.         List<int> List = new List<int>();
  24.  
  25.         public LinearFeedbackShiftRegister()
  26.         {
  27.             List.Add(0);
  28.             List.Add(1);
  29.             List.Add(1);
  30.             List.Add(0);
  31.         }
  32.  
  33.         public LinearFeedbackShiftRegister(int n)
  34.         {
  35.             Random random = new Random();
  36.  
  37.             for (int i = 0; i < n; i++) List.Add(random.Next(0, 2));
  38.         }
  39.  
  40.         public int Generate()
  41.         {
  42.             int result;
  43.             int add;
  44.  
  45.             result = List[0];
  46.  
  47.             if (List[List.Count - 1] == List[0]) add = 0;
  48.             else add = 1;
  49.  
  50.             List.Add(add);
  51.  
  52.             List.RemoveAt(0);
  53.  
  54.             return result;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement