-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypt.js
67 lines (66 loc) · 1.71 KB
/
crypt.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
var Module = {
onRuntimeInitialized: function() {
console.log('WASM module loaded!')
console.log(Module)
app.wasmModuleLoaded = true
}
}
const app = new Vue({
el: '#app',
data: {
selectedCipher: 'CaesarCipher',
ciphers: [
{ id: 1, name: 'CaesarCipher' },
{ id: 2, name: 'CaesarCipherExt' },
{ id: 3, name: 'MonoAlpha' },
{ id: 4, name: 'RailFence' }
],
message: '',
caesarCipherExtKey: 3,
wasmModuleLoaded: false,
timeTaken: 0
},
methods: {
getEncryptedMessage: function(selectedCipher, message, caesarCipherExtKey = 3) {
let cipher = null
const start = Date.now()
switch(selectedCipher) {
case 'CaesarCipher':
cipher = new Module.CaesarCipher(message)
break
case 'CaesarCipherExt':
cipher = new Module.CaesarCipherExt(message, caesarCipherExtKey)
break
case 'MonoAlpha':
cipher = new Module.MonoAlpha(message)
break
case 'RailFence':
cipher = new Module.RailFence(message)
break
}
const encryptedMessage = cipher.Encrypt()
const end = Date.now()
const timeTaken = end - start
cipher.delete()
return { encryptedMessage, timeTaken }
}
},
computed: {
encryptedMessage: function() {
let encryptedMessage = ''
if (this.wasmModuleLoaded && this.message) {
const enc = this.getEncryptedMessage(
this.selectedCipher,
this.message,
this.caesarCipherExtKey
)
encryptedMessage = enc.encryptedMessage
this.timeTaken = enc.timeTaken
}
return encryptedMessage
},
numberOfWords: function() {
return this.message.length
}
}
})