
Ŀ
                                                                    
                        
                                    
                           
                                          
Ĵ
                                  5                           
ٰ



              . ᪨ ஫ 㬬
                               by Sassa

                                

       ந   ꥪ⮢  ஫
㬬.  ਬ,    ⨯  W32.CTX,  I-Worm.Hybris,     㣨,
㦨  㭪樨  API,  室   ஫쭮 㬬   㦭.
 ⠪ ᯮ ஫ 㬬     㣨  楫.  㦭
,       祭 ࠬ ᮢ  
 㬬 ᮤঠ 訡.  ᯮ짮  ஬  ⠡  
஫  㬬   ⮢ ⬮ ⠪  
,       ਠ.    㤥    㯮
஥筨 ᮢ ଠ⨪  ⮬⨧樨,   ⭮ 蠥
  横᪨ ஫ 㬬.

     ⠭  ப  ⥫   ॡ ᯥ樠쭮-
⥬᪨           ஡    ⬮.
ਢ 뫪 ᮤঠ ⥪,     ॡ  
  ⥮ਨ 㯯  ⥮ਨ ᥫ.

       ਫ  ਬ ணࠬ  Java   ⠡
CRC-32,  騩 ⠪   4  ,  묨  㦭
᪨஢  ⮪  ᮮ饭,  ⮡  ஫쭠  㬬 
ᮮ饭 ⠢  ⠪  ,      室  ᮮ饭.  㣠
ணࠬ    ॢ஢  㭪  CRC-32    ASCII
ப,   ஫ 㬬.

1. 騥 ନ  ਬ 孮

    ४ ࠭  㦤,   横᪨   ஫
㬬 -   ।  ஫ 㬬,   ,  
⥬  뢠 "ᥩ ⠥ CRC" (CRC, cyclic redundancy
checksum)  -        ࠧ  ⠪ 㬬,    
뢠  -  㬬.  ⮬  ᥩ  ᠬ  ६   ਭ
ନ᪨ .

    * 㬬  -   १ ᫮ ᫥⥫쭮 ᥫ (⮢,
  ..).   ⮬   易⥫쭮  ᯮ      
  ᮢ  䬥᪠    ᫮ - ,  ਬ,
ᯮ짮  ᫮      2  (⭠  ⠪  
ᥢ XOR).

    * ஫쭠 㬬 -  㬬,   ᯮ  ஫
楫⭮ .   ,  ।⠢        楯窨
ᥫ,  ᪫뢠  ᫠.  쭥襬  ஢ ந諨 
ᯮ⠭     -   ᤥ ⥬ ࠢ
஫쭮 㬬  㬬, ⠭   ⮬   :
᫨ 㬬  ᮢ, , ந諨 .

    ஫ 㬬 ᯮ  ⥫ ଠ樨 ( 
᪨  ᪨,        ..),    ⮪ ।
,     娢 䠩.

    ⥩襩 ⠪ 㬬   ⭮ - .   㬬
   ᥣ 1    㬬   2  ⮢ 
.  ᫨  १ ࠭  ।    -  
㤥 ᪠,   䠪   㦥,  ᪮  ⭮
㤥 㣮.

    㣠   ਬ  ஫  㬬  -  ਯ⮣,   
⭮ - ᮧ ஭ ᥩ.  ஭  ᠬ 
ᥡ  ਯ⮣᪨ 饭 ஫쭮 㬬 (ਬ,
஢ ᥪ 箬 ᠢ襣).  ᫨ ᮮ饭 뫮
()।७ ᪠,   ஫쭠 㬬  ᮢ    
    ⮫쪮  ᪠ ଠ樨,     ⭮
ᠢ襣  ᮤন ᮮ饭:  ᫥  䨪樨  ஭
㬥  ࠧ ᪠,     㣮 㬥 
⮬   ⢨⥫쭠.    (ਤ᪨    ,    易    
ᯮ짮 ஭ ᥩ - ⥬ ᮢ襭 ⮣쭠.)

     ਬ  ஫  㬬  - ⥪ 訡  .
⨬,   ᠬ 㬬  ⮬  ࠭    ।    
묨,   ⮬ থ ᪠   ᠬ .  ⨬
⠪,   ᠬ      ,    ᪮쪮  訡,
祬, 訡   ⠪,  ஫쭠 㬬   
-   訡,    뢠  ࠭祭    ⢮
訡,   䨪஢ ⠪ ஫쭮 㬬.

     ࠢ,   祬      ᮮ饭,   ⥬    ⥫쭠
⭮ ⮣,   訡    ஫쭮 㬬  (
ࠢ  ⭮  訡  ᮮ饭 - ஫
㬬 ⥫쭮  ᠬ ᮮ饭),       ⭮
⮣,     訡  ᮮ饭.

     䠪    ࠭祭   ⮢୮ ⥪樨 訡.
 ਯ⮣᪨ ஫ 㬬,  த SHA-1  MD5    襭
⮣  ᢮⢠:    ⫨筠     ⭮ ⮣,  
ᮢ㯭 訡   ஫쭮 㬬;  ࠢ,  ⭮
⮣  ᮡ  ⮫쪮  ,      ७ॣ,   ਬ
㭪   楫.

    *   -  ᯥ樠 ࠧ  ⠭  ஫
㬬,  騥  ⮫쪮 ᭨ 稥 訡,   _ࠢ_
.   ᫨  ।  ᮮ饭  ᮤন  訡      ,
ᮮ饭      㦭  뫠  :      ࠢ  
祭.   ,  㦥 뫮 祭, 訡  
᪮쪮    訡      ।  ஫쭮
㬬, ⮬  100% ࠭⨨ ⮣,  ࠢ ᮮ饭 - 
⢨⥫쭮 ,  뫮 ।.

        ⭮⥫쭮   ᫮   .   ஬  ⮣,
ᮥ     -   㤮    ॡ
  ࠡ⪨  ( ࠢ ᮮ饭  ⮣, 
⠭        ஫쭮  㬬),      ६      
㭨樮  孮   , ࠡ뢠騥
⮪ .     ⨬  稭    ᯮ  ᪨
஫    㬬,   ,   ஬   ⮣,   ⭮⥫쭮   
⠡㫨஢  ᪮७ ணࠬ    ஫  㬬.
  ⠡筠  ଠ  ⠪  㭪権  ப ⭠ ।
ࠪ⨪ ࠧࠡ⪨ ணࠬ,    ⠪ ॠ樨  
 , ࠧ㢠  ࠧ.

2.  ࠢ쭮 뢠 ஫ 㬬

