-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
170 lines (137 loc) · 3.55 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
//utils
var counter = function(text){
return text.length;
}
var rate = function(numero){
if (numero % 2 == 0){
return 0;//p
}else{
return 1;//ip
}
}
var retro =function(text){
var back = '';
for (var i = text.length-1; i >= 0; i--) {
back=back+text[i];
};
return back;
}
var shake = function(model){
var character = '';
model.forEach(function(obj){
var text = obj.a;
if(obj.c===1){
var mid = Math.ceil(obj.b/2);
var textMid = text.substring(mid-1,mid);
var part1 = text.substring(0,mid-1);
var part2 = text.substring(mid,text.length);
character = character + retro(part1)+textMid+retro(part2)+'*';
}else{
var p = obj.b/2;
var part1 = text.substring(0,p);
var part2 = text.substring(p,text.length);
character = character + retro(part1)+retro(part2)+'*';
}
});
return character;
}
function bintoasc(bin) { // convierte de binario (01000001) a ascii (A)
var bin=bin+""; // asegura un valor "strings"
for (asc=0, i=0; i<bin.length; i++ ) {
asc=asc*2 + parseInt(bin.substr(i,1));
}
return String.fromCharCode(asc);
}
function asctobin(asc) { // conviert de ascii (A) a binario (01000001)
//var asc=asc.charCodeAt(0); // asegura un valor "numbers"
var bin="";
while (bin.length < 8) {
var z=parseInt(asc/2), bin=String.fromCharCode(48+(asc-z*2))+bin, asc=z;
}
return bin;
}
function aleatorio(inferior,superior){
numPosibilidades = superior - inferior
aleat = Math.random() * numPosibilidades
aleat = Math.floor(aleat)
return parseInt(inferior) + aleat
}
function hexa(){
hexadecimal = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F")
color_aleatorio = "#";
for (i=0;i<6;i++){
posarray = aleatorio(0,hexadecimal.length)
color_aleatorio += hexadecimal[posarray]
}
return color_aleatorio
}
console.log(hexa())
//fns
var chaos = function(text){
var divide = text.split(" ");
var model = [];
divide.forEach(function(element){
model.push({
a:element,
b:counter(element),
c:rate(counter(element))
})
});
return shake(model);
}
//main
var parser = function(text,chaos){
return chaos(text);
}
//scope
var insert=function(){
var text = document.getElementById('text').value;
document.getElementById('result').value = parser(text,chaos);
}
//
/*var hex =function(){
var a =['A','B','C','D','E','F','G','H','I','J','K','L','M','N','Ñ','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','ñ','o','p','q','r','s','t','u','v','w','x','y','z','á','é','í','ó','ú',' '];
a.forEach(function(str){
console.log(bintoasc(asctobin(str.charCodeAt(0)))+" "+asctobin(str.charCodeAt(0))+" "+str.charCodeAt(0)+" "+str);
})
var s = "t";
var b = asctobin(s.charCodeAt(0))
console.log('b',b)
}
hex();*/
/*var arPrim = new Array(1,2,3);
function primos(numero){
for(j=3;j<=numero;j+=2){
var primo = true;
for(k=2;k<arPrim.length;k++){
if(j%arPrim[k]==0){
primo = false;
break;
}
}
if (primo == true){
arPrim.push(j);
}
}
return arPrim;
}
var pr=primos(256);
var c=1;
pr.forEach(function(e){
var f = bintoasc(asctobin(e));
if(e>=37 && e<=113 || e>=163 && e!=173 && e<=233){
console.log(bintoasc(asctobin(e)),e,c++);
}
});*/
//console.log(bintoasc(asctobin('33')));
</script>
</head>
<body>
<textarea id="text" onkeyup="insert()"></textarea>
<textarea id="result"></textarea>
</body>
</html>