Breaking XOR Encryption with multiple keys of known size

I’m currently trying to break the XOR encryption of a known custom xor-encryption algorithm.

The Encryption uses 4-Byte XOR keys. The full algorithm has a table with 32768 Keys. The keys are all derived from 2 different seeds. The first half of the key table is created with the first seed (16384 elements) and the remaining half is created with the 2nd seed.

The creation of the key table can be found at github with the “Random” function found here.

func (k *KeyRand) Rand() int64 {
    // some hardcoded function from ep3 sources...
    // probably should be changed with other(better) algorithm
    k.holdRand = k.holdRand*49723125 + 21403831
    return (((((int64)(k.holdRand)>>16)*41894339 + 11741117) >> 16) & 0xFFFF)
}

The Encryption algorithm (taken from here) looks like:

func (e *Encryption) Encrypt(data []byte) ([]byte, error) {
    var iLen = len(data)

    if iLen < S2CHeaderSize {
        // packet is smaller than header...
        return nil, errors.New(
            fmt.Sprintf(
                "Packet length is smaller than required! Detected: %d, required: %d",
                iLen, S2CHeaderSize,
            ),
        )
    }

    var pPayload = make([]byte, iLen)

    var xorKey uint32
    var xorNum uint32

    // header
    xorNum = binary.LittleEndian.Uint32(data) ^ SendXorKey
    binary.LittleEndian.PutUint32(pPayload, xorNum)
    xorKey = e.Key.KeyTable[xorNum&RecvXorKeyNumMask]

    var payloadLen = iLen - (S2CHeaderSize - MainCMDSize)
    var j int32 = 4

    for i := 0; i < payloadLen/4; i++ {
        xorNum = binary.LittleEndian.Uint32(data[j:j+4]) ^ xorKey
        binary.LittleEndian.PutUint32(pPayload[j:j+4], xorNum)
        xorKey = e.Key.KeyTable[xorNum&RecvXorKeyNumMask]
        j += 4
    }

    var remainLen = int32(iLen % 4)
    var remainData = make([]byte, 4)

    copy(remainData, data[j:j+remainLen])
    var r = binary.LittleEndian.Uint32(remainData)
    var m = mask[remainLen]

    xorNum = r ^ xorKey
    r = xorNum ^ (xorKey & m)

    binary.LittleEndian.PutUint32(remainData, r)
    copy(pPayload[j:j+remainLen], remainData[0:remainLen])

    return pPayload, nil
}

The messages (data []byte) are built like:

  1. 2 Byte MagicKey
  2. 2 Byte Length of the message
  3. 2 Byte opcode
  4. x Byte depending on the opcode

The secrets are:

  • MagicKey
  • SendXorKey
  • e.Key.KeyTable
  • The first seed of the KeyTable
    The second seed of the KeyTable
    And for decryption of client messages:
  • RecvXorSeed
  • Recv2ndXorSeed

What I know/assume / What I can do

  • For some parts/opcodes I can do a known plaintext attack. (Length and opcode, also some data for specific opcodes)
  • The plaintext almost always encrypts to the same cipher except another key is taken because the previous 4 bytes were too different.
  • The key for the current 4-bytes depends on the data of the previous 4 bytes

What I’m interested in:

  • Is it possible to get the secrets to be able to decrypt everything?
  • If it is possible how would I do that except KPA for known parts?
  • Is it possible to decrypt the parts of messages where a KPA is not possible?
  • As a last resort: Could I break the encryption by decompiling the client? I assume that the secrets are stored in the client because it is a symmetric encryption algorithm. If possible I would like to avoid this option.
  • I assume brute force can’t be done in a realistic/short time?
  • Is it possible to derive the RecvXorSeed and Recv2ndXorSeed knowing the position of a key in the table?

New contributor

programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật