public void Encrypt() { List <char> seed = new List <char>(); for (int i = 0; i < StringSeed.Count(); i++) { //seed.Add(int.Parse(StringSeed[i].ToString())); seed.Add(StringSeed[i]); } foreach (string stream in Bytes) { //List<int> x = new List<int>(); //List<int> y = new List<int>(); //List<int> seed = new List<int>(); string outByte = ""; /* * for (int i = 0; i < stream.Count(); i++) * { * x.Add(int.Parse(stream[i].ToString())); * //y.Add(0); * } */ for (int i = 0; i < stream.Count(); i++) { int xorCounter = 0; for (int j = 0; j < Polynomial.Count(); j++) { if (Polynomial[j] == '1' && seed[j] == '1') { xorCounter++; } } if (stream[i] == '1') { xorCounter++; } //y[i] = (x[i] + y[i]) % 2; outByte += xorCounter % 2; for (int j = seed.Count() - 1; j > 0; j--) { seed[j] = seed[j - 1]; } seed[0] = outByte[i]; } output.Add(outByte); } }
public void Decrypt() { List <int> seed = new List <int>(); for (int i = 0; i < StringSeed.Count(); i++) { seed.Add(int.Parse(StringSeed[i].ToString())); } foreach (string stream in Bytes) { List <int> x = new List <int>(); List <int> y = new List <int>(); for (int i = 0; i < stream.Count(); i++) { x.Add(int.Parse(stream[i].ToString())); y.Add(0); } for (int i = 0; i < x.Count(); i++) { for (int j = 0; j < F.Count(); j++) { if (F[j] == 1) { y[i] += seed[j]; } } y[i] = (x[i] + (y[i] % 2)) % 2; for (int j = seed.Count() - 1; j > 0; j--) { seed[j] = seed[j - 1]; } seed[0] = x[i]; } output.Add(ByteToString(y)); } }