コード例 #1
0
        public void Bitstring_Setter_ShouldThrow_WhenIncorrectSize()
        {
            var state     = new SpongeState(SpongeSize.W02, 32);
            var bitString = new BitString("101010101010101010101010101010101010101010101010");

            state.BitString = bitString;
        }
コード例 #2
0
        public void ItemAccessor_3D_Getter_ShouldReturnExpectedBit()
        {
            var bitString = new BitString("10101010101010101010101010101010101010101010101010");
            var state     = new SpongeState(bitString, 30);

            Assert.IsTrue(state[0, 0, 0]);

            for (var y = 0; y < 5; y++)
            {
                for (var x = 0; x < 5; x++)
                {
                    for (var z = 0; z < 2; z++)
                    {
                        if ((z & 1) == 0)
                        {
                            Assert.IsTrue(state[x, y, z]);
                        }
                        else
                        {
                            Assert.IsFalse(state[x, y, z]);
                        }
                    }
                }
            }
        }
コード例 #3
0
 internal SpongeBit(SpongeState state, int x, int y, int z)
 {
     State = state;
     X     = x;
     Y     = y;
     Z     = z;
 }
コード例 #4
0
        public void Bitstring_Setter_ShouldSetBitstring_WhenCorrectSize()
        {
            var state     = new SpongeState(SpongeSize.W02, 32);
            var bitString = new BitString("10101010101010101010101010101010101010101010101010");

            state.BitString = bitString;
            Assert.AreEqual("10101010101010101010101010101010101010101010101010", state.ToBinString());
        }
コード例 #5
0
        public void Clear_ShouldClearState()
        {
            var state = new SpongeState(BitString.Random(new Random(), 48), 24);

            Assert.IsTrue(state.BitString.Any(b => b));
            state.Clear();
            Assert.IsFalse(state.BitString.Any(b => b));
        }
コード例 #6
0
        public void SetPlane_ShouldSetPlaneBits()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var plane = state.GetPlane(0);

            state.SetPlane(plane, new[] { false, true, false, true, false, true, false, true, false, true });
            Assert.AreEqual("01010101011010101010101010101010101010101010101010", state.ToBinString());
        }
コード例 #7
0
        public void SetSlice_ShouldSetSliceBits()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var slice = state.GetSlice(0);

            state.SetSlice(slice, new bool[25]);
            Assert.AreEqual("00000000000000000000000000000000000000000000000000", state.ToBinString());
        }
コード例 #8
0
        public void ItemAccessor_Flat_Setter_ShouldSetExpectedBit()
        {
            var bitString = new BitString("10101010101010101010101010101010101010101010101010");
            var state     = new SpongeState(bitString, 30);

            state[1] = true;
            Assert.IsTrue(state[1]);
        }
コード例 #9
0
        public void SetSheet_ShouldSetSheetBits()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var sheet = state.GetSheet(0);

            state.SetSheet(sheet, new[] { false, true, false, true, false, true, false, true, false, true });
            Assert.AreEqual("01101010100110101010011010101001101010100110101010", state.ToBinString());
        }
コード例 #10
0
        public void Xor_ShouldXorWithByteArray()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var bytes = new byte[] { 255, 255, 255, 255, 255, 255, 255 };

            state.Xor(bytes);
            Assert.AreEqual("01010101010101010101010101010101010101010101010101", state.ToBinString());
        }
コード例 #11
0
        public void Constructor_SpongeSizeRate_ShouldCreateExpectedState()
        {
            var state = new SpongeState(SpongeSize.W04, 72);

            Assert.AreEqual(100, state.Size.B);
            Assert.AreEqual(72, state.Rate);
            Assert.AreEqual(28, state.Capacity);
        }
コード例 #12
0
        public void SetRow_ShouldSetRowBits()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var row   = state.GetRow(0, 0);

            state.SetRow(row, new bool[5]);
            Assert.AreEqual("00000000001010101010101010101010101010101010101010", state.ToBinString());
        }
コード例 #13
0
        public void SetSlices_ShouldSetSlices()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var bits  = new bool[50];

            state.SetSlices(bits);
            Assert.AreEqual("00000000000000000000000000000000000000000000000000", state.ToBinString());
        }
コード例 #14
0
        public void XorRow_ShouldPerformBitwiseXorWithBits()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var row   = state.GetRow(0, 0);
            var bits  = new[] { true, true, true, true, true };

            state.XorRow(row, bits);
            Assert.AreEqual("00000000001010101010101010101010101010101010101010", state.ToBinString());
        }
コード例 #15
0
        public void XorPlane_ShouldPerformBitwiseXorWithBits()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var plane = state.GetPlane(0);
            var bits  = new[] { true, true, true, true, true, true, true, true, true, true };

            state.XorPlane(plane, bits);
            Assert.AreEqual("01010101011010101010101010101010101010101010101010", state.ToBinString());
        }
コード例 #16
0
        public void XorColumn_ShouldPerformBitwiseXorWithBits()
        {
            var state  = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var column = state.GetColumn(0, 0);
            var bits   = new[] { true, true, true, true, true };

            state.XorColumn(column, bits);
            Assert.AreEqual("00101010100010101010001010101000101010100010101010", state.ToBinString());
        }
コード例 #17
0
        public void Constructor_SpongeState_ShouldCopy()
        {
            var state = new SpongeState(BitString.Random(new Random(), 100), 72);
            var copy  = new SpongeState(state);

            Assert.AreNotSame(state, copy);
            Assert.AreNotSame(state.BitString, copy.BitString);
            Assert.AreEqual(state.BitString, copy.BitString);
        }
