-
Notifications
You must be signed in to change notification settings - Fork 0
/
Traingles.html
88 lines (77 loc) · 2.69 KB
/
Traingles.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Triangle Translator</title>
<script>
function encode_utf8 (s) { // converts string to utf-8 escapes and ascii
return unescape(encodeURIComponent(s))}
function decode_utf8 (s) { // converts utf-8 escapes and ascii to string
return decodeURIComponent(escape(s))}
function ascii_to_hex (str) { // converts ascii character to hex value
var arr1 = [];
for (var n = 0, l = str.length; n < l; n ++) {
var hex = Number(str.charCodeAt(n)).toString(16);
arr1.push(hex)}
return arr1.join('')}
function hex_to_ascii (str1) { // converts hex value to ascii character
var hex = str1.toString();
var str = '';
for (var n = 0; n < hex.length; n += 2) {
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16))}
return str}
function en (int) { // convert single integer to triangles
if ((0 <= int) && (int <= 7)) {
return String.fromCodePoint(int - 0x0 + 0x25b2)
} else if ((8 <= int) && (int <= 15)) {
return String.fromCodePoint(int - 0x8 + 0x25bc)
} else {
return '='}}
function de (str) { // convert triangles to single integer
x = str.charCodeAt(0)
if ((0x25b2 <= x) && (x <= 0x25b9)) {
return x - 0x25b2 + 0x0
} else if ((0x25bc <= x) && (x <= 0x25c3)) {
return x - 0x25bc + 0x8
} else {
return '='}}
function hex_to_tri (str) { // convert hex to triangles
var str1 = ''
for (var i = 0; i < str.length; i++) {
str1 += en(parseInt(str.charAt(i), 16))}
return str1}
function tri_to_hex (str) { // convert triangles to hex
var str1 = ''
for (var i = 0; i < str.length; i++) {
str1 += de(str.charAt(i)).toString(16)}
return str1}
function encode () {
x = document.getElementById('en_input').value
y = hex_to_tri(ascii_to_hex(encode_utf8(x)))
document.getElementById('en_output').value = y}
function decode () {
x = document.getElementById('de_input').value
y = decode_utf8(hex_to_ascii(tri_to_hex(x)))
document.getElementById('de_output').value = y}
function move () {
x = document.getElementById('en_output').value
document.getElementById('de_input').value = x}
</script>
</head>
<body>
<b>Encoder (Unicode safe)</b><br>
<textarea id="en_input" cols="80" rows="6">
Type your input here!</textarea><br>
<input type="button" value="Translate!" onclick="encode();"><br>
<textarea id="en_output" cols="80" rows="6">
Output comes here!</textarea><br>
<input type="button" value="Transliterate!" onclick="move();"><br>
<b>Decoder (Unicode safe)</b><br>
<textarea id="de_input" cols="80" rows="6">
Type your input here!</textarea><br>
<input type="button" value="Translate!" onclick="decode();"><br>
<textarea id="de_output" cols="80" rows="6">
Output comes here!</textarea><br>
</body>
</html>