[qmc2/rc4] fix: match QMC2 decoder logic
This commit is contained in:
parent
f75a3ccb34
commit
6a56cc8433
@ -31,8 +31,9 @@ impl QMC2RC4 {
|
||||
let n = self.key.len();
|
||||
|
||||
for (datum, offset) in data.iter_mut().zip(offset..) {
|
||||
let idx = get_segment_key(offset as u64, self.key[offset % n], self.hash) as usize;
|
||||
*datum ^= self.key[idx % n];
|
||||
let idx = get_segment_key(offset as u64, self.key[offset % n], self.hash);
|
||||
let idx = idx % (n as u64);
|
||||
*datum ^= self.key[idx as usize];
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,10 +44,11 @@ impl QMC2RC4 {
|
||||
let block_offset = offset % OTHER_SEGMENT_SIZE;
|
||||
|
||||
let seed = self.key[id % n];
|
||||
let skip = get_segment_key(id as u64, seed, self.hash) % 512;
|
||||
let skip = get_segment_key(id as u64, seed, self.hash);
|
||||
let skip = (skip & 0x1FF) as usize;
|
||||
|
||||
debug_assert!(data.len() <= OTHER_SEGMENT_SIZE - block_offset);
|
||||
let key_stream = self.key_stream.iter().skip(skip as usize + block_offset);
|
||||
let key_stream = self.key_stream.iter().skip(skip + block_offset);
|
||||
for (datum, &key) in data.iter_mut().zip(key_stream) {
|
||||
*datum ^= key;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user