public void WorksEvenWhenSliceSizeAndNumberOfSlicesDoNotEvenlyDivideData() { var originalData = new [] { (byte)'C', (byte)'a', (byte)'t' }; Slice slice1 = SliceHelpers.CreateSlice( coefficients: new [] { true, false }, data: new [] { originalData[0], originalData[1] } ), slice2 = SliceHelpers.CreateSlice( coefficients: new [] { true, true }, data: new [] { (byte)(originalData[0] ^ originalData[2]), originalData[1] } ); var solver = new SliceSolver(2, 3); solver.Remember(slice2); solver.Remember(slice1); var solved = solver.TrySolve(out var solution); Assert.True(solved); Assert.NotNull(solution); Assert.Equal(solution.Length, 3); Assert.True(solution.SequenceEqual(originalData)); }
public void ProducesSolvableSequenceAfterSystematicSection() { var data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; var mixedSection = SliceHelpers.CreateGenerator( data: data, sliceSize: 2, rngFactoryDelegate: () => new RandomAdapter(new Random(0)), // Seed Random so it's deterministic isSystematic: true ).Skip(data.Length).Take(10).ToList(); var solver = new SliceSolver(2, data.Length); foreach (var slice in mixedSection) { solver.Remember(slice); } var solved = solver.TrySolve(out var solution); Assert.True(solved); Assert.NotNull(solution); Assert.True(solution.SequenceEqual(data)); }
public void PutsTwoSequentialSlicesBackTogether() { const byte value1 = 0xFF, value2 = 0x55; Slice slice1 = SliceHelpers.CreateSlice( coefficients: new [] { true, false }, data: new [] { value1 }), slice2 = SliceHelpers.CreateSlice( coefficients: new [] { false, true }, data: new [] { value2 }); var solver = new SliceSolver(1, 2); solver.Remember(slice1); solver.Remember(slice2); var solved = solver.TrySolve(out var solution); Assert.True(solved); Assert.NotNull(solution); Assert.Equal(solution.Length, 2); Assert.Equal(solution[0], value1); Assert.Equal(solution[1], value2); }
public void CanSolveWithACombinedSlice() { const byte value1 = 0xFF, value2 = 0x55; Slice slice1 = SliceHelpers.CreateSlice( coefficients: new [] { true, false }, data: new [] { value1 }), slice2 = SliceHelpers.CreateSlice( coefficients: new [] { true, true }, data: new [] { (byte)(value2 ^ value1) }); var solver = new SliceSolver(1, 2); solver.Remember(slice1); solver.Remember(slice2); var solved = solver.TrySolve(out var solution); Assert.True(solved); Assert.NotNull(solution); Assert.Equal(solution.Length, 2); Assert.Equal(solution[0], value1); Assert.Equal(solution[1], value2); }
public void PutsOneByteBackTogether() { const byte value = 0xF5; var slice = SliceHelpers.CreateSlice( coefficients: new [] { true }, data: new [] { value } ); var solver = new SliceSolver(1, 1); solver.Remember(slice); var solved = solver.TrySolve(out var solution); Assert.True(solved); Assert.NotNull(solution); Assert.Equal(solution.Length, 1); Assert.Equal(solution[0], value); }