2.1  

     ,      ४樨  筮  訡 筮
࠭   log(n+1) ஫  (log -    ᭮
2,  n  -    ᮮ饭).    ⠪ ।   
஫ .  ⮣ ⬠  ਬ   .
ਬ ࠢ 訡 ਢ  ࠧ 3.

    ।, 㦭  ।  n  .  襬  ᫠  1  n.  
  ஬, 騬 ⥯ ᫠ 2, ᯮ ஫
,        -    ⠢ .  祭   -
  ⮢ ᮮ饭  ,        ⮬
 ,     樨 ஫쭮 .

    , C0,    ஫ ,  ᯮ  樨 1 (2^0,
  ᠬ 襬   樨)   祭  -  
    ᮮ饭 ( ,    樨  ᠬ
訩  ⠭  1).

    ⢥⢥, C1,  ன ,  ᯮ  樨  2  (2^1,
    ஬    樨)   祭 -  
 ᮮ饭,      ⠭ ன .

    ⨩ ஫  ᯮ  樨 4,     樨  3,
⠫ ,  .  ⠪ .

ਬ:

     ࢮ    ⮩  ⠡ - 筠   樨 
ᮮ饭.    - ⪨,   ᮮ饭 ᯮ
    ᮮ⢥饣  ஫쭮  .      -
ᯮ  ᮤন  ᮮ饭.  ⢥    -  १
᫮   ᮮ饭     ஫    -  ᮡ⢥,    
।.

     | C3 C2 C1 C0 | K | M        .
0001 |  .  .  .  * | . | 1 = 1+0+0:᪫뢠 ,
0010 |  .  .  *  . | . | 0 = 1+1+0:祭 窮
0011 |  .  .  *  * | 1 | 1        : ᮮ⢥饩
0100 |  .  *  .  . | . | 1 = 0+1+0:
0101 |  .  *  .  * | 0 | 0        '
0110 |  .  *  *  . | 1 | 1
0111 |  .  *  *  * | 0 | 0
1000 |  *  .  .  . | . |
1001 |  * ......  ⠪ 

⠪ (訥  ࠢ)
饭: 1010 = ..1.010 = 5
:       101  = 10.1... = 5
।:         1011010 = 0x2d

    ⢥, ஫    ஫  -㣠:    
,    室 ஫ ,   1 ⠭ ⮫쪮 
.  , ᫨ 訡 ந室  । ஫쭮 , 
 㤥 㦨.

    ᫨ ந室  訡  ।  ,  ஫ 
   㣮  祭.          ᫨
  訡筮    ⠪ 砥.  ᠭ ᯮᮡ ਢ 
ࠧ 3.

2.2 ᪨ ஫ 㬬

       横᪨   ஫   㬬   ᮮ饭   ᫮
।⠢         ,   樥   ண   -   
ᮮ⢥騥    ᮮ饭.    ஫쭮  㬬  
⮪      GF(2)        -ᮮ饭    ᯥ樠쭮
࠭ , 뢠 -஬.  ⮩  
 㤥  ᯮᮡ  -.

饭 K: 1010
 ᮮ饭: 1*x^3 + 0*x^2 + 1*x^1 + 0*x^0 = x^3+x
⥯ ⮣ : 3.

    GF(2) -  Galois Field,    (  砥 -   2).
 ⠪  ᥫ,    ஬  १  䬥᪨  権
ࠢ   2; ਬ,  GF(10): 3*7=21=1 mod 10 (⪨
  1  21  10 ࠢ,  ⮬     ᫠  ࠢ  
 10).

     ⠪    䬥᪨  樨  । ⠪ ࠧ,
⮡ ࠭  ࠨ᪨ . ਬ,   
GF (p) । ⠪ ࠧ:  1/a=b <=> a*b=1 mod p.   ,  b -
 ᫮,  ⭮ a, ᫨ ந   a ࠢ 1   p.
⨬,   ᥫ,   , ᪮筮 :   n*p+b
  n.

    , 1/3=7 mod 10 (᪮  3*7=1  mod  10).  ஢ਬ:  6/3=2  -
    ⠪?    6/3  =  6*7  =  42  = 2 mod 10 (42  2 
 ⪨    10).

     ⠪  ਭ樯 । 樨  GF(2).   ⭮,
  樨 ᫮  ⠭.

    ⠭ -   ᫮ ᫠  ⨢ : b-a=b
+ (-a). ,  -a=c <=> a+c=0 mod p.  ᥫ 祭 : 
 n*p+c.

    ,  GF(2) ,   -1=1, ᪮ 1+1=2=0 mod 2 (⪨ 
 0  2  2 ࠢ),     XOR.

      ᬮ  ந        .  
  ⮫쪮  ⮪    ,  ⮬    㤥  
  ⭮.

     ஫쭮 㬬 ந ᫥騬  ࠧ. 饭
।⠢    S(x),  㬭  x^M,    ⮪ 
      -   G(x),      M   -       ⥯
.

    ,   ᮮ饭 1010.  ᮮ⢥  S(x)=x^3
+x.   - G(x)=x^3+x+1,    ᮮ⢥  筮
 1011,  M=3 (⥯   ⢮  ஫쭮 㬬:
 CRC-3).   横᪮ ஫쭮 㬬 ந  ⠪:

    S(x)*x^M - 뢠   ᮮ饭 M : 1010*1000=1010000.

    S(x)*x^M = Q(x)*G(x) + C(x) -  祭    G(x),  
१  祣 砥 ⭮ Q(x)  ⮪   C(x) (
।⠢ ࠧ ᮮ饭  㬬 ,  饣 楫
  G(x),    ,   㦥    G (x)).  C(x)  
᪮ ஫쭠 㬬.       ⮫.    -
ਢ筮   童,  ࠢ - ୠ ଠ  ⮣ 
.

   S(x)*x^M       G(x)             K shl M    G
  ------------------------------------------------
  x^6+x^4       | x^3+x+1         1010000   | 1011
 -              `--------        -          `------
  x^6+x^4+x^3   Q(x)=x^3+1        1011        101
  ---                             ----
    -x^3=x^3 (-1=1 mod 2)            1000
    -                               -
     x^3+x+1                         1011
     ---                             ---
       -x-1=x+1=C(x)                  011=CRC-3

     ,     ஫쭮  㬬    ந
⥬ 横᪮ ᤢ ⮢ ᮮ饭, ᫥⥫쭮  
ᮮ饭   ॣ,    ⮫쪮 ᠬ 訩     ॣ
c⠭  ࠢ 1,  㦭    (⠩:  ⭮ ᫮ 
 )  ࠧ  -.  室  
     ,    㤥 뤢  ॣ ᫥
 .

    2.2.2 ⢠.

    ᪨ ஫ 㬬  ᫥騬 ᢮⢠:
    1.   ࠢ    訡    ᮮ饭,  
