public BitString GetNextIV() { if (_iv.BitLength < _blockSize) { _iv = BitString.Zeroes(_blockSize - _iv.BitLength).ConcatenateBits(_iv); } var currentIV = _iv.GetLeastSignificantBits(_blockSize).GetDeepCopy(); // Avoid throwing an exception by subtracting from 000...0 if (currentIV.Equals(BitString.Zeroes(_blockSize))) { _iv = BitString.Ones(_blockSize); } else { _iv = _iv.BitStringSubtraction(BitString.One()); } return(currentIV); }