File: crypt1.cpp

package info (click to toggle)
unrar-nonfree 1%3A7.1.8-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 1,952 kB
  • sloc: cpp: 26,394; makefile: 712; sh: 11
file content (66 lines) | stat: -rw-r--r-- 1,258 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
void CryptData::SetKey13(const char *Password)
{
  Key13[0]=Key13[1]=Key13[2]=0;
  for (size_t I=0;Password[I]!=0;I++)
  {
    byte P=Password[I];
    Key13[0]+=P;
    Key13[1]^=P;
    Key13[2]+=P;
    Key13[2]=(byte)rotls(Key13[2],1,8);
  }
}


void CryptData::SetKey15(const char *Password)
{
  InitCRC32(CRCTab);
  uint PswCRC=CRC32(0xffffffff,Password,strlen(Password));
  Key15[0]=PswCRC&0xffff;
  Key15[1]=(PswCRC>>16)&0xffff;
  Key15[2]=Key15[3]=0;
  for (size_t I=0;Password[I]!=0;I++)
  {
    byte P=Password[I];
    Key15[2]^=P^CRCTab[P];
    Key15[3]+=ushort(P+(CRCTab[P]>>16));
  }
}


void CryptData::SetCmt13Encryption()
{
  Method=CRYPT_RAR13;
  Key13[0]=0;
  Key13[1]=7;
  Key13[2]=77;
}


void CryptData::Decrypt13(byte *Data,size_t Count)
{
  while (Count--)
  {
    Key13[1]+=Key13[2];
    Key13[0]+=Key13[1];
    *Data-=Key13[0];
    Data++;
  }
}


void CryptData::Crypt15(byte *Data,size_t Count)
{
  while (Count--)
  {
    Key15[0]+=0x1234;
    Key15[1]^=CRCTab[(Key15[0] & 0x1fe)>>1];
    Key15[2]-=ushort(CRCTab[(Key15[0] & 0x1fe)>>1]>>16);
    Key15[0]^=Key15[2];
    Key15[3]=rotrs(Key15[3]&0xffff,1,16)^Key15[1];
    Key15[3]=rotrs(Key15[3]&0xffff,1,16);
    Key15[0]^=Key15[3];
    *Data^=(byte)(Key15[0]>>8);
    Data++;
  }
}