Add solutions to challenge 4

This commit is contained in:
2024-07-31 13:19:47 +02:00
parent d3423779dc
commit cc1a51c298
4 changed files with 362 additions and 2 deletions

View File

@@ -90,3 +90,16 @@ export const crackSingleByteKeyMsg: CrackSingleByteKeyMsg = (msg) => {
candidates.sort((a, b) => b[0] - a[0]);
return candidates[0][1];
};
type DetectSingleByteXor = (buffs: Buffer[]) => string;
export const detectSingleByteXor: DetectSingleByteXor = (buffs) => {
const candidates = [] as [number, string][];
buffs.slice(0, -1).forEach(buff => {
range(0, 255).forEach(i => {
const decrypted = decryptSingleByte(buff, i);
candidates.push([scoreBuffer(decrypted), decrypted.toString('utf-8').trim()]);
});
});
candidates.sort((a, b) => b[0] - a[0]);
return candidates[0][1];
};