-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEncrypt Text ROT13.js
More file actions
43 lines (40 loc) · 1.06 KB
/
Encrypt Text ROT13.js
File metadata and controls
43 lines (40 loc) · 1.06 KB
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
javascript: var coding = "abcdefghijklmnopqrstuvwxyzabcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM";
function rot13(t) {
for (var r = "", i = 0; i < t.length; i++) {
character = t.charAt(i);
position = coding.indexOf(character);
if (position > -1) character = coding.charAt(position + 13);
r += character;
}
return r;
}
S = window.getSelection();
function t(N) {
return N.nodeType == N.TEXT_NODE;
}
function r(N) {
if (t(N)) N.data = rot13(N.data);
}
for (j = 0; j < S.rangeCount; ++j) {
var g = S.getRangeAt(j),
e = g.startContainer,
f = g.endContainer,
E = g.startOffset,
F = g.endOffset,
m = (e == f);
if (!m || !t(e)) {
/* rot13 each text node between e and f, not including e and f. */
q = document.createTreeWalker(g.commonAncestorContainer, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, null, false);
q.currentNode = e;
for (N = q.nextNode(); N && N != f; N = q.nextNode()) r(N);
}
if (t(f)) f.splitText(F);
if (!m) r(f);
if (t(e)) {
r(k = e.splitText(E));
if (m) f = k;
e = k;
}
if (t(f)) g.setEnd(f, f.data.length);
}
void 0