private bool CompareCrc64(string localFile, string crc64ecma)
        {
            Crc64.InitECMA();
            String hash = String.Empty;

            using (FileStream fs = File.Open(localFile, FileMode.Open))
            {
                byte[] buffer = new byte[2048];
                int    bytesRead;
                ulong  crc = 0;

                while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ulong partCrc = Crc64.Compute(buffer, 0, bytesRead);
                    if (crc == 0)
                    {
                        crc = partCrc;
                    }
                    else
                    {
                        crc = Crc64.Combine(crc, partCrc, bytesRead);
                    }
                }

                localFileCrc64 = crc.ToString();
                return(localFileCrc64 == crc64ecma);
            }
        }
Exemple #2
0
        public Scheme(string title)
        {
            Title = title;
            var key = Encodings.cp932.GetBytes(title);

            Hash = Crc64.Compute(key, 0, key.Length);
        }
Exemple #3
0
 public void Crc64Test()
 {
     byte[] hash;
     foreach (var item in Data)
     {
         hash = Crc64.Compute(item, item.Length);
     }
 }
Exemple #4
0
        public void TestCrcCore()
        {
            string testStr = "This is a test.";

            byte[] content = Encoding.ASCII.GetBytes(testStr);
            Crc64.InitECMA();
            ulong crc = Crc64.Compute(content, 0, content.Length, 0);

            Assert.AreEqual(crc, 2186167744391481992);
        }
Exemple #5
0
        public void TestCrcCore()
        {
            string testStr = "This is a test.";

            byte[] content = Encoding.ASCII.GetBytes(testStr);
            Crc64  crc64   = new Crc64();

            Assert.Equal(2186167744391481992UL, crc64.Compute(content, 0, content.Length, 0));

            crc64 = new Crc64();
            Assert.Equal(2186167744391481992UL, crc64.Compute(content, 0, content.Length));
        }
Exemple #6
0
        public bool AddFile(ArchiveFileInfo archiveFileInfo)
        {
            var hash = Crc64.Compute(archiveFileInfo.FileName);

            files.Add(new FileEntry()
            {
                Hash     = hash,
                FileData = archiveFileInfo.FileData,
                FileName = archiveFileInfo.FileName,
            });
            return(true);
        }
Exemple #7
0
        public void Execute()
        {
            unsafe
            {
                var ptr        = Translations.GetUnsafeReadOnlyPtr();
                var lengthByte = FixTranslation.BYTE_SIZE * Translations.Length;
                Hash[0] = Crc64.Compute(ptr, lengthByte);

                ptr        = Entities.GetUnsafeReadOnlyPtr();
                lengthByte = sizeof(int) * 2 * Entities.Length;
                Hash[0]   ^= Crc64.Compute(ptr, lengthByte);
            }
        }
Exemple #8
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int index = _innerStream.Read(buffer, offset, count);

            if (index > 0)
            {
                crc64.Compute(buffer, 0, index);
                md5.TransformBlock(buffer, offset, index, buffer, 0);
            }
            else
            {
                md5.TransformFinalBlock(buffer, offset, 0);
                _ref["md5"] = Convert.ToBase64String(md5.Hash);
                _ref["crc"] = crc64.CrcValue.ToSafeString();
            }
            return(index);
        }