, 祬 2^c (c - ⥯ )
    2.   㦨  誨  訡    c ( ,
᫥⥫쭮  ,  稭騥    訡      稢騥
訡)
    3. ᯥ樠    ⠪  ⥪஢  
⭮ ⢮ 訡
    4. CRC(a+CRC(a))=0:  ᫨  ᮮ饭      ஫
㬬,  ஫쭠 㬬  १饣 ⮪  ࠢ 


    2.2.3 ਬ  ⭮  CRC-16  ⮭ ॠ樨

᫮ 䨪 ⮣   뢠 CRC-32.

; () Sassa
  mov  cx, chunksizeToCRC ; ⢮ 
  ;      ਯ 㫥 ᫮:
  ; ࠢ쭮 CRC 㤥 ᮮ⢥⢮ s*x^M -  
  ; ᮮ饭 㦭 ਯ M 㫥.
  ;   祭  ண 㭨쭮
  ; ᫠  ⮣  .
  mov  si, offset chunk

  xor  bx, bx  ;  ⠭  CRC ॡ
               ; 稭  㫥 祭(. )
               ;  ⠪ 砥   
               ; mov  bx, CRC_INIT
  ; 筮,  CX==0  㦭 稭 横, 
  ;   CX==2 -    㫥 ᮮ饭
  ; ਯᠭ 16  = 2  (㫥)
read_next_word:
  loadsb
  ; xor bl, al   ; ᠢ ⠪ ப, 㦭 
                 ; RCR BX,1  SHR BX,1,  
                 ;  㫥    ᮮ饭.
  stc               ;   ᫥饣 RCR  AL
                    ;  1, ⠪ , AL!=0, 
                    ;  뤢   ,
                    ;  㫥  (塞
                    ;  ⥫쭮 稪 横)

shift_next_bit:
  rcr  al, 1        ; 뤢     訬
                    ;  CF: 1  ࢮ 樨,
                    ;        0   ⠫ 
  jz   _loop_again  ; AL==0 => 뤢 ᫥ 
                    ; (. ਨ )

  rcr  bx, 1
  jnc  shift_next_bit
  ; CY 砥,  1  ᠬ 襬  
  ;      -:
  ; ⠭  GF(2) ࠢ xor

  xor  bx, 0a001h   ; CRC-16, 訥 16  
                    ; ᠭ  ⭮ 浪 -
                    ;   ଠ 
                    ; ⮣ .

  ; CF==0 ᫥ ᫥ XOR: RCR AL,1   AL 0
  jmp  shift_next_bit
_loop_again:
  loop  read_next_word

    頥   ࠢ  横᪨  ᤢ  ஫쭮
㬬    ॣ    묨.  ᫨ ᤢ ஫쭮 㬬  
⭮ ࠢ,  ⮦  㭨쭮 ᫮, ࠪ୮ 
    室  ,          㤥  横᪠
஫쭠  㬬,  ⠭    -,      㣨
ணࠬ  ᬮ    .

    ᫨ ᤢ  ॣ        ⭮ ࠢ,  
 ⮪  㤥 ६蠭.

    頥 ⠪   ,    CRC-16  ᯮ  
_16 _- ⥯! 17-      16-ࠧ來 ॣ, 
   ᥣ 㤥 㫥.   ࠧ,  CRC-16  ᥣ  16
,     -  16-  ⥯;  筮    㣨
⥯!

     ⨬஢ ணࠬ  ஫쭮  㬬,  ᫨
᪮஢  ப  XOR  BL,AL    RCR BX,1  SHR BX,1:
⮣  㦭    ᮮ饭  㫥     CRC16
(믮騥 ஫ 㬭  x^M).      樨
ᮤন  BX ஫ 㬬    ,    뫨  ࠡ⠭
(   ᫥   ࠡ⠭      ⢨⥫쭮  ᫥  
ᮮ饭).   ⮡          ᮮ饭,  㦭
९  ᠬ  訥    ஫쭮 㬬 ⠬  
(XOR BL,AL),  த   .

⥬᪨ ⠪  룫廊  ⠪:

S(x)=A(x)*x^N+B(x) - ᮮ饭 ।⠢塞   㬬 
ᮮ饭,  N - ⥯  B(x) (N<M, M - ⥯  G
(x)). :

S(x)*x^M=(A(x)*x^N+B(x))*x^M
=(AQ(x)*G(x)+AR(x)+B(x)*x^(M-N))*x^N,

     AR(x) - ⮪   A(x)*x^M  G(x),  ஫쭠 㬬
ᮮ饭 A, B(x)*x^(M-N) - ᤢ ᮮ饭 B(x)  ⠪, ⮡ ᠬ
 ⥯ B(x) 뫠 M,  㬭  x^N - 뢠   N
㫥.   ,  AR(x)+B(x)*x^(M-N) -     CRC(A)  XOR  (B  SHL
(M-N)).  (  ,    ணࠬ  ᤢ   ⭮
ࠢ, ⮬ ᤢ   㦥).

     ணࠬ (ਬ,  PKZIP) 稭   ஫쭮
㬬      0,     -1,   ⮬   १.  室
樨 ந  㭨樮 ன⢠.  ⠪ 権
-  稭  㬬   ,  ⮡  뫮 㦨 
砫 ⮢  ᮮ饭,  稭  㫥  ⮢.  ᫨  
稭    㫥  祭,    ।  㫥    祭
஫쭮 㬬  㤥 , ⠪ ,  㧭,  
㫥    ᪮쪮.  ஢ १  ⮩ 
 砫쭮  [CORNELL].

    (⮨ ,    ⠪  楯窨  ,  CRC  
㤥   ࠢ    -    楯窨  ,    묨  ਯᠭ  
஫쭠 㬬.  ᫥ ⠪ 楯窨     ᪮쪮  㣮
㫥,        ࠦ    ஫쭮  㬬 - CRC 㤥
⠢ "ࠢ쭮",   ᫨      ᪮쪮  㫥
.)

2.2.4   ⠡ CRC.

     ⮩    ᬠਢ  横᪨ ஫ 㬬
 ᯮ짮 ணࠬ.   ⮬ 砥  ᥣ 㤮 짮
  ।⠢    (   ᥣ ⠪ ᯮᮡ ᪮쪮
 ⭮ ࠡ⪨ ).  ⮬   設⢥  砥
