1
// Crypto/ZipCrypto.cpp
8
#include "../../../../C/7zCrc.h"
14
void CCipher::UpdateKeys(Byte b)
16
Keys[0] = CRC_UPDATE_BYTE(Keys[0], b);
17
Keys[1] += Keys[0] & 0xff;
18
Keys[1] = Keys[1] * 134775813L + 1;
19
Keys[2] = CRC_UPDATE_BYTE(Keys[2], (Byte)(Keys[1] >> 24));
22
void CCipher::SetPassword(const Byte *password, UInt32 passwordLength)
27
for (UInt32 i = 0; i < passwordLength; i++)
28
UpdateKeys(password[i]);
31
Byte CCipher::DecryptByteSpec()
33
UInt32 temp = Keys[2] | 2;
34
return (Byte)((temp * (temp ^ 1)) >> 8);
37
Byte CCipher::DecryptByte(Byte encryptedByte)
39
Byte c = (Byte)(encryptedByte ^ DecryptByteSpec());
44
Byte CCipher::EncryptByte(Byte b)
46
Byte c = (Byte)(b ^ DecryptByteSpec());
51
void CCipher::DecryptHeader(Byte *buffer)
53
for (int i = 0; i < 12; i++)
54
buffer[i] = DecryptByte(buffer[i]);
57
void CCipher::EncryptHeader(Byte *buffer)
59
for (int i = 0; i < 12; i++)
60
buffer[i] = EncryptByte(buffer[i]);