Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 58 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,34 +363,66 @@ export default class Giiker extends EventEmitter {
};

const moves = [];
for (let i = 0; i < value.byteLength; i++) {
const move = value.getUint8(i);

const highNibble = move >> 4;
const lowNibble = move & 0b1111;

if (i < 4) {
state.cornerPositions.push(highNibble, lowNibble);
} else if (i < 8) {
state.cornerOrientations.push(highNibble, lowNibble);
} else if (i < 14) {
state.edgePositions.push(highNibble, lowNibble);
} else if (i < 16) {
state.edgeOrientations.push(!!(move & 0b10000000));
state.edgeOrientations.push(!!(move & 0b01000000));
state.edgeOrientations.push(!!(move & 0b00100000));
state.edgeOrientations.push(!!(move & 0b00010000));
if (i === 14) {
state.edgeOrientations.push(!!(move & 0b00001000));
state.edgeOrientations.push(!!(move & 0b00000100));
state.edgeOrientations.push(!!(move & 0b00000010));
state.edgeOrientations.push(!!(move & 0b00000001));
if (value.getUint8(18) == 0xa7) { // decrypt
var key = [176, 81, 104, 224, 86, 137, 237, 119, 38, 26, 193, 161, 210, 126, 150, 81, 93, 13, 236, 249, 89, 235, 88, 24, 113, 81, 214, 131, 130, 199, 2, 169, 39, 165, 171, 41];
var k = value.getUint8(19);
var k1 = k >> 4 & 0xf;
var k2 = k & 0xf;
for (let i = 0; i < value.byteLength; i++) {
const move = (value.getUint8(i) + key[i + k1] + key[i + k2]) & 0xff;
const highNibble = move >> 4;
const lowNibble = move & 0b1111;
if (i < 4) {
state.cornerPositions.push(highNibble, lowNibble);
} else if (i < 8) {
state.cornerOrientations.push(highNibble, lowNibble);
} else if (i < 14) {
state.edgePositions.push(highNibble, lowNibble);
} else if (i < 16) {
state.edgeOrientations.push(!!(move & 0b10000000));
state.edgeOrientations.push(!!(move & 0b01000000));
state.edgeOrientations.push(!!(move & 0b00100000));
state.edgeOrientations.push(!!(move & 0b00010000));
if (i === 14) {
state.edgeOrientations.push(!!(move & 0b00001000));
state.edgeOrientations.push(!!(move & 0b00000100));
state.edgeOrientations.push(!!(move & 0b00000010));
state.edgeOrientations.push(!!(move & 0b00000001));
}
} else {
moves.push(this._parseMove(highNibble, lowNibble));
}
}
}
else {
for (let i = 0; i < value.byteLength; i++) {
const move = value.getUint8(i);

const highNibble = move >> 4;
const lowNibble = move & 0b1111;

if (i < 4) {
state.cornerPositions.push(highNibble, lowNibble);
} else if (i < 8) {
state.cornerOrientations.push(highNibble, lowNibble);
} else if (i < 14) {
state.edgePositions.push(highNibble, lowNibble);
} else if (i < 16) {
state.edgeOrientations.push(!!(move & 0b10000000));
state.edgeOrientations.push(!!(move & 0b01000000));
state.edgeOrientations.push(!!(move & 0b00100000));
state.edgeOrientations.push(!!(move & 0b00010000));
if (i === 14) {
state.edgeOrientations.push(!!(move & 0b00001000));
state.edgeOrientations.push(!!(move & 0b00000100));
state.edgeOrientations.push(!!(move & 0b00000010));
state.edgeOrientations.push(!!(move & 0b00000001));
}
} else {
moves.push(this._parseMove(highNibble, lowNibble));
}
} else {
moves.push(this._parseMove(highNibble, lowNibble));
}
}

return { state, moves };
}

Expand Down Expand Up @@ -563,4 +595,4 @@ export default class Giiker extends EventEmitter {

return faces.join('');
}
}
}