Add repeating XOR encryption
This commit is contained in:
18
basics.ts
18
basics.ts
@@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user