Add repeating XOR encryption

This commit is contained in:
2024-07-31 16:49:39 +02:00
parent a18092cb6a
commit 20c2af05ec
3 changed files with 38 additions and 3 deletions

View File

@@ -103,3 +103,21 @@ export const detectSingleByteXor: DetectSingleByteXor = (buffs) => {
candidates.sort((a, b) => b[0] - a[0]);
return candidates[0][1];
};
type EncryptRepeatingXOR = (buff: Buffer, key: Buffer) => Buffer;
export const encryptRepeatingXOR: EncryptRepeatingXOR = (buff, key) => {
const resBuff = Buffer.alloc(buff.length);
range(0, buff.length).forEach(i => {
resBuff[i] = buff[i] ^ key[i % key.length];
});
return resBuff;
};
type DecryptRepeatingXOR = (buff: Buffer, key: Buffer) => Buffer;
export const decryptRepeatingXOR: DecryptRepeatingXOR = (buff, key) => {
const resBuff = Buffer.alloc(buff.length);
range(0, buff.length).forEach(i => {
resBuff[i] = buff[i] ^ key[i % key.length];
});
return resBuff;
};