Ejemplo n.º 1
0
    public void Crc16Test1()
    {
      var hash = new CRC16();

      // test Initialize()
      hash.Initialize();

      // check default settings
      Assert.AreEqual(0x0000, hash.InitValue);
      Assert.AreEqual(0x0000, hash.XorValue);
      Assert.AreEqual(16, hash.HashSize);
      Assert.AreEqual(2, hash.Hash.Length);
      Assert.AreEqual(true, hash.CanReuseTransform);
      Assert.AreEqual(true, hash.CanTransformMultipleBlocks);
      Assert.AreEqual(1, hash.InputBlockSize);
      Assert.AreEqual(1, hash.OutputBlockSize);

      // CRC16 ("") = 00000000
      var testData = ByteArrayConversion.StringToByteArray(string.Empty);
      var result = hash.ComputeHash(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "0000");

      // CRC16 ("abc") = 9738
      testData = ByteArrayConversion.StringToByteArray("abc");
      result = hash.ComputeHash(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "9738");

      // CRC32 ("ABC") = 4521
      testData = ByteArrayConversion.StringToByteArray("ABC");
      result = hash.ComputeHash(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "4521");

      // CRC16 ("CBA") = 4401
      testData = ByteArrayConversion.StringToByteArray("CBA");
      result = hash.ComputeHash(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "4401");

      // CRC16 ("12345678") = 3C9D
      testData = ByteArrayConversion.StringToByteArray("12345678");
      result = hash.ComputeHash(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "3C9D");
    }
Ejemplo n.º 2
0
    public void Crc16Test1()
    {
      var hash = new CRC16();

      // test Initialize()
      hash.Initialize();

      // check default settings
      Assert.AreEqual(0x0000, hash.InitValue);
      Assert.AreEqual(0x0000, hash.XorValue);
      Assert.AreEqual("CRC16", hash.AlgorithmName);
      Assert.AreEqual(2, hash.HashLength);

      // CRC16 ("") = 00000000
      var testData = ByteArrayConversion.StringToByteArray(string.Empty);
      var result = hash.HashData(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "0000");

      // CRC16 ("abc") = 9738
      testData = ByteArrayConversion.StringToByteArray("abc");
      result = hash.HashData(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "9738");

      // CRC32 ("ABC") = 4521
      testData = ByteArrayConversion.StringToByteArray("ABC");
      result = hash.HashData(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "4521");

      // CRC16 ("CBA") = 4401
      testData = ByteArrayConversion.StringToByteArray("CBA");
      result = hash.HashData(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "4401");

      // CRC16 ("12345678") = 3C9D
      testData = ByteArrayConversion.StringToByteArray("12345678");
      result = hash.HashData(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "3C9D");
    }