-
Notifications
You must be signed in to change notification settings - Fork 0
/
elaboration.js
55 lines (44 loc) · 1.47 KB
/
elaboration.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
function myFunction()
{
var plain_text = document.getElementById('textarea1').value;
if (plain_text.length == 0)
{
alert("String empty")
}
else
{
var encoded_string = '';
// Go through each character
for (var i = 0; i < plain_text.length; i++)
{
// Get the character we'll be appending
var single_character = plain_text[i];
// If it's a letter...
if (single_character .match(/[a-z]/i))
{
// Get its code
var code = plain_text.charCodeAt(i);
// Uppercase letters
if ((code >= 65) && (code <= 90))
single_character = String.fromCharCode(((code - 65 + 13) % 26) + 65);
// Lowercase letters
else if ((code >= 97) && (code <= 122))
single_character = String.fromCharCode(((code - 97 + 13) % 26) + 97);
}
// Append
encoded_string += single_character;
}
}
show_encoded_string(encoded_string);
}
function show_encoded_string(encoded_string)
{
var paragraph = document.getElementById("paragraph1");
var text = document.createTextNode(encoded_string);
paragraph.appendChild(text);
}
function reset()
{
document.getElementById("textarea1").value = '';
document.getElementById('paragraph1').innerHTML = ' ';
}