コード例 #1
0
ファイル: Program.cs プロジェクト: ballance/QuickTest
        private static void CRCTestRunner()
        {
            var bytesToCrc = new byte[]         { 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47 };
            var bytesToCrcOffByOne = new byte[] { 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47 };

            var crc_guy = new CRC.Crc32();

            byte[] madeSomeCrc;
            using (var bytesToCrCMemStream = new MemoryStream(bytesToCrc))
            {
                  madeSomeCrc = crc_guy.ComputeHash(bytesToCrCMemStream);
            }

            byte[] madeSomeCrcOffByOne;
            using (var bytesToCrCOffByOneMemStream = new MemoryStream(bytesToCrcOffByOne))
            {
                madeSomeCrcOffByOne = crc_guy.ComputeHash(bytesToCrCOffByOneMemStream);
            }

            Console.WriteLine("before not off by one: {0}", Encoding.ASCII.GetString(bytesToCrc));
            Console.WriteLine("before is off by one:  {0}", Encoding.ASCII.GetString(bytesToCrcOffByOne));

            Console.WriteLine("not off one: {0}", Encoding.ASCII.GetString(madeSomeCrc));
            Console.WriteLine("Off by one:  {0}", Encoding.ASCII.GetString(madeSomeCrcOffByOne));
            Console.WriteLine();
            Console.WriteLine("Are equal? {0}", madeSomeCrc.SequenceEqual(madeSomeCrcOffByOne));
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ballance/QuickTest
        private static void CRCTestRunner()
        {
            var bytesToCrc         = new byte[]         { 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47 };
            var bytesToCrcOffByOne = new byte[] { 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47, 56, 54, 55, 53, 51, 48, 57, 47 };

            var crc_guy = new CRC.Crc32();

            byte[] madeSomeCrc;
            using (var bytesToCrCMemStream = new MemoryStream(bytesToCrc))
            {
                madeSomeCrc = crc_guy.ComputeHash(bytesToCrCMemStream);
            }

            byte[] madeSomeCrcOffByOne;
            using (var bytesToCrCOffByOneMemStream = new MemoryStream(bytesToCrcOffByOne))
            {
                madeSomeCrcOffByOne = crc_guy.ComputeHash(bytesToCrCOffByOneMemStream);
            }

            Console.WriteLine("before not off by one: {0}", Encoding.ASCII.GetString(bytesToCrc));
            Console.WriteLine("before is off by one:  {0}", Encoding.ASCII.GetString(bytesToCrcOffByOne));

            Console.WriteLine("not off one: {0}", Encoding.ASCII.GetString(madeSomeCrc));
            Console.WriteLine("Off by one:  {0}", Encoding.ASCII.GetString(madeSomeCrcOffByOne));
            Console.WriteLine();
            Console.WriteLine("Are equal? {0}", madeSomeCrc.SequenceEqual(madeSomeCrcOffByOne));
            Console.ReadKey();
        }