| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
use SWF qw(:ALL); |
|---|
| 23 |
use SWF::Constants qw(:Text :Button :DisplayItem :Fill); |
|---|
| 24 |
|
|---|
| 25 |
SWF::setScale(1); |
|---|
| 26 |
SWF::useSWFVersion(6); |
|---|
| 27 |
my $movie = new SWF::Movie(); |
|---|
| 28 |
$movie->setDimension(100, 100); |
|---|
| 29 |
$movie->setBackground(0xFF, 0xFF, 0xFF); |
|---|
| 30 |
$movie->setRate(30); |
|---|
| 31 |
$movie->add(new SWF::Action(<<"EndOfActionScript")); |
|---|
| 32 |
|
|---|
| 33 |
var dummyVar=(getTimer()+random(100000)); |
|---|
| 34 |
|
|---|
| 35 |
if(context != undefined) { |
|---|
| 36 |
context = context.toUpperCase(); |
|---|
| 37 |
colaEvento(0,"debug","contexto leido "+context); |
|---|
| 38 |
if(context == "DEFAULT") { context=""; } |
|---|
| 39 |
} else { |
|---|
| 40 |
colaEvento(0,"debug","context undefined"); |
|---|
| 41 |
context=""; |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
var archivo = "variables"+context+".txt?rand="+dummyVar; |
|---|
| 45 |
|
|---|
| 46 |
vr = new LoadVars (); |
|---|
| 47 |
|
|---|
| 48 |
vr.onLoad = function (success) |
|---|
| 49 |
{ |
|---|
| 50 |
if (success == true) { |
|---|
| 51 |
colaEvento(0,"debug","Ok al leer "+archivo); |
|---|
| 52 |
nextFrame(); |
|---|
| 53 |
} else { |
|---|
| 54 |
colaEvento(0,"debug","Fallo al leer "+archivo); |
|---|
| 55 |
stop(); |
|---|
| 56 |
} |
|---|
| 57 |
}; |
|---|
| 58 |
|
|---|
| 59 |
vr.load(archivo); |
|---|
| 60 |
|
|---|
| 61 |
EndOfActionScript |
|---|
| 62 |
|
|---|
| 63 |
$movie->nextFrame(); |
|---|
| 64 |
$movie->add(new SWF::Action(<<"EndOfActionScript")); |
|---|
| 65 |
|
|---|
| 66 |
function conecta() { |
|---|
| 67 |
_global.sock = new XMLSocket; |
|---|
| 68 |
_global.sock.onConnect = handleConnect; |
|---|
| 69 |
_global.sock.onClose = handleDisconnect; |
|---|
| 70 |
_global.sock.onXML = handleXML; |
|---|
| 71 |
if(_global.port == undefined) { |
|---|
| 72 |
_global.port = 4445; |
|---|
| 73 |
} |
|---|
| 74 |
if(_global.server == undefined) { |
|---|
| 75 |
_global.sock.connect(null, _global.port); |
|---|
| 76 |
_global.server_print = "default"; |
|---|
| 77 |
} else { |
|---|
| 78 |
_global.sock.connect(_global.server, _global.port); |
|---|
| 79 |
_global.server_print = _global.server; |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
function handleConnect(connectionStatus){ |
|---|
| 84 |
|
|---|
| 85 |
if (connectionStatus) { |
|---|
| 86 |
colaEvento(0,"debug","Conectado! con contexto: "+context); |
|---|
| 87 |
_global.reconecta = 0; |
|---|
| 88 |
if(_global.enable_crypto==1) { |
|---|
| 89 |
envia_comando("contexto", 0, 0); |
|---|
| 90 |
} else { |
|---|
| 91 |
envia_comando("contexto", 1, 0); |
|---|
| 92 |
} |
|---|
| 93 |
if(restrict != undefined) { |
|---|
| 94 |
envia_comando("restrict",restrict,0); |
|---|
| 95 |
} |
|---|
| 96 |
} else { |
|---|
| 97 |
colaEvento(0,"debug","No pude conectar!"); |
|---|
| 98 |
_global.reconecta = 1; |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
function handleXML(doc){ |
|---|
| 103 |
var e = doc.firstChild; |
|---|
| 104 |
if (e != null) { |
|---|
| 105 |
if (e.nodeName == "response") { |
|---|
| 106 |
var numeroboton = e.attributes.btn; // btn is the button number |
|---|
| 107 |
var comando = e.attributes.cmd; |
|---|
| 108 |
var textofinal = e.attributes.data; |
|---|
| 109 |
|
|---|
| 110 |
if (_global.key != undefined) { |
|---|
| 111 |
if(_global.enable_crypto == 1) { |
|---|
| 112 |
comando = decrypt(comando, _global.key); |
|---|
| 113 |
if (textofinal.length > 0) { |
|---|
| 114 |
textofinal = decrypt(textofinal, _global.key); |
|---|
| 115 |
} |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
var botonparte = numeroboton.split("@"); |
|---|
| 121 |
var boton_numero = botonparte[0]; |
|---|
| 122 |
var boton_contexto = botonparte[1]; |
|---|
| 123 |
var timernumber = 0; |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
if (boton_contexto == undefined) { |
|---|
| 127 |
boton_contexto = ""; |
|---|
| 128 |
} |
|---|
| 129 |
if (_root.context == undefined) { |
|---|
| 130 |
_root.context = ""; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
if (comando == "key") { |
|---|
| 135 |
_global.key = textofinal; |
|---|
| 136 |
return; |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
if (comando == "restrict") { |
|---|
| 140 |
_global.restrict = numeroboton; |
|---|
| 141 |
_global.mybutton = numeroboton; |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
if (comando == "version") { |
|---|
| 145 |
if(textofinal != _global.swfversion) |
|---|
| 146 |
{ |
|---|
| 147 |
_global.statusline=vr.version_mismatch; |
|---|
| 148 |
} else { |
|---|
| 149 |
_global.statusline=""; |
|---|
| 150 |
} |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
if (_root.context == boton_contexto) { |
|---|
| 154 |
if(_global.restrict != undefined) { |
|---|
| 155 |
if(_global.restrict == boton_numero) { |
|---|
| 156 |
colaEvento(boton_numero,comando,textofinal); |
|---|
| 157 |
} |
|---|
| 158 |
} else { |
|---|
| 159 |
colaEvento(boton_numero,comando,textofinal); |
|---|
| 160 |
} |
|---|
| 161 |
} |
|---|
| 162 |
// endif root.context |
|---|
| 163 |
} |
|---|
| 164 |
// endif == response |
|---|
| 165 |
} |
|---|
| 166 |
// endiff e != null |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
function colaEvento(boton_numero,comando,textofinal) { |
|---|
| 170 |
|
|---|
| 171 |
if(_global.VersionFlash == "MAC") { |
|---|
| 172 |
// GetURL method for MAC |
|---|
| 173 |
jsQueue.push("javascript: docommand('"+boton_numero+"','"+comando+"','"+textofinal+"')"); |
|---|
| 174 |
} else { |
|---|
| 175 |
// FSCommand method for anything else |
|---|
| 176 |
jsQueue.push("newevent;"+boton_numero+"|"+comando+"|"+textofinal); |
|---|
| 177 |
} |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
function handleDisconnect(){ |
|---|
| 182 |
delete _global.key; |
|---|
| 183 |
_global.reconecta = 1; |
|---|
| 184 |
colaEvento(0,"debug","Attempt reconnection"); |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
Inicia_Variables = function () { |
|---|
| 189 |
_global.jsQueue = new Array(); |
|---|
| 190 |
var flashVersion = System.capabilities.version; |
|---|
| 191 |
var datos = flashVersion.split(" "); |
|---|
| 192 |
_global.VersionFlash = datos[0]; |
|---|
| 193 |
_global.server = vr.server; |
|---|
| 194 |
_global.port = vr.port; |
|---|
| 195 |
_global.enable_crypto = Number(vr.enable_crypto); |
|---|
| 196 |
if (isNaN(_global.enable_crypto)) { |
|---|
| 197 |
_global.enable_crypto=0; |
|---|
| 198 |
} else { |
|---|
| 199 |
if(_global.enable_crypto != 0) { |
|---|
| 200 |
_global.enable_crypto = 1; |
|---|
| 201 |
} |
|---|
| 202 |
} |
|---|
| 203 |
}; |
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
recarga = function () { |
|---|
| 207 |
if(_global.restart == 1) { |
|---|
| 208 |
// Send command to restart Asterisk |
|---|
| 209 |
envia_comando("restart","1","1"); |
|---|
| 210 |
} else { |
|---|
| 211 |
// Reloads FLASH client |
|---|
| 212 |
delete _global.key; |
|---|
| 213 |
var incontext = context; |
|---|
| 214 |
var inbutton = mybutton; |
|---|
| 215 |
var inrestrict = _global.restrict; |
|---|
| 216 |
var indial = dial; |
|---|
| 217 |
var innohighlight = nohighlight; |
|---|
| 218 |
for (var a in _root) { |
|---|
| 219 |
if (typeof (_root[a]) == "object") { |
|---|
| 220 |
removeMovieClip(_root[a]); |
|---|
| 221 |
} |
|---|
| 222 |
if (typeof (_root[a]) == "movieclip") { |
|---|
| 223 |
removeMovieClip(_root[a]); |
|---|
| 224 |
} |
|---|
| 225 |
} |
|---|
| 226 |
_global.context = incontext; |
|---|
| 227 |
_global.mybutton = inbutton; |
|---|
| 228 |
_global.restrict = inrestrict; |
|---|
| 229 |
_global.dial = indial; |
|---|
| 230 |
_global.nohighlight = inhighlight; |
|---|
| 231 |
stop(); |
|---|
| 232 |
gotoAndPlay(1); |
|---|
| 233 |
} |
|---|
| 234 |
}; |
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
_root.onEnterFrame = function() { |
|---|
| 238 |
|
|---|
| 239 |
if(_global.jsQueue.length>0) { |
|---|
| 240 |
if(_global.VersionFlash == "MAC") { |
|---|
| 241 |
getURL(jsQueue.shift()); |
|---|
| 242 |
} else { |
|---|
| 243 |
var partes = jsQueue.shift().split(";"); |
|---|
| 244 |
var comando=partes[0]; |
|---|
| 245 |
var params=partes[1]; |
|---|
| 246 |
getURL("FSCommand:"+comando,params); |
|---|
| 247 |
} |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
}; |
|---|
| 251 |
|
|---|
| 252 |
Timers = function () { |
|---|
| 253 |
|
|---|
| 254 |
if (_global.reconecta == 1) { |
|---|
| 255 |
delete setInterval; |
|---|
| 256 |
delete _global.key; |
|---|
| 257 |
recarga(); |
|---|
| 258 |
return; |
|---|
| 259 |
} |
|---|
| 260 |
}; |
|---|
| 261 |
|
|---|
| 262 |
setInterval(Timers, 10000); |
|---|
| 263 |
|
|---|
| 264 |
function ExtraeNumeroClip(name) { |
|---|
| 265 |
var destino = ""; |
|---|
| 266 |
name = name._name; |
|---|
| 267 |
for (var s = 0; s<name.length; s++) { |
|---|
| 268 |
var c = name.charAt(s); |
|---|
| 269 |
if (c<"0" || c>"9") { |
|---|
| 270 |
} else { |
|---|
| 271 |
destino = destino+""+c; |
|---|
| 272 |
} |
|---|
| 273 |
if (c == ".") { |
|---|
| 274 |
destino = ""; |
|---|
| 275 |
} |
|---|
| 276 |
} |
|---|
| 277 |
return destino; |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
envia_comando = function (comando, origen, destino) { |
|---|
| 281 |
if (comando != "bogus" && comando != "contexto" && comando != "restrict") { |
|---|
| 282 |
if (_global.restrict!=0) { |
|---|
| 283 |
if(comando == "cortar") { |
|---|
| 284 |
origen_number = ExtraeNumeroClip(origen); |
|---|
| 285 |
} else { |
|---|
| 286 |
origen_number = origen; |
|---|
| 287 |
} |
|---|
| 288 |
if(_global.restrict != undefined) { |
|---|
| 289 |
if (_global.restrict == origen_number ) { |
|---|
| 290 |
} else { |
|---|
| 291 |
return; |
|---|
| 292 |
} |
|---|
| 293 |
} |
|---|
| 294 |
} |
|---|
| 295 |
} |
|---|
| 296 |
message = new XML(); |
|---|
| 297 |
message_data = message.createElement("msg"); |
|---|
| 298 |
if (_root.context.length>0) { |
|---|
| 299 |
agrega_contexto = "@"+context; |
|---|
| 300 |
} |
|---|
| 301 |
if (agrega_contexto == undefined) { |
|---|
| 302 |
agrega_contexto = ""; |
|---|
| 303 |
} |
|---|
| 304 |
if (_level0.claveinput.secret == undefined) { |
|---|
| 305 |
_level0.claveinput.secret = ""; |
|---|
| 306 |
} |
|---|
| 307 |
if (_global.claveingresada == undefined && ( comando != "contexto" && comando != "bogus" && comando != "dial" && comando != "restrict")) { |
|---|
| 308 |
_root.codebox._visible = true; |
|---|
| 309 |
Selection.setFocus(_root.codebox.claveform); |
|---|
| 310 |
_root.codebox.swapDepths(_root.log); |
|---|
| 311 |
return; |
|---|
| 312 |
} |
|---|
| 313 |
// var clave=_level0.claveinput.secret+_global.key; |
|---|
| 314 |
var clave = _global.claveingresada+_global.key; |
|---|
| 315 |
var md5clave = ""; |
|---|
| 316 |
var md5clave = calcMD5(clave); |
|---|
| 317 |
if (comando == "contexto" || comando == "restrict") { |
|---|
| 318 |
md5clave = ""; |
|---|
| 319 |
} |
|---|
| 320 |
message_data.attributes.data = origen+agrega_contexto+"|"+comando+destino+"|"+md5clave; |
|---|
| 321 |
message.appendChild(message_data); |
|---|
| 322 |
_global.sock.send(message); |
|---|
| 323 |
var clave = ""; |
|---|
| 324 |
}; |
|---|
| 325 |
|
|---|
| 326 |
function LTrim(str) { |
|---|
| 327 |
var whitespace = new String(" \t\n\r"); |
|---|
| 328 |
var s = new String(str); |
|---|
| 329 |
if (whitespace.indexOf(s.charAt(0)) != -1) { |
|---|
| 330 |
var j = 0, i = s.length; |
|---|
| 331 |
while (j<i && whitespace.indexOf(s.charAt(j)) != -1) { |
|---|
| 332 |
j++; |
|---|
| 333 |
} |
|---|
| 334 |
s = s.substring(j, i); |
|---|
| 335 |
} |
|---|
| 336 |
return s; |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
function RTrim(str) { |
|---|
| 340 |
var whitespace = new String(" \t\n\r"); |
|---|
| 341 |
var s = new String(str); |
|---|
| 342 |
if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { |
|---|
| 343 |
var i = s.length-1; |
|---|
| 344 |
// Get length of string |
|---|
| 345 |
while (i>=0 && whitespace.indexOf(s.charAt(i)) != -1) { |
|---|
| 346 |
i--; |
|---|
| 347 |
} |
|---|
| 348 |
s = s.substring(0, i+1); |
|---|
| 349 |
} |
|---|
| 350 |
return s; |
|---|
| 351 |
} |
|---|
| 352 |
|
|---|
| 353 |
function Trim(str) { |
|---|
| 354 |
return RTrim(LTrim(str)); |
|---|
| 355 |
} |
|---|
| 356 |
|
|---|
| 357 |
function setDND(obj, item) { |
|---|
| 358 |
var nroboton = ExtraeNumeroClip(obj); |
|---|
| 359 |
envia_comando("dnd", nroboton, nroboton); |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
function genera_selecttimeout() { |
|---|
| 363 |
|
|---|
| 364 |
_global.positionselect = 0; |
|---|
| 365 |
test = attachMovie("option","optionselected", getNextHighestDepth(), {_x:800, _y:6}); |
|---|
| 366 |
test._visible = true; |
|---|
| 367 |
test.legend = "No timeout"; |
|---|
| 368 |
|
|---|
| 369 |
test.onPress = function() { |
|---|
| 370 |
_root.despliega_select(); |
|---|
| 371 |
}; |
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
for (a=0; a<5; a++) { |
|---|
| 375 |
var b=a+1; |
|---|
| 376 |
if (_global.opcionesTimeout[a] != undefined) { |
|---|
| 377 |
|
|---|
| 378 |
testa = attachMovie("option","option"+a, getNextHighestDepth(), {_x:800, _y:(b*22)+6}); |
|---|
| 379 |
testa.legend = _global.opcionesTimeout[a]; |
|---|
| 380 |
testa._visible = false; |
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
testa.onRollOver = function() { |
|---|
| 384 |
this.legend = "* "+this.legend; |
|---|
| 385 |
}; |
|---|
| 386 |
|
|---|
| 387 |
testa.onRollOut = function() { |
|---|
| 388 |
this.legend = this.legend.substring(2, this.legend.length); |
|---|
| 389 |
}; |
|---|
| 390 |
|
|---|
| 391 |
testa.onPress = function() { |
|---|
| 392 |
this.legend = this.legend.substring(2, this.legend.length); |
|---|
| 393 |
var posicion = ExtraeNumeroClip(this); |
|---|
| 394 |
_global.timeout_value = _global.opcionesTimeoutSecs[posicion]; |
|---|
| 395 |
_root.muestra_selecttimeout(0); |
|---|
| 396 |
_root.selectbox1.gotoAndStop(1); |
|---|
| 397 |
_root.optionselected._visible=true; |
|---|
| 398 |
_root.optionselected.legend = this.legend; |
|---|
| 399 |
}; |
|---|
| 400 |
} |
|---|
| 401 |
} |
|---|
| 402 |
}; |
|---|
| 403 |
|
|---|
| 404 |
function muestra_selecttimeout(value) { |
|---|
| 405 |
for (a=0; a<5; a++) { |
|---|
| 406 |
var v = eval("_root.option"+a); |
|---|
| 407 |
if(value) { |
|---|
| 408 |
v._visible = true; |
|---|
| 409 |
} else { |
|---|
| 410 |
v._visible = false; |
|---|
| 411 |
} |
|---|
| 412 |
} |
|---|
| 413 |
}; |
|---|
| 414 |
|
|---|
| 415 |
function despliega_select() { |
|---|
| 416 |
_root.optionselected._visible=false; |
|---|
| 417 |
_root.selectbox1.gotoAndStop(2); |
|---|
| 418 |
_root.muestra_selecttimeout(1); |
|---|
| 419 |
|
|---|
| 420 |
}; |
|---|
| 421 |
|
|---|
| 422 |
function base64_decode(opString) { |
|---|
| 423 |
if ( opString == undefined ) { |
|---|
| 424 |
return; |
|---|
| 425 |
} |
|---|
| 426 |
var str = opString; |
|---|
| 427 |
var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
|---|
| 428 |
var bits, bit1, bit2, bit3, bit4, i = 0; |
|---|
| 429 |
var decOut = ""; |
|---|
| 430 |
for (i=0; i<str.length; i += 4) { |
|---|
| 431 |
bit1 = (base64s.indexOf(str.charAt(i)) & 0xff) << 18 ; |
|---|
| 432 |
bit2 = (base64s.indexOf(str.charAt(i+1)) & 0xff) << 12 ; |
|---|
| 433 |
bit3 = (base64s.indexOf(str.charAt(i+2)) & 0xff) << 6 ; |
|---|
| 434 |
bit4 = (base64s.indexOf(str.charAt(i+3)) & 0xff); |
|---|
| 435 |
bits = bit1 | bit2 | bit3 | bit4; |
|---|
| 436 |
decOut += String.fromCharCode((bits & 0xff0000) >> 16, (bits & 0xff00) >> 8, bits & 0xff); |
|---|
| 437 |
} |
|---|
| 438 |
if (str.charCodeAt(i-2) == 61) { |
|---|
| 439 |
return decOut.substring(0, decOut.length-2); |
|---|
| 440 |
} else if (str.charCodeAt(i-1) == 61) { |
|---|
| 441 |
return decOut.substring(0, decOut.length-1); |
|---|
| 442 |
} else { |
|---|
| 443 |
return decOut.substring(0, decOut.length); |
|---|
| 444 |
} |
|---|
| 445 |
}; |
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
// MD5 ROUTINE |
|---|
| 450 |
/* |
|---|
| 451 |
* Convert a 32-bit number to a hex string with ls-byte first |
|---|
| 452 |
*/ |
|---|
| 453 |
var hex_chr = "0123456789abcdef"; |
|---|
| 454 |
// |
|---|
| 455 |
// somehow the expression (bitAND(b, c) | bitAND((~b), d)) didn't return coorect results on Mac |
|---|
| 456 |
// for: |
|---|
| 457 |
// b&c = a8a20450, ((~b)&d) = 0101c88b, (bitAND(b, c) | bitAND((~b), d)) = a8a20450 <-- !!! |
|---|
| 458 |
// looks like the OR is not executed at all. |
|---|
| 459 |
// |
|---|
| 460 |
// let's try to trick the P-code compiler into working with us... Prayer beads are GO! |
|---|
| 461 |
// |
|---|
| 462 |
function bitOR(a, b) { |
|---|
| 463 |
var lsb = (a & 0x1) | (b & 0x1); |
|---|
| 464 |
var msb31 = (a >>> 1) | (b >>> 1); |
|---|
| 465 |
return (msb31 << 1) | lsb; |
|---|
| 466 |
} |
|---|
| 467 |
// |
|---|
| 468 |
// will bitXOR be the only one working...? |
|---|
| 469 |
// Nope. XOR fails too if values with bit31 set are XORed. |
|---|
| 470 |
// |
|---|
| 471 |
// Note however that OR (and AND and XOR?!) works alright for the statement |
|---|
| 472 |
// (msb31 << 1) | lsb |
|---|
| 473 |
// even if the result of the left-shift operation has bit 31 set. |
|---|
| 474 |
// So there might be an extra condition here (Guessmode turned on): |
|---|
| 475 |
// Mac Flash fails (OR, AND and XOR) if either one of the input operands has bit31 set |
|---|
| 476 |
// *and* both operands have one or more bits both set to 1. In other words: when both |
|---|
| 477 |
// input bit-patterns 'overlap'. |
|---|
| 478 |
// Stuff to munch on for the MM guys, I guess... |
|---|
| 479 |
// |
|---|
| 480 |
function bitXOR(a, b) { |
|---|
| 481 |
var lsb = (a & 0x1) ^ (b & 0x1); |
|---|
| 482 |
var msb31 = (a >>> 1) ^ (b >>> 1); |
|---|
| 483 |
return (msb31 << 1) | lsb; |
|---|
| 484 |
} |
|---|
| 485 |
// |
|---|
| 486 |
// bitwise AND for 32-bit integers. This uses 31 + 1-bit operations internally |
|---|
| 487 |
// to work around bug in some AS interpreters. (Mac Flash!) |
|---|
| 488 |
// |
|---|
| 489 |
function bitAND(a, b) { |
|---|
| 490 |
var lsb = (a & 0x1) & (b & 0x1); |
|---|
| 491 |
var msb31 = (a >>> 1) & (b >>> 1); |
|---|
| 492 |
return (msb31 << 1) | lsb; |
|---|
| 493 |
// return (a & b); |
|---|
| 494 |
} |
|---|
| 495 |
// |
|---|
| 496 |
// Add integers, wrapping at 2^32. This uses 16-bit operations internally |
|---|
| 497 |
// to work around bugs in some AS interpreters. (Mac Flash!) |
|---|
| 498 |
// |
|---|
| 499 |
function addme(x, y) { |
|---|
| 500 |
var lsw = (x & 0xFFFF)+(y & 0xFFFF); |
|---|
| 501 |
var msw = (x >> 16)+(y >> 16)+(lsw >> 16); |
|---|
| 502 |
return (msw << 16) | (lsw & 0xFFFF); |
|---|
| 503 |
} |
|---|
| 504 |
function rhex(num) { |
|---|
| 505 |
str = ""; |
|---|
| 506 |
for (j=0; j<=3; j++) { |
|---|
| 507 |
str += hex_chr.charAt((num >> (j*8+4)) & 0x0F)+hex_chr.charAt((num >> (j*8)) & 0x0F); |
|---|
| 508 |
} |
|---|
| 509 |
return str; |
|---|
| 510 |
} |
|---|
| 511 |
/* |
|---|
| 512 |
* Convert a string to a sequence of 16-word blocks, stored as an array. |
|---|
| 513 |
* Append padding bits and the length, as described in the MD5 standard. |
|---|
| 514 |
*/ |
|---|
| 515 |
function str2blks_MD5(str) { |
|---|
| 516 |
nblk = ((str.length+8) >> 6)+1; |
|---|
| 517 |
// 1 + (len + 8)/64 |
|---|
| 518 |
blks = new Array(nblk*16); |
|---|
| 519 |
for (i=0; i<nblk*16; i++) { |
|---|
| 520 |
blks[i] = 0; |
|---|
| 521 |
} |
|---|
| 522 |
/* |
|---|
| 523 |
Input: |
|---|
| 524 |
|
|---|
| 525 |
'willi' without the quotes. |
|---|
| 526 |
|
|---|
| 527 |
trace() Output on Intel (and MAC now?): |
|---|
| 528 |
|
|---|
| 529 |
see TXT files: *.Output.txt |
|---|
| 530 |
|
|---|
| 531 |
*/ |
|---|
| 532 |
for (i=0; i<str.length; i++) { |
|---|
| 533 |
blks[i >> 2] |= str.charCodeAt(i) << (((str.length*8+i)%4)*8); |
|---|
| 534 |
} |
|---|
| 535 |
blks[i >> 2] |= 0x80 << (((str.length*8+i)%4)*8); |
|---|
| 536 |
var l = str.length*8; |
|---|
| 537 |
blks[nblk*16-2] = (l & 0xFF); |
|---|
| 538 |
blks[nblk*16-2] |= ((l >>> 8) & 0xFF) << 8; |
|---|
| 539 |
blks[nblk*16-2] |= ((l >>> 16) & 0xFF) << 16; |
|---|
| 540 |
blks[nblk*16-2] |= ((l >>> 24) & 0xFF) << 24; |
|---|
| 541 |
return blks; |
|---|
| 542 |
} |
|---|
| 543 |
/* |
|---|
| 544 |
* Bitwise rotate a 32-bit number to the left |
|---|
| 545 |
*/ |
|---|
| 546 |
function rol(num, cnt) { |
|---|
| 547 |
return (num << cnt) | (num >>> (32-cnt)); |
|---|
| 548 |
} |
|---|
| 549 |
/* |
|---|
| 550 |
* These functions implement the basic operation for each round of the |
|---|
| 551 |
* algorithm. |
|---|
| 552 |
*/ |
|---|
| 553 |
function cmn(q, a, b, x, s, t) { |
|---|
| 554 |
return addme(rol((addme(addme(a, q), addme(x, t))), s), b); |
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
function ff(a, b, c, d, x, s, t) { |
|---|
| 558 |
return cmn(bitOR(bitAND(b, c), bitAND((~b), d)), a, b, x, s, t); |
|---|
| 559 |
} |
|---|
| 560 |
|
|---|
| 561 |
function gg(a, b, c, d, x, s, t) { |
|---|
| 562 |
return cmn(bitOR(bitAND(b, d), bitAND(c, (~d))), a, b, x, s, t); |
|---|
| 563 |
} |
|---|
| 564 |
|
|---|
| 565 |
function hh(a, b, c, d, x, s, t) { |
|---|
| 566 |
return cmn(bitXOR(bitXOR(b, c), d), a, b, x, s, t); |
|---|
| 567 |
} |
|---|
| 568 |
|
|---|
| 569 |
function ii(a, b, c, d, x, s, t) { |
|---|
| 570 |
return cmn(bitXOR(c, bitOR(b, (~d))), a, b, x, s, t); |
|---|
| 571 |
} |
|---|
| 572 |
/* |
|---|
| 573 |
* Take a string and return the hex representation of its MD5. |
|---|
| 574 |
*/ |
|---|
| 575 |
function calcMD5(str) { |
|---|
| 576 |
x = str2blks_MD5(str); |
|---|
| 577 |
a = 1732584193; |
|---|
| 578 |
b = -271733879; |
|---|
| 579 |
c = -1732584194; |
|---|
| 580 |
d = 271733878; |
|---|
| 581 |
var step; |
|---|
| 582 |
for (i=0; i<x.length; i += 16) { |
|---|
| 583 |
olda = a; |
|---|
| 584 |
oldb = b; |
|---|
| 585 |
oldc = c; |
|---|
| 586 |
oldd = d; |
|---|
| 587 |
step = 0; |
|---|
| 588 |
a = ff(a, b, c, d, x[i+0], 7, -680876936); |
|---|
| 589 |
d = ff(d, a, b, c, x[i+1], 12, -389564586); |
|---|
| 590 |
c = ff(c, d, a, b, x[i+2], 17, 606105819); |
|---|
| 591 |
b = ff(b, c, d, a, x[i+3], 22, -1044525330); |
|---|
| 592 |
a = ff(a, b, c, d, x[i+4], 7, -176418897); |
|---|
| 593 |
d = ff(d, a, b, c, x[i+5], 12, 1200080426); |
|---|
| 594 |
c = ff(c, d, a, b, x[i+6], 17, -1473231341); |
|---|
| 595 |
b = ff(b, c, d, a, x[i+7], 22, -45705983); |
|---|
| 596 |
a = ff(a, b, c, d, x[i+8], 7, 1770035416); |
|---|
| 597 |
d = ff(d, a, b, c, x[i+9], 12, -1958414417); |
|---|
| 598 |
c = ff(c, d, a, b, x[i+10], 17, -42063); |
|---|
| 599 |
b = ff(b, c, d, a, x[i+11], 22, -1990404162); |
|---|
| 600 |
a = ff(a, b, c, d, x[i+12], 7, 1804603682); |
|---|
| 601 |
d = ff(d, a, b, c, x[i+13], 12, -40341101); |
|---|
| 602 |
c = ff(c, d, a, b, x[i+14], 17, -1502002290); |
|---|
| 603 |
b = ff(b, c, d, a, x[i+15], 22, 1236535329); |
|---|
| 604 |
a = gg(a, b, c, d, x[i+1], 5, -165796510); |
|---|
| 605 |
d = gg(d, a, b, c, x[i+6], 9, -1069501632); |
|---|
| 606 |
c = gg(c, d, a, b, x[i+11], 14, 643717713); |
|---|
| 607 |
b = gg(b, c, d, a, x[i+0], 20, -373897302); |
|---|
| 608 |
a = gg(a, b, c, d, x[i+5], 5, -701558691); |
|---|
| 609 |
d = gg(d, a, b, c, x[i+10], 9, 38016083); |
|---|
| 610 |
c = gg(c, d, a, b, x[i+15], 14, -660478335); |
|---|
| 611 |
b = gg(b, c, d, a, x[i+4], 20, -405537848); |
|---|
| 612 |
a = gg(a, b, c, d, x[i+9], 5, 568446438); |
|---|
| 613 |
d = gg(d, a, b, c, x[i+14], 9, -1019803690); |
|---|
| 614 |
c = gg(c, d, a, b, x[i+3], 14, -187363961); |
|---|
| 615 |
b = gg(b, c, d, a, x[i+8], 20, 1163531501); |
|---|
| 616 |
a = gg(a, b, c, d, x[i+13], 5, -1444681467); |
|---|
| 617 |
d = gg(d, a, b, c, x[i+2], 9, -51403784); |
|---|
| 618 |
c = gg(c, d, a, b, x[i+7], 14, 1735328473); |
|---|
| 619 |
b = gg(b, c, d, a, x[i+12], 20, -1926607734); |
|---|
| 620 |
a = hh(a, b, c, d, x[i+5], 4, -378558); |
|---|
| 621 |
d = hh(d, a, b, c, x[i+8], 11, -2022574463); |
|---|
| 622 |
c = hh(c, d, a, b, x[i+11], 16, 1839030562); |
|---|
| 623 |
b = hh(b, c, d, a, x[i+14], 23, -35309556); |
|---|
| 624 |
a = hh(a, b, c, d, x[i+1], 4, -1530992060); |
|---|
| 625 |
d = hh(d, a, b, c, x[i+4], 11, 1272893353); |
|---|
| 626 |
c = hh(c, d, a, b, x[i+7], 16, -155497632); |
|---|
| 627 |
b = hh(b, c, d, a, x[i+10], 23, -1094730640); |
|---|
| 628 |
a = hh(a, b, c, d, x[i+13], 4, 681279174); |
|---|
| 629 |
d = hh(d, a, b, c, x[i+0], 11, -358537222); |
|---|
| 630 |
c = hh(c, d, a, b, x[i+3], 16, -722521979); |
|---|
| 631 |
b = hh(b, c, d, a, x[i+6], 23, 76029189); |
|---|
| 632 |
a = hh(a, b, c, d, x[i+9], 4, -640364487); |
|---|
| 633 |
d = hh(d, a, b, c, x[i+12], 11, -421815835); |
|---|
| 634 |
c = hh(c, d, a, b, x[i+15], 16, 530742520); |
|---|
| 635 |
b = hh(b, c, d, a, x[i+2], 23, -995338651); |
|---|
| 636 |
a = ii(a, b, c, d, x[i+0], 6, -198630844); |
|---|
| 637 |
d = ii(d, a, b, c, x[i+7], 10, 1126891415); |
|---|
| 638 |
c = ii(c, d, a, b, x[i+14], 15, -1416354905); |
|---|
| 639 |
b = ii(b, c, d, a, x[i+5], 21, -57434055); |
|---|
| 640 |
a = ii(a, b, c, d, x[i+12], 6, 1700485571); |
|---|
| 641 |
d = ii(d, a, b, c, x[i+3], 10, -1894986606); |
|---|
| 642 |
c = ii(c, d, a, b, x[i+10], 15, -1051523); |
|---|
| 643 |
b = ii(b, c, d, a, x[i+1], 21, -2054922799); |
|---|
| 644 |
a = ii(a, b, c, d, x[i+8], 6, 1873313359); |
|---|
| 645 |
d = ii(d, a, b, c, x[i+15], 10, -30611744); |
|---|
| 646 |
c = ii(c, d, a, b, x[i+6], 15, -1560198380); |
|---|
| 647 |
b = ii(b, c, d, a, x[i+13], 21, 1309151649); |
|---|
| 648 |
a = ii(a, b, c, d, x[i+4], 6, -145523070); |
|---|
| 649 |
d = ii(d, a, b, c, x[i+11], 10, -1120210379); |
|---|
| 650 |
c = ii(c, d, a, b, x[i+2], 15, 718787259); |
|---|
| 651 |
b = ii(b, c, d, a, x[i+9], 21, -343485551); |
|---|
| 652 |
a = addme(a, olda); |
|---|
| 653 |
b = addme(b, oldb); |
|---|
| 654 |
c = addme(c, oldc); |
|---|
| 655 |
d = addme(d, oldd); |
|---|
| 656 |
} |
|---|
| 657 |
return rhex(a)+rhex(b)+rhex(c)+rhex(d); |
|---|
| 658 |
} |
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
// TEA2 |
|---|
| 662 |
|
|---|
| 663 |
c2b = new Object(); |
|---|
| 664 |
c2b['\\000'] = 0; |
|---|
| 665 |
c2b["\001"] = 1; |
|---|
| 666 |
c2b["\002"] = 2; |
|---|
| 667 |
c2b["\003"] = 3; |
|---|
| 668 |
c2b["\004"] = 4; |
|---|
| 669 |
c2b["\005"] = 5; |
|---|
| 670 |
c2b["\006"] = 6; |
|---|
| 671 |
c2b["\007"] = 7; |
|---|
| 672 |
c2b["\010"] = 8; |
|---|
| 673 |
c2b["\011"] = 9; |
|---|
| 674 |
c2b["\012"] = 10; |
|---|
| 675 |
c2b["\013"] = 11; |
|---|
| 676 |
c2b["\014"] = 12; |
|---|
| 677 |
c2b["\015"] = 13; |
|---|
| 678 |
c2b["\016"] = 14; |
|---|
| 679 |
c2b["\017"] = 15; |
|---|
| 680 |
c2b["\020"] = 16; |
|---|
| 681 |
c2b["\021"] = 17; |
|---|
| 682 |
c2b["\022"] = 18; |
|---|
| 683 |
c2b["\023"] = 19; |
|---|
| 684 |
c2b["\024"] = 20; |
|---|
| 685 |
c2b["\025"] = 21; |
|---|
| 686 |
c2b["\026"] = 22; |
|---|
| 687 |
c2b["\027"] = 23; |
|---|
| 688 |
c2b["\030"] = 24; |
|---|
| 689 |
c2b["\031"] = 25; |
|---|
| 690 |
c2b["\032"] = 26; |
|---|
| 691 |
c2b["\033"] = 27; |
|---|
| 692 |
c2b["\034"] = 28; |
|---|
| 693 |
c2b["\035"] = 29; |
|---|
| 694 |
c2b["\036"] = 30; |
|---|
| 695 |
c2b["\037"] = 31; |
|---|
| 696 |
c2b["\040"] = 32; |
|---|
| 697 |
c2b["\041"] = 33; |
|---|
| 698 |
c2b['\042'] = 34; |
|---|
| 699 |
c2b["\043"] = 35; |
|---|
| 700 |
c2b["\044"] = 36; |
|---|
| 701 |
c2b["\045"] = 37; |
|---|
| 702 |
c2b["\046"] = 38; |
|---|
| 703 |
c2b["\047"] = 39; |
|---|
| 704 |
c2b["\050"] = 40; |
|---|
| 705 |
c2b["\051"] = 41; |
|---|
| 706 |
c2b["\052"] = 42; |
|---|
| 707 |
c2b["\053"] = 43; |
|---|
| 708 |
c2b["\054"] = 44; |
|---|
| 709 |
c2b["\055"] = 45; |
|---|
| 710 |
c2b["\056"] = 46; |
|---|
| 711 |
c2b["\057"] = 47; |
|---|
| 712 |
c2b["\060"] = 48; |
|---|
| 713 |
c2b["\061"] = 49; |
|---|
| 714 |
c2b["\062"] = 50; |
|---|
| 715 |
c2b["\063"] = 51; |
|---|
| 716 |
c2b["\064"] = 52; |
|---|
| 717 |
c2b["\065"] = 53; |
|---|
| 718 |
c2b["\066"] = 54; |
|---|
| 719 |
c2b["\067"] = 55; |
|---|
| 720 |
c2b["\070"] = 56; |
|---|
| 721 |
c2b["\071"] = 57; |
|---|
| 722 |
c2b["\072"] = 58; |
|---|
| 723 |
c2b["\073"] = 59; |
|---|
| 724 |
c2b["\074"] = 60; |
|---|
| 725 |
c2b["\075"] = 61; |
|---|
| 726 |
c2b["\076"] = 62; |
|---|
| 727 |
c2b["\077"] = 63; |
|---|
| 728 |
c2b["\100"] = 64; |
|---|
| 729 |
c2b["\101"] = 65; |
|---|
| 730 |
c2b["\102"] = 66; |
|---|
| 731 |
c2b["\103"] = 67; |
|---|
| 732 |
c2b["\104"] = 68; |
|---|
| 733 |
c2b["\105"] = 69; |
|---|
| 734 |
c2b["\106"] = 70; |
|---|
| 735 |
c2b["\107"] = 71; |
|---|
| 736 |
c2b["\110"] = 72; |
|---|
| 737 |
c2b["\111"] = 73; |
|---|
| 738 |
c2b["\112"] = 74; |
|---|
| 739 |
c2b["\113"] = 75; |
|---|
| 740 |
c2b["\114"] = 76; |
|---|
| 741 |
c2b["\115"] = 77; |
|---|
| 742 |
c2b["\116"] = 78; |
|---|
| 743 |
c2b["\117"] = 79; |
|---|
| 744 |
c2b["\120"] = 80; |
|---|
| 745 |
c2b["\121"] = 81; |
|---|
| 746 |
c2b["\122"] = 82; |
|---|
| 747 |
c2b["\123"] = 83; |
|---|
| 748 |
c2b["\124"] = 84; |
|---|
| 749 |
c2b["\125"] = 85; |
|---|
| 750 |
c2b["\126"] = 86; |
|---|
| 751 |
c2b["\127"] = 87; |
|---|
| 752 |
c2b["\130"] = 88; |
|---|
| 753 |
c2b["\131"] = 89; |
|---|
| 754 |
c2b["\132"] = 90; |
|---|
| 755 |
c2b["\133"] = 91; |
|---|
| 756 |
var pepe="\"; |
|---|
| 757 |
c2b[pepe] = 92; |
|---|
| 758 |
var pepe="]"; |
|---|
| 759 |
c2b[pepe] = 93; |
|---|
| 760 |
c2b["\136"] = 94; |
|---|
| 761 |
c2b["\137"] = 95; |
|---|
| 762 |
c2b["\140"] = 96; |
|---|
| 763 |
c2b["\141"] = 97; |
|---|
| 764 |
c2b["\142"] = 98; |
|---|
| 765 |
c2b["\143"] = 99; |
|---|
| 766 |
c2b["\144"] = 100; |
|---|
| 767 |
c2b["\145"] = 101; |
|---|
| 768 |
c2b["\146"] = 102; |
|---|
| 769 |
c2b["\147"] = 103; |
|---|
| 770 |
c2b["\150"] = 104; |
|---|
| 771 |
c2b["\151"] = 105; |
|---|
| 772 |
c2b["\152"] = 106; |
|---|
| 773 |
c2b["\153"] = 107; |
|---|
| 774 |
c2b["\154"] = 108; |
|---|
| 775 |
c2b["\155"] = 109; |
|---|
| 776 |
c2b["\156"] = 110; |
|---|
| 777 |
c2b["\157"] = 111; |
|---|
| 778 |
c2b["\160"] = 112; |
|---|
| 779 |
c2b["\161"] = 113; |
|---|
| 780 |
c2b["\162"] = 114; |
|---|
| 781 |
c2b["\163"] = 115; |
|---|
| 782 |
c2b["\164"] = 116; |
|---|
| 783 |
c2b["\165"] = 117; |
|---|
| 784 |
c2b["\166"] = 118; |
|---|
| 785 |
c2b["\167"] = 119; |
|---|
| 786 |
c2b["\170"] = 120; |
|---|
| 787 |
c2b["\171"] = 121; |
|---|
| 788 |
c2b["\172"] = 122; |
|---|
| 789 |
c2b["\173"] = 123; |
|---|
| 790 |
c2b["\174"] = 124; |
|---|
| 791 |
c2b["\175"] = 125; |
|---|
| 792 |
c2b["\176"] = 126; |
|---|
| 793 |
c2b["\177"] = 127; |
|---|
| 794 |
c2b["\200"] = 128; |
|---|
| 795 |
c2b["\201"] = 129; |
|---|
| 796 |
c2b["\202"] = 130; |
|---|
| 797 |
c2b["\203"] = 131; |
|---|
| 798 |
c2b["\204"] = 132; |
|---|
| 799 |
c2b["\205"] = 133; |
|---|
| 800 |
c2b["\206"] = 134; |
|---|
| 801 |
c2b["\207"] = 135; |
|---|
| 802 |
c2b["\210"] = 136; |
|---|
| 803 |
c2b["\211"] = 137; |
|---|
| 804 |
c2b["\212"] = 138; |
|---|
| 805 |
c2b["\213"] = 139; |
|---|
| 806 |
c2b["\214"] = 140; |
|---|
| 807 |
c2b["\215"] = 141; |
|---|
| 808 |
c2b["\216"] = 142; |
|---|
| 809 |
c2b["\217"] = 143; |
|---|
| 810 |
c2b["\220"] = 144; |
|---|
| 811 |
c2b["\221"] = 145; |
|---|
| 812 |
c2b["\222"] = 146; |
|---|
| 813 |
c2b["\223"] = 147; |
|---|
| 814 |
c2b["\224"] = 148; |
|---|
| 815 |
c2b["\225"] = 149; |
|---|
| 816 |
c2b["\226"] = 150; |
|---|
| 817 |
c2b["\227"] = 151; |
|---|
| 818 |
c2b["\230"] = 152; |
|---|
| 819 |
c2b["\231"] = 153; |
|---|
| 820 |
c2b["\232"] = 154; |
|---|
| 821 |
c2b["\233"] = 155; |
|---|
| 822 |
c2b["\234"] = 156; |
|---|
| 823 |
c2b["\235"] = 157; |
|---|
| 824 |
c2b["\236"] = 158; |
|---|
| 825 |
c2b["\237"] = 159; |
|---|
| 826 |
c2b["\240"] = 160; |
|---|
| 827 |
c2b["\241"] = 161; |
|---|
| 828 |
c2b["\242"] = 162; |
|---|
| 829 |
c2b["\243"] = 163; |
|---|
| 830 |
c2b["\244"] = 164; |
|---|
| 831 |
c2b["\245"] = 165; |
|---|
| 832 |
c2b["\246"] = 166; |
|---|
| 833 |
c2b["\247"] = 167; |
|---|
| 834 |
c2b["\250"] = 168; |
|---|
| 835 |
c2b["\251"] = 169; |
|---|
| 836 |
c2b["\252"] = 170; |
|---|
| 837 |
c2b["\253"] = 171; |
|---|
| 838 |
c2b["\254"] = 172; |
|---|
| 839 |
c2b["\255"] = 173; |
|---|
| 840 |
c2b["\256"] = 174; |
|---|
| 841 |
c2b["\257"] = 175; |
|---|
| 842 |
c2b["\260"] = 176; |
|---|
| 843 |
c2b["\261"] = 177; |
|---|
| 844 |
c2b["\262"] = 178; |
|---|
| 845 |
c2b["\263"] = 179; |
|---|
| 846 |
c2b["\264"] = 180; |
|---|
| 847 |
c2b["\265"] = 181; |
|---|
| 848 |
c2b["\266"] = 182; |
|---|
| 849 |
c2b["\267"] = 183; |
|---|
| 850 |
c2b["\270"] = 184 |
|---|