-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
29 lines (22 loc) · 1.33 KB
/
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
const { textToPlaincode, plaincodeToText, createOnetimePad, nob, codebook, checkLength, encryptPlaincode, decryptEncryptedMsg } = require('./dist/otp-ed-lib.nodejs.cjs.js')
// The message
const message = 'Hello 👨👩👦👦🏳️🌈😀🇿🇼 world, 123:æøå! https://somesecreturl.com/'
console.log('\n\nMessage: ' + message)
// ### Testing: Text to plaincode
const plaincodeConverted = textToPlaincode(message, nob, codebook)
console.log('Plaincode: ' + plaincodeConverted)
// ### Testing: Creating a one-time pad
const otp = createOnetimePad(1024)
console.log('One-time pad: ' + otp)
// ### Checking length of plaincode vs. one-time pad
const lengthObj = checkLength(plaincodeConverted, otp)
console.log('Length: ' + JSON.stringify(lengthObj))
// ### Testing: Encrypting plaincode
const encryptedMsg = encryptPlaincode(plaincodeConverted, otp)
console.log('Encrypted plaincode: ' + encryptedMsg.join(''))
// ### Testing: Decrypting encrypted message
const decryptedPlaincode = decryptEncryptedMsg(encryptedMsg.join(''), otp)
console.log('Decrypted plaincode: ' + decryptedPlaincode.join(''))
// ### Plaincode to text - The message delivered!
const textConverted = plaincodeToText(decryptedPlaincode.join(''), nob, codebook)
console.log('Decrypted message: ' + textConverted + '\n\n')