Exemple #9
0
        public void TestCrcCompute()
        {
            ulong[] crcVals = { 0x0 /*0*/,                 0x330284772E652B05, 0xBC6573200E84B046, 0x2CD8094A1A277627, 0x3C9D28596E5960BA,
                                0x40BDF58FB0895F2 /*5*/,   0xD08E9F8545A700F4, 0xEC20A3A8CC710E66, 0x67B4F30A647A0C59, 0x9966F6C89D56EF8E,
                                0x32093A2ECD5773F4 /*10*/, 0x8A0825223EA6D221, 0x8562C0AC2AB9A00D, 0x3EE2A39C083F38B4, 0x1F603830353E518A,
                                0x2FD681D7B2421FD /*15*/,  0x790EF2B16A745A41, 0x3EF8F06DACCDCDDF,  0x49E41B2660B106D, 0x561CC0CFA235AC68,
                                0xD4FE9EF082E69F59 /*20*/, 0xE3B5E46CD8D63A4D, 0x865AAF6B94F2A051, 0x7ECA10D2F8136EB4, 0xD7DD118C98E98727,
                                0x70FB33C119C29318 /*25*/, 0x57C891E39A97D9B7, 0xA1F46BA20AD06EB7, 0x7AD25FAFA1710407, 0x73CEF1666185C13F,
                                0xB41858F73C389602 /*30*/ };

            string[] textVals = { "" /*0*/,                                                                                                                               "a", "ab", "abc", "abcd", "abcde" /*5*/, "abcdef", "abcdefg", "abcdefgh", "abcdefghi", "abcdefghij" /*10*/,
                                  "Discard medicine more than two years old.",
                                  "He who has a shady past knows that nice guys finish last.",
                                  "I wouldn't marry him with a ten foot pole.",
                                  "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave",
                                  "The days of the digital watch are numbered.  -Tom Stoppard" /*15*/,
                                  "Nepal premier won't resign.",
                                  "For every action there is an equal and opposite government program.",
                                  "His money is twice tainted: 'taint yours and 'taint mine.",
                                  "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977",
                                  "It's a tiny change to the code and not completely disgusting. - Bob Manchek" /*20*/,
                                  "size:  a.out:  bad magic",
                                  "The major problem is with sendmail.  -Mark Horton",
                                  "Give me a rock, paper and scissors and I will move the world.  CCFestoon",
                                  "If the enemy is within range, then so are you.",
                                  "It's well we cannot hear the screams/That we create in others' dreams." /*25*/,
                                  "You remind me of a TV show, but that's all right: I watch it anyway.",
                                  "C is as portable as Stonehedge!!",
                                  "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley",
                                  "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction.  Lewis-Randall Rule",
                                  "How can you write a big system without C++?  -Paul Glick" /*30*/ };

            Crc64.InitECMA();
            for (int i = 0; i < crcVals.Length; i++)
            {
                byte[] content = Encoding.ASCII.GetBytes(textVals[i]);
                ulong  crc     = Crc64.Compute(content, 0, content.Length, 0);
                System.Console.WriteLine("{0:X}", crc);
                Assert.AreEqual(crc, crcVals[i]);
            }
        }
Exemple #10
0
        public void TestCombine()
        {
            string str1 = "this is a test.";
            string str2 = "hello world.";
            string str  = str1 + str2;

            byte[] content1 = Encoding.ASCII.GetBytes(str1);
            byte[] content2 = Encoding.ASCII.GetBytes(str2);
            byte[] content  = Encoding.ASCII.GetBytes(str);

            Crc64.InitECMA();
            ulong crc1 = Crc64.Compute(content1, 0, content1.Length);
            ulong crc2 = Crc64.Compute(content2, 0, content2.Length);
            ulong crc  = Crc64.Compute(content, 0, content.Length);

            Assert.AreEqual(crc, Crc64.Combine(crc1, crc2, content2.Length));

            ulong crc3 = Crc64.Compute(content2, 0, content2.Length, crc1);

            Assert.AreEqual(crc3, crc);
        }
Exemple #11
0
    static ulong GetHashFromNetMessageTypes(Type[] netMessageTypes)
    {
        StringBuilder concatenatedNamesBuilder = new StringBuilder();

        foreach (var t in netMessageTypes)
        {
            concatenatedNamesBuilder.Append(t.FullName);
        }

        string concatenatedNames = concatenatedNamesBuilder.ToString();

        byte[] crcData = new byte[concatenatedNames.Length * 2]; // each char is 2 bytes

        BitStreamWriter writer = new BitStreamWriter(crcData);

        for (int i = 0; i < concatenatedNames.Length; i++)
        {
            writer.WriteChar(concatenatedNames[i]);
        }

        return(Crc64.Compute(crcData));
    }
Exemple #12
0
        public void TestCrcCombine()
        {
            string text = "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley";

            byte[] content = Encoding.ASCII.GetBytes(text);
            Crc64.InitECMA();
            ulong crc = Crc64.Compute(content, 0, content.Length);

            for (int i = 1; i < text.Length; i++)
            {
                string before   = text.Substring(0, i);
                string after    = text.Substring(i);
                byte[] content1 = Encoding.ASCII.GetBytes(before);
                byte[] content2 = Encoding.ASCII.GetBytes(after);

                ulong crc1 = Crc64.Compute(content1, 0, content1.Length);
                ulong crc2 = Crc64.Compute(content2, 0, content2.Length);
                Assert.AreEqual(crc, Crc64.Combine(crc1, crc2, content2.Length));

                ulong crc3 = Crc64.Compute(content2, 0, content2.Length, crc1);
                Assert.AreEqual(crc3, crc);
            }
        }