コード例 #18
0
        public void ItemAccessor_3D_Setter_ShouldSetExpectedBit()
        {
            var bitString = new BitString("10101010101010101010101010101010101010101010101010");
            var state     = new SpongeState(bitString, 30);

            state[0, 0, 0] = false;
            state[0, 0, 1] = true;
            Assert.AreEqual("01101010101010101010101010101010101010101010101010", state.ToBinString());
        }
コード例 #19
0
        public void XorSheet_ShouldPerformBitwiseXorWithBits()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var sheet = state.GetSheet(0);
            var bits  = new[] { true, true, true, true, true, true, true, true, true, true };

            state.XorSheet(sheet, bits);
            Assert.AreEqual("01101010100110101010011010101001101010100110101010", state.ToBinString());
        }
コード例 #20
0
        public void GetLanes_ShouldEnumerateLanes()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);

            foreach (var lane in state.GetLanes())
            {
                var bits = lane.GetBits().ToArray();
                Assert.AreEqual(2, bits.Length);
                Assert.IsTrue(bits[0]);
                Assert.IsFalse(bits[1]);
            }
        }
コード例 #21
0
        public void SetColumn_ShouldSetColumnBits()
        {
            var state  = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var column = state.GetColumn(0, 0);

            state.SetColumn(column, new[] { false, false, false, false, false });

            for (var y = 0; y < 5; y++)
            {
                Assert.IsTrue(column.GetBits().All((b) => !b));
            }
        }
コード例 #22
0
        public void XorSlices_ShouldPerformBitwiseXorForSlices()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var bits  = new bool[50];

            for (var i = 0; i < 50; i++)
            {
                bits[i] = true;
            }

            state.XorSlices(bits);
            Assert.AreEqual("01010101010101010101010101010101010101010101010101", state.ToBinString());
        }
コード例 #23
0
        public void GetRows_ShouldEnumerateRows()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);

            foreach (var row in state.GetRows())
            {
                var rowCheck = (row.Z & 1) == 0
                                ? row.GetBits().All((b) => b)
                                : row.GetBits().All((b) => !b);

                Assert.IsTrue(rowCheck);
            }
        }
コード例 #24
0
        public void XorSlice_ShouldPerformBitwiseXorWithBits()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);
            var slice = state.GetSlice(0);
            var bits  = new bool[25];

            for (var i = 0; i < 25; i++)
            {
                bits[i] = true;
            }

            state.XorSlice(slice, bits);
            Assert.AreEqual("00000000000000000000000000000000000000000000000000", state.ToBinString());
        }
コード例 #25
0
        public void GetIndex_Coordinates_ShouldReturnCorrectIndex()
        {
            var state = new SpongeState(new BitString("1001001011101011110011010"), 12);

            for (var x = 0; x < 5; x++)
            {
                for (var y = 0; y < 5; y++)
                {
                    for (var z = 0; z < 1; z++)
                    {
                        Assert.AreEqual((5 * y) + x + z, state.GetIndex(x, y, z));
                    }
                }
            }
        }
コード例 #26
0
        public void GetBit_ShouldReturnExpectedBit()
        {
            var state = new SpongeState(new BitString("1010101010101010101010101"), 13);

            for (var i = 0; i < 25; i++)
            {
                if ((i & 1) == 0)
                {
                    Assert.IsTrue(state.GetBit(i).Value);
                }
                else
                {
                    Assert.IsFalse(state.GetBit(i).Value);
                }
            }
        }
コード例 #27
0
        public void GetSlices_ShouldEnumerateSlices()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);

            foreach (var slice in state.GetSlices())
            {
                foreach (var column in slice.GetColumns())
                {
                    var colCheck = (column.Z & 1) == 0
                                        ? column.GetBits().All((b) => b)
                                        : column.GetBits().All((b) => !b);

                    Assert.IsTrue(colCheck);
                }
            }
        }
コード例 #28
0
        public void GetLane_ShouldReturnExpectedLane()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);

            for (var y = 0; y < 5; y++)
            {
                for (var x = 0; x < 5; x++)
                {
                    var lane = state.GetLane(x, y);
                    var bits = lane.GetBits().ToArray();
                    Assert.AreEqual(2, bits.Length);
                    Assert.IsTrue(bits[0]);
                    Assert.IsFalse(bits[1]);
                }
            }
        }
コード例 #29
0
        public void ItemAccessor_Flat_Getter_ShouldReturnExpectedBit()
        {
            var bitString = new BitString("10101010101010101010101010101010101010101010101010");
            var state     = new SpongeState(bitString, 30);

            for (var i = 0; i < state.BitString.Length; i++)
            {
                if ((i & 1) == 0)
                {
                    Assert.IsTrue(state[i]);
                }
                else
                {
                    Assert.IsFalse(state[i]);
                }
            }
        }
コード例 #30
0
        public void GetSlice_ShouldReturnExpectedSlice()
        {
            var state = new SpongeState(new BitString("10101010101010101010101010101010101010101010101010"), 25);

            for (var z = 0; z < 2; z++)
            {
                var slice = state.GetSlice(z);
                foreach (var column in slice.GetColumns())
                {
                    var colCheck = (column.Z & 1) == 0
                                        ? column.GetBits().All((b) => b)
                                        : column.GetBits().All((b) => !b);

                    Assert.IsTrue(colCheck);
                }
            }
        }