mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-10 08:15:00 -04:00
Reset Stream
This commit is contained in:
parent
41a080aee1
commit
54286784a7
1 changed files with 1 additions and 23 deletions
|
@ -105,47 +105,25 @@ export default class Stream {
|
|||
bitBufLen = 0;
|
||||
|
||||
// Add remaining bits from current byte
|
||||
console.log("Bit pos: " + this.bitPos.toString(2));
|
||||
console.log("Pos: " + this.position.toString(2));
|
||||
|
||||
bitBuf = (this.bytes[this.position++] & bitMask(this.bitPos)) >>> this.bitPos;
|
||||
bitBufLen = 8 - this.bitPos;
|
||||
this.bitPos = 0;
|
||||
|
||||
console.log("Bit pos: " + this.bitPos.toString(2));
|
||||
console.log("Bit buff: " + bitBuf.toString(2));
|
||||
console.log("Bit buff len: " + bitBufLen.toString(2));
|
||||
console.log("Num bits: " + numBits.toString(2));
|
||||
|
||||
|
||||
|
||||
// Not enough bits yet
|
||||
while (bitBufLen < numBits) {
|
||||
bitBuf |= this.bytes[this.position++] << bitBufLen;
|
||||
bitBufLen += 8;
|
||||
}
|
||||
|
||||
console.log("Pos: " + this.position.toString(2));
|
||||
|
||||
// Reverse back to numBits
|
||||
if (bitBufLen > numBits) {
|
||||
|
||||
const excess = bitBufLen - numBits;
|
||||
console.log("Excess: " + excess.toString(2));
|
||||
console.log("Bit buff: " + bitBuf.toString(2));
|
||||
console.log("Mask: " + ((1 << numBits) - 1).toString(2));
|
||||
//bitBuf &= (1 << numBits) - 1;
|
||||
bitBuf &= 256 - (1 << numBits);
|
||||
bitBuf = bitBuf >> excess;
|
||||
bitBuf &= (1 << numBits) - 1;
|
||||
bitBufLen -= excess;
|
||||
this.position--;
|
||||
this.bitPos = 8 - excess;
|
||||
}
|
||||
|
||||
console.log("Bit buff len: " + bitBufLen.toString(2));
|
||||
console.log("Bit buff: " + bitBuf.toString(2));
|
||||
console.log("Pos: " + this.position.toString(2));
|
||||
|
||||
return bitBuf;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue