Exemplo n.º 1
0
    public void XCrcTest1()
    {
      var hash = new XCRC();

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

      // check default settings
      Assert.AreEqual(0xA695, hash.InitValue);
      Assert.AreEqual(0xffff, 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);

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

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

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

      // XCRC ("CBA") = 443E
      testData = ByteArrayConversion.StringToByteArray("CBA");
      result = hash.ComputeHash(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      Test.TestSupport.CheckResult(result, "443E");

      // XCRC ("12345678") = 8E37
      testData = ByteArrayConversion.StringToByteArray("12345678");
      result = hash.ComputeHash(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      Test.TestSupport.CheckResult(result, "8E37");
    }
Exemplo n.º 2
0
    public void XCrcTest1()
    {
      var hash = new XCRC();

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

      // check default settings
      Assert.AreEqual(0xA695, hash.InitValue);
      Assert.AreEqual(0xffff, hash.XorValue);
      Assert.AreEqual("XCRC", hash.AlgorithmName);
      Assert.AreEqual(2, hash.HashLength);

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

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

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

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

      // XCRC ("12345678") = 8E37
      testData = ByteArrayConversion.StringToByteArray("12345678");
      result = hash.HashData(testData, 0, testData.Length);
      Assert.AreEqual(2, result.Length);
      TestSupport.CheckResult(result, "8E37");
    }