ணࠬ     ⠡栬    CRC,      
᭨ 祭 横᪮ ஫쭮 㬬,  ࠡ뢠 ᮮ饭
⭮.

     ஥    横᪮  ஫쭮  㬬   ᨬ 
     ஫쭮  㬬    䨪஢
 :   㬬 ᯮ     ᫮. ⮬
᫨ 뤢  ஫쭮 㬬 8 ,      1,    㬬  ᥣ
  䨪஢  .

    ६ 訥   ஫쭮 㬬  
ᨬ   ⮢ .  ᫥⥫쭮  ਬ
-       ⮢        祭,
᪮     믮    XOR.    ᢮⢠
横᪨  㬬   ந  ⠡  256 ப,  
 ப ன ᠭ XOR-᪠,     
 ஫쭠 㬬  横᪮ ᤢ 㬬  8 .

     ஥  ⠪  ⠡  室    CRC  
  (0..255),  ⮣ ⤥쭮.  祭  㦭
  ⠡.

짮 ⮩ ⠡楩 㦭 ⠪:

    -  8    ஫쭮 㬬
    - ᤢ ஫ 㬬  8 
    - ᪮஢  ᫥騩       訥 8  ஫쭮
㬬
    - ᫮      2 ஫ 㬬  ᪮ XOR,   
ப ⠡, ᮮ⢥饩   ஫쭮 㬬

 :

    data - ᫥騩  
    crc[] - ⠡
    crc(int) - 㭪 ⭮  CRC
    b - ⥪饥 祭 CRC
    CRC_BITS - ⢮   CRC

    樠 ⠡:
    for (i=0; i<0x100; i++) crc[i]=crc(i);

    ᯮ짮 ⠡   (᪮         -  
,    㦭  M ﬨ):

    c=b>>(CRC_BITS-8);
    b=b<<8 + data;
    b=b ^ crc[c];

        ப:
b = (data + b<<8) ^ crc[b>>(CRC_BITS-8)];

    ᯮ짮 ⠡    -㣮 (⨬ ,  
ᠭ  2.2.3):

    c=data ^ (b>>(CRC_BITS-8));
    b=b<<8;
    b=b ^ crc[c];

     ப ⠪  룫廊 ⠪:

    b=(b<<8) ^ crc[data ^ (b>>(CRC_BITS-8))];


    3.  ࠢ 訡

    3.1   

    ⮡ ࠢ  訡,  室  ᨭ஬,    ࠢ
ﭨ   :  ᫮   2 祭  
, ⠭  ᪠ ᮮ饭.

    ﭨ    㪠뢠    訡 (
஥).  ᫨ ࠢ 訡  뫮,  ﭨ   
  ࠢ  .  ᫨ 뫠  訡,  ﭨ  
 㪠     訡.  ࠢ  砥  
஢ ஢ .

ਬ:

饭: ..1.010 = 1010 = 5
:       10.1... = 101  = 5  (1)
।:  1011010        = 0x2d
訡:    .....1. (᪠  6)
祭:  1011000        = 0x0d
:       11.0... = 110  = 3  (2)
஬ (1) xor (2): 101 xor 110 = 011 = 6.

    ࠢ塞 訡  6- ,     (
  ).

3.2  ᪨ ஫ 㬬

    த㥬 ஢ CRC ᮮ饭 K=1010,   ஬  ᪠
⨩ : E=0010, 諮 ᮮ饭 K+E.

S(x)+E(x)=x^3+x+x=x^3

 S(x)+E(x)*x^M     G(x)           K+E shl M    G
  x^6           | x^3+x+1         1000000   | 1011
 -              `--------        -          `------
  x^6+x^4+x^3   Q(x)=x^3+x+1      1011        1011
  ---                             ----
    -x^4-x^3=x^4+x^3 (-1=1 mod 2)   1100
    -                              -
     x^4+x^2+x                      1011
     ---                            ---
       x^3-x^2-x=x^3+x^2+x           1110
      -                             -
       x^3+x+1                       1011
       ---                           ---
          x^2-1=x^2+1=C(x)            101=CRC-3


    101!=011,    ,  ⭠  ஫쭠  㬬    ᮢ  
।     ᮮ饭,    ,    ।  ந諮
᪠ .

    ࠢ 訡    横᪨ ஫ 㬬  ⠪ ,
     :    ࠢ  訡  㦭  짮
⠡栬.  ⨬,     㬬 (᪠, 32-)  ⠡
  ஬묨,   ਬ - ࠪ筮.

    3.3  ᪠ ᮮ饭 (      訡  
ᮮ饭)

।⠢ ᮮ饭   
S(x)=F(x)*x^(M+n-1)+A(x)*x^(M-1)+D(x)
 S(x)*x^M=Q(x)*G(x)+C(x)

     F(x)  -      ,  A(x)  -  楫 
⥯ n,  D(x) -  ⥯ (M-1),     C(x),  C(x)  -
⮪         -  G(x),  ஫쭠  㬬
ᮮ饭 S (x). Q(x) -  ⭮ (  㥬).

     ஫쭠 㬬   ᮮ饭  㤥    ⠪
ࠧ:

(F(x)*x^(M+n-1)+A(x))*x^M=R(x)*G(x)+C_0(x),

     ஫    㬬   ᥣ   ᮮ饭         
⭮ 㫥:

S(x)*x^M=(R(x)*G(x)+C_0(x)+D(x))*x^M=Q(x)*G(x)+C(x)

    ᫨  楫    ᮮ饭  -    
A(x)  B(x) ⮩  ⥯ -  ⮡  ⮬ ஫쭠 㬬 饣
ᮮ饭 ⠫ , 㦭 ᫨ 祭  P (x):

S_1(x)= F(x)*x^(M+n)+B(x)*x^M+P(x)


 (F(x)*x^(M+n)+B(x))*x^M=R_1(x)*G(x)+C_1(x),

    ⮣ ⮡  ஫쭠  㬬  ᥣ  ᮮ饭  S_1(x) 뫠 ⮦
C(x),    ᮮ饭 S(x):

S(x)*x^M=(R(x)*G(x)+C_0(x)+D(x))*x^M=Q(x)*G(x)+C(x)
=S_1(x)*x^M=(R_1(x)*G(x)+C_1(x)+P(x))*x^M

     P(x)  㤮⢮ ⠪ ᫮:


C_1(x)+P(x)=C_0(x)+D(x).

      ,  P(x)=C_0(x)-C_1(x)+D(x)=C_0(x)+C_1(x)+D(x)
