public void ShouldNumCorrectly(string xStr, int expected)
        {
            var x = new BitString(MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(xStr).Reverse());

            var result = _subject.Num(x);

            Assert.AreEqual((BigInteger)expected, result);
        }
Esempio n. 2
0
        public void ShouldCorrectlyInc_s(int s, string onesAndZeroes, string expectationOnesAndZeroes)
        {
            BitString X           = new BitString(MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(onesAndZeroes));
            BitString expectation = new BitString(MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(expectationOnesAndZeroes));

            var result = _subject.inc_s(s, X);

            Assert.AreEqual(expectation, result);
        }
        public void ShouldReturnBitStringInCorrectOrderLt8Characters(string testString)
        {
            var expectation = testString.Reverse().ToArray();

            var result = MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(testString);
            var bs     = new BitString(result);

            Assert.AreEqual(expectation, bs.ToString());
        }
Esempio n. 4
0
        public void ShouldReturnJ0With96BitIvWithNoExternalCalls(string hString, string ivString, string expectedString)
        {
            BitString h          = new BitString(MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(hString));
            BitString iv         = new BitString(MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(ivString));
            BitString expectedJ0 = new BitString(MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(expectedString));

            var result = _mockSubject.Object.Getj0(h, iv);

            Assert.AreEqual(expectedJ0, result, nameof(expectedJ0));
            _mockSubject.Verify(
                v => v.GHash(It.IsAny <BitString>(), It.IsAny <BitString>()),
                Times.Never,
                nameof(_mockSubject.Object.GHash)
                );
        }
Esempio n. 5
0
        public void ShouldInvokeGHashWithAppropriateValuesWhenIvNot96Bits(string hString, string ivString)
        {
            BitString h  = new BitString(MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(hString));
            BitString iv = new BitString(MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(ivString));
            BitString fakeGHashReturn = new BitString(5);

            _mockSubject
            .Setup(s => s.GHash(It.IsAny <BitString>(), It.IsAny <BitString>()))
            .Returns(fakeGHashReturn);

            var result = _mockSubject.Object.Getj0(h, iv);

            var expectedS = 128 * 96 - iv.BitLength;
            var expectedX = iv.ConcatenateBits(new BitString(new BitArray(expectedS + 64))).ConcatenateBits(BitString.To64BitString(iv.BitLength));

            Assert.AreEqual(fakeGHashReturn, result, nameof(result));
            _mockSubject.Verify(
                v => v.GHash(It.IsAny <BitString>(), It.IsAny <BitString>()),
                Times.Once,
                nameof(_mockSubject.Object.GHash)
                );
        }
Esempio n. 6
0
        public void ShouldConvertToInt(string bitsAsZeroesAndOnes, int expectedInt)
        {
            var bArray = MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(bitsAsZeroesAndOnes);

            Assert.AreEqual(expectedInt, bArray.ToInt());
        }
 public void ShouldThrowArgumentExceptionWhenStringContainsCharactersBesidesSpaceZeroAndOne(string testString)
 {
     Assert.Throws(
         typeof(ArgumentException),
         () => MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(testString));
 }
 public void ShouldThrowArgumentNullExceptionWhenStringNullOrEmpty(string testString)
 {
     Assert.Throws(
         typeof(ArgumentNullException),
         () => MsbLsbConversionHelpers.GetBitArrayFromStringOf1sAnd0s(testString));
 }