-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
88 lines (76 loc) · 2.08 KB
/
index.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<html>
<script type="text/javascript">
function encode (str, code) {
var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*()_+,.<>/[]{}|;:'";
//code = code.toLowerCase();
//str = str.toLowerCase();
var ret = "";
for( i=0; i<str.length; i++ )
{
if( code.indexOf( str.charAt(i) ) > -1 )
{
ret = ret + code.charAt( abc.indexOf(str.charAt( i )) );
}
else
{
ret = ret + str.charAt(i);
}
}
return ret;
}
function decode (str, code) {
var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*()_+,.<>/[]{}|;:'";
//code = code.toLowerCase();
//str = str.toLowerCase();
var ret = "";
for( i=0; i<str.length; i++ )
{
if( abc.indexOf( str.charAt(i) ) > -1 )
{
ret = ret + abc.charAt( code.indexOf(str.charAt( i )) );
}
else
{
ret = ret + str.charAt(i);
}
}
return ret;
}
function code () {
var c = "";
var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*()_+,.<>/[]{}|;:'";
var l = abc.length;
console.log("l is: " + l);
var i = 0;
var r = 0;
//for (i = 0; i < 26; i++)
while (i < l)
{
r = Math.floor(Math.random() * l);
console.log("r is: " + r);
console.log("The letter is: " + abc[r]);
if (c.indexOf(abc[r]) === -1) {
c = c + abc[r];
i++;
console.log("c is: " + c);
}
}
console.log("the length of c is: " + c.length);
return c;
}
</script>
</head>
<body>
<p> Enter Text: </p>
<textarea rows="30" cols="80" id="x" name="x"></textarea>
<br> <br>
<p> Output Text: </p>
<textarea rows="30" cols="80" id="a" name="a"></textarea>
<p> Enter Code: </p>
<textarea rows="1" cols="80" id="y" name="y"></textarea> <br>
<input type="button" value="Encode" onClick="document.getElementById('a').value = encode( document.getElementById('x').value, document.getElementById('y').value);">
<input type="button" value="Decode" onClick="document.getElementById('a').value = decode( document.getElementById('x').value, document.getElementById('y').value);">
<br>
<input type="button" value="Create Code" onClick="document.getElementById('y').value = code ();">
</body>
</html>