᪮   GF(2) 樨 ᫮  ⠭ ࠢ.

    ᫨     ⮢  ,      ஥
᫮  ᮮ饭,  㦭    -  ᫥騥  M
.  祬,   砥  ⮬,  㦭 ᫮  
XOR  騥      ஫쭮  㬬      
ᮮ饭      ஫쭮  㬬  ᮮ⢥饩  
ᮮ饭:

S=FAD
S1=FB(D xor CRC(FA) xor CRC(FB))
CRC(S)=CRC(S1),

     F -   ᮮ饭,  A  -  塞  ᫮,  B  -
楫 ࠧ  ᫮ A, D - ࠥ ᫮.

    㦭 ,      楫   ࠧ        
࠭祭  ᮮ饭,    室    ᮮ饭
  M ,    ந쭮 ( D).

    ᬮਬ  砩,  ᫥ A  M ,   
ந쭮,    ⠪   A:  S=FDA.     
ᮮ饭 S1=FPB.  ᫮, ஬  㤮⢮ 
P, ⮡ ஫ 㬬  ᮮ饭 뫨 .

     C0=CRC(FD), C1=CRC(FP).
     CRC(S)=CRC(FDA)=CRC(C0+A)=CRC(FPB)=CRC(C1+B).

    ⠪,  ᫮ C0+A=C1+B ,   C1=C0+A+B.   P
ந ᯮᮡ, ᠭ .

    (F*x^M+P)*x^M=R*G+C1=F*x^(2*M)+P*x^M=T*G+CF+P*x^M,  CF=CRC(FO), 
O - 楯窠  M 㫥 .

     CT=C1+CF.

    P*x^M+CT=R*G -    楫  G(x).

     p_i  - 樥  ᮮ⢥ ⥯ x  
P  (x),    c_i,  r_i    g_i  -      CT(x),  R(x)      G(x)
ᮮ⢥⢥.

     室  ⠪ ⥬ ࠢ (0<=i<=M):

    .--
c_i= >  {r_j*g_(i-j)}
    `--
   0<=j<=i

    .--
p_i= >  {r_j*g_(M-j)}
    `--
   0<=j<=i

    .--
  >  - 㬬஢ 鸞 ᥫ,  ஬  j
    `--
   0<=j<=i

    ஡ 祭  0  i ⥫쭮,  r_j -  j-  樥
 R(x),  g_(i-j) - i-j- 樥  G(x).

    뢠,   ᫮     2,  蠥  ⥬.
ࢠ  ࠢ (c_i=...)    祭  r_j,    
 ࠢ (p_i=...)   樥  P(x).

    ⮢ ।⠢  ⮢ 룫廊        
ॡ  襭 ⥬ ࠢ.   ⮣ 室  
 CT  ࠧ    ⠬    P,    ந  樨,
   ⮫  G.  :

   0...  0   0 c_M...c_2 c_1 c_0 = P(x)*x^M+CT(x)
+  :     :   :   :     :   :   :
   :     :   1 g_M...g_2 g_1 g_0 = r_0*G(x)
+  :     :   :   :     :   :   :
   :     1 g_M.......g_1 g_0   : = r_1*x*G(x)
+  :     :   :   :     :   :   :
   : 1 g_M ..........g_0   :   : = r_2*(x^2)*G(x)
+  :     :   :   :     :   :   :
 ..:.....:...:   :     :   :   :
+  :     :   :   :     :   :   :
   1 g_M...g_1 g_0     :   :   : = r_(M-1)*(x^M)*G(x)
 -------------------------------
 p_M...p_1 p_0   0...  0   0   0

     ,  室 ᤢ G(x)   ᪫뢠   2 
CT (x) ⠪, ⮡ ᠬ 訩 騩  G(x)  ᠬ 訩
騩  CT(x).   㫥   CT(x),  祭   P
(x)*x^M.

         ।⠢      ஫쭮 㬬
⭮ 楯窨    "-", 饣  
室 -,  ᠭ  ⭮ 浪. (
।⠢      ⮩  稭,    ᫮    ⠭
      GF(2).    ⠪  ,    ਫ
ணࠬ   ⮩ ⨬樨, ⮡  뫮,  ந室
 饭 १ 㭪樨  室 楯  .)

    ⠪,   ⠪  P(x),    ᮢ㯭 
楫    B(x)  A(x),     ஫ 㬬,
  室 ᮮ饭.

     ⠪  ᯮᮡ   P(x) ⠪ ࠧ,
⮡  뫮 䨪஢ 祭    ⮢  .  
⠪  砥  ᪮       ࠧᠭ  ப,  祬
 M      ,      襭      :  
ॡ   ࠧ  , 祭  䨪஢.

    4. ᯮ짮 ஫ 㬬  㣨 楫

    ஫ 㬬   ᥩ  ᯮ    ⮫쪮    ஢ન
楫⭮ ᮮ饭.  쭮  ஫  㬬  ᯮ
 䨪  楯祪 .

     楯窨        -           ᮢ㯭   ଠ樨,
⥭饩 ⭮ 짮⥫,   㫠     
  ,    ᨣ  ,     䨪 ணࠬ,
⠭   .

     ஡ ᯮ짮 ஫  㬬    ⥭䨪樨
㦤    ਫ ,   ⨪ ᯮ짮 ஫ 㬬
  䨪樨  ணࠬ  ᠬ  -    ਫ  .    
⠭   ஡,  易  ᯮ짮 ஫ 㬬
  㭪権.

              ஫   㬬   ᯮ   
஢      砩 楯祪 .  ,  ஫ 
ࠢ ⮨   ᨬ  ASCII  ⠡.      
  ⥬  뢠      ⥪⮢ ப.   ᮢ
   権  । ଠ.

    ஫ 㬬     ᯮ   騥
㭪樨,    ⮬    ᥣ  襥 ᥨ १⮢ 
 ⤥쭮  ।.  ਬ,  CRC-32 ᫮  `begin'
