-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.js
More file actions
23 lines (20 loc) · 697 Bytes
/
cipher.js
File metadata and controls
23 lines (20 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function encode(secret, plainText){
let encodedText = '';
let originalUnicodeDecimal;
let newUnicodeDecimal;
for(i = 0; i < plainText.length; i++){
originalUnicodeDecimal = plainText.charCodeAt(i);
newUnicodeDecimal = originalUnicodeDecimal * secret;
encodedText += String.fromCharCode(newUnicodeDecimal)
}
return encodedText;
}
function decode(secret, encodedText){
let decodedText = '';
let originalUnicodeDecimal;
for(i = 0; i < encodedText.length; i++){
originalUnicodeDecimal = encodedText.charCodeAt(i) / secret;
decodedText += String.fromCharCode(originalUnicodeDecimal)
}
return decodedText;
}