Add solutions to challenge 4
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import test from 'node:test';
|
||||
import * as path from 'node:path';
|
||||
import * as assert from 'node:assert/strict';
|
||||
|
||||
import { range } from '../utils';
|
||||
import { hexToBuff, buffTo64, xorBuffers, encryptSingleByte, decryptSingleByte, crackSingleByteKeyMsg } from '../basics';
|
||||
const DATA_PATH = path.join(__dirname, '..', 'data');
|
||||
|
||||
import { range, fileToBuff } from '../utils';
|
||||
import { hexToBuff, buffTo64, xorBuffers, encryptSingleByte, decryptSingleByte, crackSingleByteKeyMsg, detectSingleByteXor } from '../basics';
|
||||
|
||||
test('range', () => {
|
||||
assert.deepEqual(range(0, 10), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
@@ -33,3 +36,9 @@ test('crack produces english sentence', () => {
|
||||
const expected = 'Cooking MC\'s like a pound of bacon';
|
||||
assert.equal(crackSingleByteKeyMsg(input), expected);
|
||||
});
|
||||
|
||||
test('detect single byte xor', () => {
|
||||
const input = fileToBuff(path.join(DATA_PATH, 'xorSingleByte.txt'), 'hex');
|
||||
const expected = 'Now that the party is jumping';
|
||||
assert.equal(detectSingleByteXor(input), expected);
|
||||
});
|
||||
|
Reference in New Issue
Block a user