ࠢ  CRC-32  楯窨 ᨬ `?,J{'  ࠢ 0x7a859515 (஫
㬬 ⠭  ,  ᯮ㥬    娢  ZIP).  (
१    ,  ⨢  ਫ    ணࠬ:
"revCRC begin .....")

    ᫥ ⢠  ஢          CRC-64
[CRC64]  ⠪  મ  ⪨ ࠭ 㭪樨.  
ࠧ,  । ⥬,   ᯮ짮 ஫ 㬬  騥
㭪樨,  室  ᫥ ᥨ १⮢ ,  ,
  室 㭪.

ਫ . ⠭ 

(祭   [BERKLEY, ATT])

CRC-8: x^8+x^2+x+1
         100000111

CRC-10: x^10+x^9+x^5+x^4+x+1
                 11000110011

CRC-12: x^12+x^11+x^3+x^2+x+1
                 110000001111

CRC-16 (bisynch): x^16+x^15+x^2+1
                11000000000000101

CRC-16 (CCITT, XMODEM): x^16+x^12+x^5+1
                      10001000000100001

    CCITT ᯮ     ᫥⥫쭮    ,  
XMODEM - .

CRC-24: x^24+x^23+x^18+x^14+x^11+x^10+x^7+x^6+x^5+x^4+x^3+x+1
                            1100001000100110011111011

CRC-32 (Ethernet):
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4
+x^2+x+1
                    100000100110000010001110110110111

     ,   ॠ 祭,  ᯮ 
᪨஢  ஫쭮  㬬,   ᮤঠ ᠬ 襣 ,  
   ᠭ  ⭮  ᫥⥫쭮  (  砥
           㣮   ᤢ ॣ
 ந室    ஭;  ⠪  CRC-16      
0xa001  -  訥  16      ᠭ   ⭮ 浪).
,  ᮡ  ࠢ 室   ᮢ⨬.  
 "㭨쭮 䨪"   楫   ⠪ .

ਫ . ᯮ짮 ஫ 㬬  ⥭䨪樨

    ⥭䨪 -        樠樨  ⭨  饭  
㭨  䨪஬.    䨪஬    㯠,
ਬ,  짮⥫  ⥬ (login).

        ⥭䨪樨   ⭨       -
ࠧ,    ᮮ⢥   㭨 䨪.  
⥩襬  砥 ⭨  ।  ᥪ, 
  ஢饬;  ᪠,   ஫ (஢騩 - 樮
⥬    ᠩ -).  ⮡ ᥪ  ⠫ 㯥  ⠯
।  ⭨  ஢饬,    ।  ⮬ ,
       뢠  ஫  㬬.  (  ⮬  ஫
  砩묨   묨            replay-⠪.)
஢騩  ᥣ    㤮⮢,    ⭨  ᯮ짮
ࠢ  ᥪ,  ᫨  祭  ஫쭠  㬬  ᮢ  
஫쭮  㬬  ᥪ  (  ᥣ   ᤥ,   ᥪ
⥭  ).

     ᨫ ᯮᮡ ⥭䨪樨 - ᯮ짮  ਯ⮣䨨 
  箬.      㤠⢠    ய  쥧
뢠   饭樮    প  ⠪
⥭䨪樨 ࠦ,    㦥   ࠧ ᯮ짮
஭   㬥  ਤ᪨ .

     ⠪  ⥭䨪樨  ⭨  ᮧ  ஭   
㬥    砩  (ᯮ㥬
 楫   replay-⠪)   ᯮ짮  筮  ᥪ⭮
.    ஢ન ⮢୮  ᯮ  ,
㯭 ᥬ  ᮮ⢥騩 ᥪ⭮  ⭨.

     㦥  뫮   ᪠   ࠭,   ஭      
஢ ஫쭮 㬬 ᮮ饭.   ஢ન 楫⭮ 
⥭筮 ᮮ饭 ( ,  ஢ન ⮣,    ᮮ饭  뫮
ᠭ    ⥬,      㬠)  筮   
஫ 㬬 ᮮ饭   ࠢ    㬬,  ஢  
஭    ⮣ .  ᫨  㬬 ᮢ,
 ᮮ饭  ௥   ⥭筮.

      㤥 ᪠,   ⨢ ଠ  믮
  ᨩ  頥  ᨬ묨  砬    ਯ⮣  
  箬    ᯮ,  ᬮ      饥   
ॡ  ⥭筮   ᭮:  ᨬ묨 砬 
ࠢ,   । 㣮 -       २⢮  ।
⥬ ᨬ筮 ஢  ᮪ ᫮.

    (,        ᮧ  㬥⮢    ⥫쭮  ࠭
ᯮ -⠪ ⥬ ᨬ筮 ஢.)

---------------------------------------------------------------------
ਫ .  ஫ 㬬  㭪権.

     ஡    롮஬  襩  -㭪樨  (.   4),
    ᮧ⥫  (㬠 - 室 㦭
㭪樨,    -),  㣨 ꥪ⨢ 稭, 
 ᯮ짮 ஫ 㬬   㤠 襭.

    ।,  ࠭ ஫ 㬬 30 㭪権,   
 .   ᯮ ⠡ CRC-16   ஫
㬬  䠩.   ࠧ ,  ᯮ㥬  ࠭ 
,   ᮯ殮     ᪮      㭪権,  ࠢ
30*2+2*256=572 .  ⮣ 墠⨫   ࠭  30    㭪権
।  19.06 ᨬ.       ப
  .    18-ᨬ .  ⮣   祬
筮     設⢠ 㭪権:  ᫨誮  
㭪権    ᬮ  ᯮ  ࠬ  (ANSI  C  ࠧ砥
䨪   32 ᨬ).

     ࠧ,  ᯮ짮  ᠬ ஫ 㬬  ᪠
⥫ ணࠬ  ⨬ 襭.


뫪  祡 ਠ   

[ATT] http://home.att.net/~cbwatson/CRC_info.doc - [9 ] 
᭥, ⠭ , ਬ ணࠬ  ⠡ ࠢ CRC.

[BERKLEY] http://www.cs.berkeley.edu/~kfall/EE122/lec06/lec06-outline.pdf -
[9 ] ᫠  樨  ஫ 㬬

[CORNELL] http://www.library.cornell.edu/nr/bookcpdf/c20-3.pdf -
[9 ]    Less-Numerical Algorithms.

[CRC64] http://www.cs.ucl.ac.uk/staff/D.Jones/crcnote.pdf -
[9 ] 砭   ஢ ASCII ப   CRC-64

[MAN1] http://www.cs.man.ac.uk/Study_subweb/Ugrad/coursenotes/CS2272/skb/ -
[9 ] 樨  ஫ 㬬

[MAN2] http://www.cs.man.ac.uk/Study_subweb/Ugrad/coursenotes/CS2272/skb/SKB_Lecture_11.pdf -
[9 ]   CRC

----------------------------------------------------------------
ਫ 

/*
* This program gets two strings on input: the initial ASCII string, and
* the target ASCII string. The target ASCII string may contain wildcards,
* which means that those characters will be calculated. The program will
* output the resulting ASCII string that will have the same CRC-32, as the
* initial ASCII string, and will have the same characters, as the target string,
* except for wildcards.
*
* Wildcard is '.' (dot).
*
* The program produces an example of how the CRC-32 is calculated bit by bit
* (and outputs the process on the screen). Then it shows how CRC-32 can be
* reversed to get the target CRC-32. Note that ZIP and Java use the reverse
* form of the polynomial, so bear in mind that the bits in the result are
* in the reverse order.
*
* Note also that the first 4 bytes may not be achieved in a-zA-Z range -
* that's because CRC-32 may not be reversible in such way, it may HAVE to have
* the bits that are forbidden by usage mask.
*
* (c) 2004 Sassa
*/

public class revCRC {
	public static final int POLYNOMIAL = 0x04c11db7;

	public static void main(String [] args) throws Exception {
		if (args.length!=2){
			System.out.println("usage: revCRC <initial string> <target string>\n\n\tinitial string - may only contain characters a-z, A-Z\n\ttarget string - may contain '.', wildcards\n\n");
			return;
		}

		byte [] original = args[0].getBytes();
		byte [] achieve = args[1].getBytes();
		byte [] usageMask = new byte[achieve.length];
		int firstBit=achieve.length*8;

		for (int i=0; i<usageMask.length; i++){
			if (achieve[i]=='.'){
				if (firstBit>i*8){
					firstBit=i*8;
				}

				achieve[i]=(byte)0x40;
				usageMask[i]=(byte)0xc0;
			}else{
				usageMask[i]=(byte)0xff;
			}
		}

		java.util.zip.CRC32 javacrc32 = new java.util.zip.CRC32();
		javacrc32.reset();
		javacrc32.update(original);

		long crcOriginal=javacrc32.getValue();

		javacrc32.reset();
		javacrc32.update(achieve);
		long crcAchieve=javacrc32.getValue();

		System.out.println("CRC-32 for `"+args[0]+"': "+Long.toHexString(crcOriginal)+
				"\nInitial CRC-32 for `"+new String(achieve)+"': "+Long.toHexString(crcAchieve));

		byte [] a = new byte[achieve.length+4];
		byte [] u = new byte[a.length];
		byte [] r = new byte[a.length]; // this array will hold the resulting string; it is initiated with achieve string of bytes, with crcOriginal XOR crcAchieve at the end

		System.arraycopy(achieve, 0, a, 0, achieve.length);
		a[0] ^= 0xff; // invert the first 4 bytes - that's "start with CRC_INIT=0xffffffff"
		a[1] ^= 0xff;
		a[2] ^= 0xff;
		a[3] ^= 0xff;

		System.arraycopy(usageMask, 0, u, 0, usageMask.length);
		System.arraycopy(a, 0, r, 0, a.length);

		crcAchieve ^= crcOriginal; // XOR both - we will show how CRC is calculated first
		//crcAchieve=~crcOriginal; // invert the CRC-32 value - get the actual CRC of the original message
		for (int i=usageMask.length; i<u.length; i++){
			a[i]=0;
			u[i]=(byte)0xff;
			r[i] ^=(byte)(crcAchieve & 0xff); // put 0 here to see the real CRC-32 of the message
			crcAchieve >>>= 8;
		}

		usageMask=u;
		achieve=a;

		byte [][] polynomial = new byte[8][];

		int p=POLYNOMIAL;

		for (int i=0; i<8; i++){
			polynomial[i]=new byte[4];

			int p1=p;

			for (int j=0; j<polynomial[i].length; j++){
				polynomial[i][j]=(byte)(p1 & 0xff);
				p1 >>= 8;
			}

			p=rol(p); // cyclic rotation
		}


		// now we are ready to reverse the CRC-32 to get the answer

		int bit=0; // the rightmost bit
		int bitNum=7; // what polynomial to use
		int bitpos=0;
						// note also that -1 is to account for the 33-d bit of the generator polynomial
		int pos=0;
		int mask=0xff;

		// have to reverse the bits in bytes, so they will be XORed in the right order
		reverse_bits(achieve);
		reverse_bits(usageMask);
		reverse_bits(r);

		printBits(achieve);
		printBits(r);
		System.out.println("-------------");
		System.out.println("\n\n*** Calculate CRC-32 now ***\n");

		while(bitpos<8*(achieve.length-4)){
			mask >>>=1;
			if (bit==0) bit=0x80;

			printBits(r);
			if ((r[pos] & bit) != 0){
				// i.e. in the next position there is 1

				for (int i=1; i<polynomial[bitNum].length; i++){
					r[pos+polynomial[bitNum].length-i] ^= polynomial[bitNum][i];
				}

				r[pos] ^= (polynomial[bitNum][0] & mask) | bit; // invert the highest bit, too
				r[pos+polynomial[bitNum].length] ^= polynomial[bitNum][0] & ~mask;
			}
			printPolynomial(bitpos);
			printBits(r);
			System.out.println("-------------");

			bit>>>=1;
			if (bit==0){ // full rotation occured
				pos++;
				mask=0xff;
			}

			bitpos++;
			bitNum = (bitNum-1) & 7;
		}


		System.out.println("\n\n*** CRC calculated now ***\n");


		printBits(achieve);
		printBits(usageMask);
		printBits(r);
		System.out.println("-------------");

		pos=achieve.length-1;
		mask=0;
		bitpos=8*(achieve.length-4)-1; // this is the position of the major bit that will change
		bit=1;
		bitNum=0;

		while(bitpos>=0){
			if ((usageMask[pos] & bit)!=0 && ((achieve[pos] & bit) != (r[pos] & bit))){
				// i.e. the usage Mask tells that this bit must have a specific value
				// and the bit in r (result) and achieve mask is different,
				// need to XOR the lot with the polynomial


				for (int i=1; i<polynomial[bitNum].length; i++){
					r[pos-i] ^= polynomial[bitNum][i];
				}

				r[pos] ^= polynomial[bitNum][0] & ~mask;
				r[pos-polynomial[bitNum].length] ^= (polynomial[bitNum][0] & mask) | bit; 
				// invert the highest bit, too
			}

			printBits(achieve);
			printBits(usageMask);

			printPolynomial(bitpos);
			printBits(r);
			System.out.println("-------------");

			bit=(byte)rol(bit, 8);
			if (bit==1){ // full rotation occured
				pos--;
				mask=0;
			}else{
				mask = (byte)(1 | (mask << 1));
			}
			bitpos--;
			bitNum = (bitNum+1) & 7;
		}

		reverse_bits(r);

		r[0] ^= 0xff; // inverse the first 4 bytes of the result back
		r[1] ^= 0xff;
		r[2] ^= 0xff;
		r[3] ^= 0xff;

		byte [] result = new byte[r.length-4];
		System.arraycopy(r, 0, result, 0, result.length);

		javacrc32.reset();
		javacrc32.update(result);

		long crcR = javacrc32.getValue();
		System.out.println("CRC-32 for `"+new String(result)+"': "+Long.toHexString(crcR));
	}

	public static int rol(int p){
		return rol(p, 32);
	}

	public static int rol(int p, int b){
		return ((p << 1) | ((p >> (b-1)) & 1)) & (0xffffffff >>> (32-b));
	}

	/**
	* This method reverses the bits in the bytes of the array.
	*/
	public static void reverse_bits(byte [] a){
		for (int i=0; i<a.length; i++){
			int b=0;
			for (int j=0; j<8; j++){
				b = (b << 1) | (a[i] & 1);
				a[i] >>>= 1;
			}
			a[i]=(byte)b;
		}
	}

	/**
	* Debugging method.
	*/
	public static void printBits(byte [] a){
		for (int i=0; i<a.length; i++){
			for (int j=0x80; j!=0; j>>=1){
				System.out.print((a[i] & j)!=0?"1":"0");
			}
			System.out.print(" ");
		}
		System.out.println();
	}

	public static void printPolynomial(int bitpos){
		for (int i=0; i<bitpos; i++) System.out.print(((i+1)& 7)==0?"  ":" ");

		System.out.print("1");
		bitpos++;

		for (int j=0x80000000; j!=0; j>>>=1, bitpos++){
			System.out.print(
				((bitpos & 7)==0?" ":"")+
				((POLYNOMIAL & j)!=0?"1":"0")
				);
		}
		System.out.println();
	}
}

