-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
79 lines (69 loc) · 2.56 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const Natocrypt = require("./index");
let { nato_alphabet_list, nato_characters } = require("./utils/nato");
let { morse_characters } = require("./utils/morse");
const nato = new Natocrypt();
let encrypted_text = nato.encrypt("h3lL0 g4m3f4c3!", 200);
test("encryption successful", () => {
nato_alphabet_list.forEach((char) => {
expect(encrypted_text.field).toContain(char);
});
expect(encrypted_text.field).not.toBeNull();
});
test("decryption successful", () => {
expect(nato.decrypt(encrypted_text)).toBe("h3lL0 g4m3f4c3!");
});
test("comparison successful", () => {
const result = nato.compare("h3lL0 g4m3f4c3!", encrypted_text);
const result2 = nato.compare("something else", encrypted_text);
expect(result).toBe(true);
expect(result2).toBe(false);
});
test("auto generated multiplier successful", () => {
let encrypted_text = nato.encrypt("h3lL0 g4m3f4c3!");
nato_alphabet_list.forEach((char) => {
expect(encrypted_text.field).toContain(char);
});
expect(encrypted_text.field).not.toBeNull();
});
test("character registration successful", () => {
let encrypted_test_string = nato.encrypt(
"1234567890-=,./;'`[]<>?:{}!@#$%^&*()_+qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
);
for (let key in nato_characters) {
expect(encrypted_test_string.field).toContain(nato_characters[key]);
}
expect(encrypted_test_string.field).not.toBeNull();
});
let encrypted_morse = nato.morse("encrypt", "h3Ll0 g4m3f4c3!");
let decrypted_morse = nato.morse("decrypt", encrypted_morse);
test("morse encryption successful", () => {
expect(decrypted_morse).toBe("h3Ll0 g4m3f4c3!");
expect(decrypted_morse).not.toBeNull();
});
test("morse encryption with multiplier successful", () => {
let encrypted_morse_with_multiplier = nato.morse(
"encrypt",
"h3Ll0 g4m3f4c3!",
7
);
let decrypted_morse_with_multiplier = nato.morse(
"decrypt",
encrypted_morse_with_multiplier
);
expect(decrypted_morse_with_multiplier).toBe("h3Ll0 g4m3f4c3!");
expect(decrypted_morse_with_multiplier).not.toBeNull();
});
test("morse character registration successful", () => {
let encrypted_morse_with_all_characters = nato.morse(
"encrypt",
"1234567890.,?'!/()&:;=+-$@qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
);
let decrypted_morse_with_all_characters = nato.morse(
"decrypt",
encrypted_morse_with_all_characters
);
expect(decrypted_morse_with_all_characters).toBe(
"1234567890.,?'!/()&:;=+-$@qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
);
expect(decrypted_morse_with_all_characters).not.toBeNull();
});