OSDN Git Service

add japanese site html
[sevenzip/7-Zip.git] / 7z457 / CPP / 7zip / Archive / Lzh / LzhCRC.cpp
1 // LzhCRC.cpp
2
3 #include "StdAfx.h"
4
5 #include "LzhCRC.h"
6
7 namespace NArchive {
8 namespace NLzh {
9
10 static const UInt16 kCRCPoly = 0xA001;
11
12 UInt16 CCRC::Table[256];
13
14 void CCRC::InitTable()
15 {
16   for (UInt32 i = 0; i < 256; i++)
17   {
18     UInt32 r = i;
19     for (int j = 0; j < 8; j++)
20       if (r & 1) 
21         r = (r >> 1) ^ kCRCPoly;
22       else     
23         r >>= 1;
24     CCRC::Table[i] = (UInt16)r;
25   }
26 }
27
28 class CCRCTableInit
29 {
30 public:
31   CCRCTableInit() { CCRC::InitTable(); }
32 } g_CRCTableInit;
33
34 void CCRC::Update(const void *data, size_t size)
35 {
36   UInt16 v = _value;
37   const Byte *p = (const Byte *)data;
38   for (; size > 0; size--, p++)
39     v = (UInt16)(Table[((Byte)(v)) ^ *p] ^ (v >> 8));
40   _value = v;
41 }
42
43 }}