---------------------------------------------------------------------

ਫ 

/*
* This code calculates CRC-32 of a given file.
* Then you can specify a CRC to reach, and it will give you 4 bytes to append
* to the file. You will need to xor the bytes with the actual value residing
* in the original file.

* cksum from UNIX does almost the same, but in a less efficient way (see comment
* on RICRC table); besides, they also use file length in the CRC output, and
* they use 0 as initial value, not FFFFFFFF, as specified by the standard.

* prepend your file with FF FF FF FF to obtain 0 CRC at the start
* of the actual file.
* append file length (truncate zero major bytes of the length) - now RICRC will
* give you the same value as the cksum utility.

* (c) 24 August 2001, Sassa
*/

public class CRC32 {
	private static final int [] CRC = new int[256];	// the table
	private static final int [] RICRC = new int[256];	
	// the table for reverse input CRC (bytes input msb->lsb, not usual lsb->msb)
	public static final int POLYNOMIAL = reverse(0x04c11db7, 32);	
			// this is a reverse of what Kris Kaspersky used to tell,
			// but this is what actually is used by Ethernet, PKZIP,
			// etc; if you notice, PKZIP etc have a different way
			// of applying it, while most people simply fail to
			// calculate the CRC32 properly at all (see all those free
			// code on-line). I think, my "RICRC", standing for
			// Reverse Input CRC table, is more efficient, than
			// the published code, since it does not need to do
			// those additional {crc >>> 24} all the time.
			// i simply have to output the bytes of the checksum in
			// the reverse order - that's all
	public static final int INITIAL_VALUE = 0xffffffff;

public static final String HELP_SCREEN = "usage: CRC32 filename 
[[-r]crc to achieve]\n\n the utility will calculate crc32 and will tell 
you the four bytes to append to the file, to get the given crc32 
value\nif -r option is specified, it calculates the bytes for the 
Reverse Input CRC (ZIP-like)\n\n";

