-
Notifications
You must be signed in to change notification settings - Fork 7
/
cbc-sebnis-issue.js
72 lines (55 loc) · 1.72 KB
/
cbc-sebnis-issue.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
/*global describe it expect twofish*/
(function doTest(describe, it, expect, twofish){
'use strict';
describe('CBC SebNis', function doTestSuite() {
var IV = [180, 106, 2, 96, 176, 188, 73, 34, 181, 235, 7, 133, 164, 183, 204, 158]
, key = [73, 65, 63, 72, 65, 74]
, twF = twofish(IV);
it('cbc - issue use case #1', function doTestCase() {
var pt = 'Paris'
, ptArray = []
, ct
, cpt
, aSingleChar
, aSingleCharIndex = 0;
for (; aSingleCharIndex < pt.length; aSingleCharIndex += 1) {
aSingleChar = pt[aSingleCharIndex];
if (aSingleChar &&
aSingleChar.charCodeAt) {
ptArray.push(aSingleChar.charCodeAt());
}
}
if (ptArray.length === pt.length) {
ct = twF.encryptCBC(key, ptArray);
cpt = twF.decryptCBC(key, ct);
cpt = cpt.splice(0, pt.length);
expect(ptArray).toEqual(cpt);
} else {
expect(false).toEqual(true);
}
});
it('cbc - issue use case #2', function doTestCase() {
var pt = 'Berlin'
, ptArray = []
, ct
, cpt
, aSingleChar
, aSingleCharIndex = 0;
for (; aSingleCharIndex < pt.length; aSingleCharIndex += 1) {
aSingleChar = pt[aSingleCharIndex];
if (aSingleChar &&
aSingleChar.charCodeAt) {
ptArray.push(aSingleChar.charCodeAt());
}
}
if (ptArray.length === pt.length) {
ct = twF.encryptCBC(key, ptArray);
cpt = twF.decryptCBC(key, ct);
cpt = cpt.splice(0, pt.length);
expect(ptArray).toEqual(cpt);
} else {
expect(false).toEqual(true);
}
});
});
}(describe, it, expect, twofish));