1 extern uint CRCTab[256];
2 
SetKey13(const char * Password)3 void CryptData::SetKey13(const char *Password)
4 {
5   Key13[0]=Key13[1]=Key13[2]=0;
6   for (size_t I=0;Password[I]!=0;I++)
7   {
8     byte P=Password[I];
9     Key13[0]+=P;
10     Key13[1]^=P;
11     Key13[2]+=P;
12     Key13[2]=(byte)rotls(Key13[2],1,8);
13   }
14 }
15 
16 
SetKey15(const char * Password)17 void CryptData::SetKey15(const char *Password)
18 {
19   InitCRC32(CRCTab);
20   uint PswCRC=CRC32(0xffffffff,Password,strlen(Password));
21   Key15[0]=PswCRC&0xffff;
22   Key15[1]=(PswCRC>>16)&0xffff;
23   Key15[2]=Key15[3]=0;
24   for (size_t I=0;Password[I]!=0;I++)
25   {
26     byte P=Password[I];
27     Key15[2]^=P^CRCTab[P];
28     Key15[3]+=P+(CRCTab[P]>>16);
29   }
30 }
31 
32 
SetAV15Encryption()33 void CryptData::SetAV15Encryption()
34 {
35   InitCRC32(CRCTab);
36   Method=CRYPT_RAR15;
37   Key15[0]=0x4765;
38   Key15[1]=0x9021;
39   Key15[2]=0x7382;
40   Key15[3]=0x5215;
41 }
42 
43 
SetCmt13Encryption()44 void CryptData::SetCmt13Encryption()
45 {
46   Method=CRYPT_RAR13;
47   Key13[0]=0;
48   Key13[1]=7;
49   Key13[2]=77;
50 }
51 
52 
Decrypt13(byte * Data,size_t Count)53 void CryptData::Decrypt13(byte *Data,size_t Count)
54 {
55   while (Count--)
56   {
57     Key13[1]+=Key13[2];
58     Key13[0]+=Key13[1];
59     *Data-=Key13[0];
60     Data++;
61   }
62 }
63 
64 
Crypt15(byte * Data,size_t Count)65 void CryptData::Crypt15(byte *Data,size_t Count)
66 {
67   while (Count--)
68   {
69     Key15[0]+=0x1234;
70     Key15[1]^=CRCTab[(Key15[0] & 0x1fe)>>1];
71     Key15[2]-=CRCTab[(Key15[0] & 0x1fe)>>1]>>16;
72     Key15[0]^=Key15[2];
73     Key15[3]=rotrs(Key15[3]&0xffff,1,16)^Key15[1];
74     Key15[3]=rotrs(Key15[3]&0xffff,1,16);
75     Key15[0]^=Key15[3];
76     *Data^=(byte)(Key15[0]>>8);
77     Data++;
78   }
79 }
80