        public static void main(String [] args){
                if (args.length<1 || args.length>3){
                        System.out.println(HELP_SCREEN);
                        System.exit(0);
                }

            try{
                java.io.FileInputStream fis = new java.io.FileInputStream(args[0]);

                init_table();

                int crc=INITIAL_VALUE;
                int ricrc = reverse(INITIAL_VALUE); // a bit silly thing - just in 
case you will need to use a different INITIAL_VALUE

                java.util.zip.CRC32 javacrc32=new java.util.zip.CRC32(); // reference 
implementation
                javacrc32.reset();

                while(fis.available()!=0){      // I've just checked that my code is 
correct: "resume" = 60C1D0A0 (CRC table), as advertised. RICRC gives 
something different, as it is supposed to do, either
                        int c=fis.read();
                        javacrc32.update(c);
                        crc = (crc >>> 8) ^ CRC[(crc ^ c) & 0xff];
                        ricrc = (ricrc >>> 8) ^ RICRC[(ricrc ^ c) & 0xff];
                }

                fis.close();

                System.out.println("Java CRC32: "+Long.toHexString(javacrc32.getValue())+
                                "\nCRC32: "+Integer.toHexString(crc ^ INITIAL_VALUE)+
                                "\nReverse input CRC32: "+Integer.toHexString(reverse_bytes(ricrc) ^ 
INITIAL_VALUE)
                        );

                if (args.length>1){
                        int achieve = (int)(Long.parseLong(args[args.length-1], 16) ^ 
INITIAL_VALUE);

                        int ri=0;
                        if (args.length==2){    // no -r option
                                ri = achieve(achieve, crc);
                        }else{
                                ri = achieve(reverse_bytes(achieve), ricrc);
                        }

                        System.out.println("\n\nxor the original bytes with such 4 bytes: 
"+Integer.toHexString(reverse_bytes(ri)));
                }

            }catch (Exception ex){
                System.out.println("oops...");
                ex.printStackTrace();
            }
        }


        public static void init_table(){
                for (int i=0; i<CRC.length; i++){
                        CRC[i] = i;
                        for (int j=0; j<8; j++){
                                CRC[i] = (CRC[i] >>> 1) ^ ((CRC[i] & 1)!=0 ? POLYNOMIAL : 0);
                        }
                        RICRC[reverse(i, 8)] = reverse(CRC[i]);
                }
        }

        private static int reverse(int what, int bits){
                int result = 0;
                for (; bits-->0; what >>=1){
                        result |= (what & 1) << bits;
                }
                return result;
        }

        private static int reverse(int what){ // reverses bits in bytes
                return reverse_bytes(reverse(what, 32));
        }

        private static int reverse_bytes(int c){ // reverse bytes
                return (c << 24) | ((c & 0xff00) << 8) |
                        ((c >> 8) & 0xff00) | (c >>> 24);
        }

        private static int achieve(int achieve, int crc){
                return achieve ^ crc;
        }
}
