public void Encrypt(string filePath, string outputfile) { LFSR = new LFSR(_seed, _polynomial); _inputBytesArray = File.ReadAllBytes(filePath).ToList(); _outputBytesArray = new List <byte>(); #region LocalVariables int[] inputBitsArray; int[] outputBitsArray = new int[8]; int LFSROutput; int decoded; #endregion foreach (byte _byte in _inputBytesArray) { inputBitsArray = ConvertByteToBitsArray(_byte); for (int i = 0; i < inputBitsArray.Length; i++) { LFSROutput = LFSR.GetNext(); decoded = inputBitsArray[i]; outputBitsArray[i] = LFSROutput == decoded ? 0 : 1; } _outputBytesArray.Add(ConvertBitsArrayToByte(outputBitsArray)); } File.WriteAllBytes(outputfile, _outputBytesArray.ToArray()); }
public string EncryptString(string text) { StringBuilder sb = new StringBuilder(); LFSR = new LFSR(_seed, _polynomial); int actualNumber; int actualXor; foreach (var item in text) { actualNumber = item == '1' ? 1 : 0; actualXor = LFSR.GetNext(); sb.Append((actualNumber + actualXor) % 2 == 1 ? "1" : "0"); } return(sb.ToString()); }