public override void Start() { while (Input.IsOpen | (Input.Count > 0)) { byte[] temp = Input.Take(256 - 100); temp = ecc.Encode(temp, 100); Output.Add(temp); } Output.Complete(); }
public void TestAccountIdFromAddress() { var address = _account.Address.Replace(Constants.AddressPrefix, ""); var id = ReedSolomon.Decode(address); Assert.AreEqual(id, _account.Id); var addr1 = ReedSolomon.Encode(id); Assert.AreEqual(address, addr1); }
private System.Drawing.Bitmap Draw() { DataMatrixDefinition def = ComputeSize(); ReedSolomon rs = new ReedSolomon(new DataMatrixInitialiser(def)); _Data = rs.Encode(_Data, 1); int row = 0, col = 4; bool up = true; foreach (byte item in _Data) { Rectangle[] r = DrawCodeword(item); if (row < _Size.Height & col < _Size.Width) { Transform(r, row, col); } if (up) { row -= 2; col += 2; up = row >= 0 && col < _Size.Width; if (!up) { row += 3; col += 1; } } else { row += 2; col -= 2; up = row >= _Size.Height && col < 0; if (up) { row += 3; col += 1; } } } throw new NotImplementedException(); }
public void T01_ReedSolomon() { byte[] orig = Encoding.UTF8.GetBytes("Hello, world! Velit omnis consequatur nobis. Cum omnis ipsam rerum ut velit minus. Bye!"); ReedSolomon rs = new ReedSolomon(8); // first test the basics byte[] encoded = rs.Encode(orig); TestHelpers.AssertArrayEquals(encoded.Skip(rs.EccLength).ToArray(), orig); // test that the encoded data ends with the original data Assert.IsTrue(rs.Check(encoded)); TestHelpers.AssertArrayEquals(rs.Decode(encoded), orig); // we should be able to correct up to four errors in the encoded data encoded[7] = 77; encoded[22] = 44; encoded[62] = 11; encoded[81] = 0; Assert.IsFalse(rs.Check(encoded)); TestHelpers.AssertArrayEquals(rs.Decode(encoded), orig); // but not five encoded[2] = 1; Assert.IsNull(rs.Decode(encoded)); // however, if we specify the positions, we should be able to fix more TestHelpers.AssertArrayEquals(rs.Decode(encoded, new[] { 2, 7, 22, 62, 81 }, true), orig); encoded[12] = 2; TestHelpers.AssertArrayEquals(rs.Decode(encoded, new[] { 2, 7, 12, 22, 62 }, false), orig); // in fact should be able to fix at least eight errors encoded[23] = 3; encoded[40] = 4; TestHelpers.AssertArrayEquals(rs.Decode(encoded, new[] { 2, 7, 12, 22, 23, 40, 62, 81 }, true), orig); TestHelpers.AssertArrayEquals(rs.Decode(encoded, new[] { 2, 7, 12, 22, 23, 40, 62, 81 }, false), orig); // but not nine errors encoded[70] = 5; Assert.IsNull(rs.Decode(encoded, new[] { 2, 7, 12, 22, 23, 40, 62, 70, 81 }, true)); // now try the methods that take array indexes byte[] orig2 = new byte[orig.Length / 2]; int encodedLength = orig2.Length + rs.EccLength; Array.Copy(orig, orig2, orig2.Length); rs.Encode(orig, 0, orig.Length / 2, encoded, 10); // first, try the basic decoding Assert.IsTrue(rs.Check(encoded, 10, orig2.Length + rs.EccLength)); TestHelpers.AssertArrayEquals(rs.Decode(encoded, 10, encodedLength), orig2); byte[] decoded = new byte[orig2.Length + 30]; Assert.AreEqual(orig2.Length, rs.Decode(encoded, 10, encodedLength, decoded, 20)); TestHelpers.AssertArrayEquals(decoded.Skip(20).Take(orig2.Length).ToArray(), orig2); // now fix four errors with positions unspecified encoded[11] = 77; encoded[17] = 44; encoded[23] = 11; encoded[34] = 0; Assert.AreEqual(orig2.Length, rs.Decode(encoded, 10, encodedLength, decoded, 20)); TestHelpers.AssertArrayEquals(decoded.Skip(20).Take(orig2.Length).ToArray(), orig2); // now fix eight errors with positions specified encoded[13] = 1; encoded[19] = 2; encoded[27] = 3; encoded[31] = 4; Assert.AreEqual(-1, rs.Decode(encoded, 10, encodedLength, decoded, 20)); // check that it gives a failure result without positions Assert.AreEqual(orig2.Length, rs.Decode(encoded, 10, encodedLength, decoded, 20, new[] { 1, 3, 7, 9, 13, 17, 21, 24 })); TestHelpers.AssertArrayEquals(decoded.Skip(20).Take(orig2.Length).ToArray(), orig2); }
internal string GetReedSolomonFromAccountId(ulong accountId) { return(ReedSolomon.Encode(accountId)); }
private System.Drawing.Bitmap Draw() { DataMatrixDefinition def = ComputeSize(); ReedSolomon rs = new ReedSolomon(new DataMatrixInitialiser(def)); _Data = rs.Encode(_Data, 1); int row = 0, col = 4; bool up = true; foreach (byte item in _Data) { Rectangle[] r = DrawCodeword(item); if (row < _Size.Height & col < _Size.Width) Transform(r, row, col); if (up) { row -= 2; col += 2; up = row >= 0 && col < _Size.Width; if (!up) { row += 3; col += 1; } } else { row += 2; col -= 2; up = row >= _Size.Height && col < 0; if (up) { row += 3; col += 1; } } } throw new NotImplementedException(); }
/// <summary> /// Gets an address from a given id /// </summary> /// <param name="id">Address id</param> /// <returns></returns> public static string GetAddress(ulong id) { var address = ReedSolomon.Encode(id); return($"{Constants.AddressPrefix}{address}"); }