MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / testBlockCipher

Function testBlockCipher

examples/crypt/cryptblockcipher/main.js:90–112  ·  view source on GitHub ↗
(name, keyStr, plain, expected)

Source from the content-addressed store, hash-verified

88}
89
90function testBlockCipher(name, keyStr, plain, expected)
91{
92 let key = ("string" == typeof keyStr) ? ArrayBuffer.fromString(keyStr) : keyStr;
93 expected = Hex.toBuffer(expected);
94
95 let result = (new BlockCipher(name, key)).encrypt(plain + "");
96
97 if (Bin.comp(result, expected) != 0)
98 trace(`${name} encrypt FAIL\n`);
99 else
100 trace(`${name} encrypt pass\n`);
101
102 plain = ArrayBuffer.fromString(plain);
103 result = (new BlockCipher(name, key)).decrypt(result)
104
105 if (Bin.comp(result, plain) != 0) {
106 trace(`${name} decrypt FAIL\n`);
107 trace(" result = " + Hex.toString(result) + "\n");
108 trace(" plain = " + Hex.toString(plain) + "\n");
109 }
110 else
111 trace(`${name} decrypt pass\n`);
112}
113
114function testStreamCipher(name, keyStr, plain, iv, counter, expected)
115{

Callers 1

main.jsFile · 0.85

Calls 4

fromStringMethod · 0.80
encryptMethod · 0.45
decryptMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected