Add solutions to challenge 4
This commit is contained in:
13
basics.ts
13
basics.ts
@@ -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];
|
||||
};
|
||||
|
Reference in New Issue
Block a user