Exemple #13
0
        public static void WriteIndex(this BinaryWriter bw, Index index)
        {
            // write the table to a stream to calculate the size
            using var ms          = new MemoryStream();
            using var tablewriter = new BinaryWriter(ms);

            index.FileEntryCount          = (uint)index.FileEntries.Count;
            index.FileSegmentCount        = (uint)index.FileSegments.Count;
            index.ResourceDependencyCount = (uint)index.Dependencies.Count;
            //tablewriter.Write(Crc);
            tablewriter.Write(index.FileEntryCount);
            tablewriter.Write(index.FileSegmentCount);
            tablewriter.Write(index.ResourceDependencyCount);

            foreach (var archiveItem in index.FileEntries)
            {
                tablewriter.WriteFileEntry(archiveItem.Value);
            }

            foreach (var offsetEntry in index.FileSegments)
            {
                tablewriter.WriteFileSegment(offsetEntry);
            }

            foreach (var dependency in index.Dependencies)
            {
                tablewriter.WriteDependency(dependency);
            }

            index.FileTableOffset = 8; //TODO
            bw.Write(index.FileTableOffset);
            bw.Write((uint)ms.Length + 8);
            //crc64 calculate
            bw.Write(Crc64.Compute(tablewriter.BaseStream.ToByteArray()));
            bw.Write(tablewriter.BaseStream.ToByteArray());
        }
Exemple #14
0
        public void Write(BinaryWriter bw)
        {
            // write the table to a stream to calculate the size
            using var ms          = new MemoryStream();
            using var tablewriter = new BinaryWriter(ms);

            Table1count = (uint)FileInfo.Count;
            Table2count = (uint)Offsets.Count;
            Table3count = (uint)Dependencies.Count;
            //tablewriter.Write(Checksum);
            tablewriter.Write(Table1count);
            tablewriter.Write(Table2count);
            tablewriter.Write(Table3count);

            foreach (var archiveItem in FileInfo)
            {
                archiveItem.Value.Write(tablewriter);
            }

            foreach (var offsetEntry in Offsets)
            {
                offsetEntry.Write(tablewriter);
            }

            foreach (var dependency in Dependencies)
            {
                dependency.Write(tablewriter);
            }

            Num = 8; //TODO
            bw.Write(Num);
            bw.Write((uint)ms.Length + 8);
            //crc64 calculate
            bw.Write(Crc64.Compute(tablewriter.BaseStream.ToByteArray()));
            bw.Write(tablewriter.BaseStream.ToByteArray());
        }
Exemple #15
0
        public void Write(BinaryWriter bw)
        {
            // write the table to a stream to calculate the size
            using var ms          = new MemoryStream();
            using var tablewriter = new BinaryWriter(ms);

            FileEntryCount          = (uint)FileEntries.Count;
            FileSegmentCount        = (uint)FileSegments.Count;
            ResourceDependencyCount = (uint)Dependencies.Count;
            //tablewriter.Write(Crc);
            tablewriter.Write(FileEntryCount);
            tablewriter.Write(FileSegmentCount);
            tablewriter.Write(ResourceDependencyCount);

            foreach (var archiveItem in FileEntries)
            {
                archiveItem.Value.Write(tablewriter);
            }

            foreach (var offsetEntry in FileSegments)
            {
                offsetEntry.Write(tablewriter);
            }

            foreach (var dependency in Dependencies)
            {
                dependency.Write(tablewriter);
            }

            FileTableOffset = 8; //TODO
            bw.Write(FileTableOffset);
            bw.Write((uint)ms.Length + 8);
            //crc64 calculate
            bw.Write(Crc64.Compute(tablewriter.BaseStream.ToByteArray()));
            bw.Write(tablewriter.BaseStream.ToByteArray());
        }
Exemple #16
0
 public virtual ulong ComputeHash(byte[] name)
 {
     return(Crc64.Compute(name, 0, name.Length));
 }
Exemple #17
0
        public static ulong GetKey(string title)
        {
            var key = Encodings.cp932.GetBytes(title);

            return(Crc64.Compute(key, 0, key.Length));
        }
 protected override void HashCore(byte[] array, int ibStart, int cbSize)
 {
     crc64 = Crc64.Compute(array, ibStart, cbSize, crc64);
 }
Exemple #19
0
        public void ShortAsciiString2()
        {
            var actual = Crc64.Compute(SimpleBytes2);

            Assert.Equal((UInt64)0x416B4150508661EE, actual);
        }
Exemple #20
0
        public void ShortAsciiString()
        {
            var actual = Crc64.Compute(SimpleBytes);

            Assert.Equal((UInt64)0x7E210EB1B03E5A1D, actual);
        }