first commit

This commit is contained in:
didier amyot committed 2016-03-25 17:54:34 -04:00
commit 5a8274a7ef
10 files changed
+651

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
var util = require("../dist/spritz.js")._util;
var spritz = require("../dist/spritz.js");
var assert = require('assert');
describe('utility functions', function() {
describe('the low function', function(){
it('should get the low nibble of the input', function () {
assert.equal(util.low(3), 3);
assert.equal(util.low(0), 0);
assert.equal(util.low(255), 15);
});
});
});
describe('the string to array convertion', function(){
it('should be able to convert string to utf-8 array', function(){
var utf8String = "maison-дом-տուն-სახლი";
var expt = [109,97,105,115,111,110,45,208,180,208,190,208,188,45,213,191,213,184,214,130,213,182,45,225,131,161,225,131,144,225,131,174,225,131,154,225,131,152];
assert.deepEqual(spritz.stringToUtf8ByteArray(utf8String), expt);
});
it('should be able to convert utf-8 array to string', function(){
var utf8Array = [109,97,105,115,111,110,45,208,180,208,190,208,188,45,213,191,213,184,214,130,213,182,45,225,131,161,225,131,144,225,131,174,225,131,154,225,131,152];
var expt = "maison-дом-տուն-სახლი";
assert.deepEqual(spritz.utf8ByteArrayToString(utf8Array), expt);
});
});
describe('the hash function', function(){
it('should be able to hash an array', function(){
var M = [65, 66, 67];
var r = 32;
var expt = [2,143,162,180,139,147,74,24,98,184,105,16,81,58,71,103,124,28,45,149,236,62,117,112,120,111,28,50,139,189,74,71];
assert.deepEqual(spritz.hash(M, r), expt);
});
it('should be able to hash a string', function(){
var M = 'ABC';
var r = 32;
var expt = [2,143,162,180,139,147,74,24,98,184,105,16,81,58,71,103,124,28,45,149,236,62,117,112,120,111,28,50,139,189,74,71];
assert.deepEqual(spritz.hash(M, r), expt);
});
});
describe('the encrypt/decrypt function', function(){
it('should be encrypt/decrypt a byte array', function(){
var stringMessage = "maison-дом-տուն-სახლი";
var byteArrMessage = spritz.stringToUtf8ByteArray(stringMessage);
var key = [12, 99, 200, 76, 162, 87, 729, 272, 272, 282, 282];
var cypher = spritz.encrypt(key, byteArrMessage);
var decryptedMessage = spritz.decrypt(key, cypher);
assert.deepEqual(decryptedMessage, byteArrMessage);
});
xit('should encrypt correctly the message', function(){
var stringMessage = "maison-дом-տուն-სახლი";
var byteArrMessage = spritz.stringToUtf8ByteArray(stringMessage);
var key = [12, 55, 12, 12, 87, 89, 81, 17, 27, 89];
var cypher = spritz.encrypt(key, byteArrMessage);
var expt = [125,26,182,7,75,36,178,253,82,46,91,21,218,16,127,41,203,45,90,129,129,47,171,68,221,112,210,6,99,250,91,111,225,27,89,100,189,9];
assert.deepEqual(cypher, expt);
});
});