-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryption-decryption.js
38 lines (25 loc) · 1.01 KB
/
encryption-decryption.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
const ElGamal = require('../elgamal');
const debug = require('debug');
const log = debug('app::test')
async function test(){
const elgamal = new ElGamal();
log('Initialize the engine remotely...');
await elgamal.initializeRemotely();
let securityStatus = elgamal.checkSecurity();
if(! securityStatus){
log('Error: Engine is not secure.');
return;
}
let message = await elgamal.randomGropuMember();
log(`length of selected message is ${message.bitLength()} and
the original message is: ${message}`);
log('Encrypting message...');
let cipherPair = await elgamal.encrypt(message);
log('Resulted cipher text:', cipherPair);
log('Decrypting cipher text...');
let decryptedMessage = await elgamal.decrypt(cipherPair);
log(`length of decrypted message is ${decryptedMessage.bitLength()} and
the decrypted decryptedMessage is: ${message}`);
log(`\n\n========> Test Result: ${message.equals(decryptedMessage)} <========`);
}
test();