q = new Array();

q['q1'] = new Array('acbe10e69a72bafc917a09c173f8bdb6dadda85e');
q['q2'] = new Array('a407638ac0b0eff547c6ce5c8743ef65d34d8530');
q['q3'] = new Array('0287ef2dc7a6dbcaab8748e031659b6ded5c443c');
q['q4'] = new Array('4fc68b47baab54a44b537827ce335bd82581d9bb');
q['q5'] = new Array('49fbd9bcdf31a1def0e779535f0a51b4682faf9b');
q['q6'] = new Array('97df6ee4d80c58b95f39461723ddeaf350e3d2f1', '5cf6a87d4ba502b4cfcff28db11632026253432a');
q['q7'] = new Array('5a3509aa5b14e3ad298273936dbda304917d2911');
q['q8'] = new Array('77973d4492d47b122bc58eaaee36cd52eb00fad5');
q['q9'] = new Array('7550b672e162c224c309bdea5d48ca975081a904');
q['q10'] = new Array('3b49a099cb158e601c4379291a183633522b3639');
q['q11'] = new Array('424c980774a19a15e5cff0db96631030069ed638', '0c6b1705586998469722f78f7f6e83595196b03d');
q['q12'] = new Array('7c47a206a5fccd1aebbeb342ff6511a4d7f826ed');
q['q13'] = new Array('53d7151de9123845cd6d9b9cf9b0bcb1d7265b86');
q['q14'] = new Array('f3854546226b7079f1bc7d787dc8d7c2c864c3b5');
q['q15'] = new Array('04370e04e1e8bae732fc601068a5df5f1b9ad9d2');
q['q16'] = new Array('ed9bb3fe3e8f6f97877e957b8e3db19c81a0c6e7');
q['q17'] = new Array('3a03be06a4a7a9523cc99472cf53f07aaa1bf611', '4b03d1fc8af9ca29fa72db8c45617f2d9753f305');
q['q18'] = new Array('6c375c99221cfae7eb7fb8a11e49cd93265ce011');
q['q19'] = new Array('959399200585c2f394bb317b697ace0e9e7b07bf');
q['q20'] = new Array('625447a37892e5339574bc4be68cdf7c5b638e22');
q['q21'] = new Array('2dac81d65dd44b5d6ac0dd7afdf25b1527f6f0f7');
q['q22'] = new Array('4f5de2e1ea65e51e6123906ec3f9e370a8c2aab5');
q['q23'] = new Array('e60e6f35d64a920a5dd1ad2f0cfa5e7159c95a72');
q['q24'] = new Array('a7e2677fabfb73a59a1578a159a6a1b0d1599f72');
q['q25'] = new Array('e8a5ff092c549637a8a9a47f820359b091386c9f');
q['q26'] = new Array('673c0c108b7fabb00d5528872d79a1abd247a572');


function mirar(str) {

var ok=0;
for (x in q[str])
{
	if(sha1Hash(document.getElementById(str).value.toLowerCase()) == (q[str][x]) 	)
	{
		
		ok=1;
	}
}  


	if(ok)
	{
		validar1(str);
	}
	else
	{
		validar2(str);
	}
	
}

function carga() { 
	
	for (var i=1; i<76; i++) {		
		str='q'+i;	
		document.getElementById(str).style.border = '1px solid #A5ACB2';
		document.getElementById(str).disabled = false;
	} 
} 


function validar1(qstr) { 
	if(document.getElementById(qstr).disabled == false) {
	document.getElementById(qstr).disabled = true;
	document.getElementById(qstr).style.border = '2px solid #00FF00'; 
	document.getElementById('correct').innerHTML = document.getElementById('correct').innerHTML*1 + 1;
	}
}

function validar2(qstr) {
	if(document.getElementById(qstr).value=='') {
		document.getElementById(qstr).style.border = '1px solid #A5ACB2'; 
	}
	else
	{
	document.getElementById(qstr).style.border = '2px solid #FF0000'; 
	}
}


function sha1Hash(msg)
{
    // constants [4.2.1]
    var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];

    // PREPROCESSING 
 
    msg += String.fromCharCode(0x80);  // add trailing '1' bit to string [5.1.1]

    // convert string msg into 512-bit/16-integer blocks arrays of ints [5.2.1]
    var l = Math.ceil(msg.length/4) + 2;  // long enough to contain msg plus 2-word length
    var N = Math.ceil(l/16);              // in N 16-int blocks
    var M = new Array(N);

    for (var i=0; i<N; i++) {
        M[i] = new Array(16);
        for (var j=0; j<16; j++) {  // encode 4 chars per integer, big-endian encoding
            M[i][j] = (msg.charCodeAt(i*64+j*4)<<24) | (msg.charCodeAt(i*64+j*4+1)<<16) | 
                      (msg.charCodeAt(i*64+j*4+2)<<8) | (msg.charCodeAt(i*64+j*4+3));
        } // note running off the end of msg is ok 'cos bitwise ops on NaN return 0
    }
    // add length (in bits) into final pair of 32-bit integers (big-endian) [5.1.1]
    M[N-1][14] = ((msg.length-1) >>> 30) * 8;
    M[N-1][15] = ((msg.length-1)*8) & 0xffffffff;

    // set initial hash value [5.3.1]
    var H0 = 0x67452301;
    var H1 = 0xefcdab89;
    var H2 = 0x98badcfe;
    var H3 = 0x10325476;
    var H4 = 0xc3d2e1f0;

    // HASH COMPUTATION [6.1.2]

    var W = new Array(80); var a, b, c, d, e;
    for (var i=0; i<N; i++) {

        // 1 - prepare message schedule 'W'
        for (var t=0;  t<16; t++) W[t] = M[i][t];
        for (var t=16; t<80; t++) W[t] = ROTL(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);

        // 2 - initialise five working variables a, b, c, d, e with previous hash value
        a = H0; b = H1; c = H2; d = H3; e = H4;

        // 3 - main loop
        for (var t=0; t<80; t++) {
            var s = Math.floor(t/20); // seq for blocks of 'f' functions and 'K' constants
            var T = (ROTL(a,5) + f(s,b,c,d) + e + K[s] + W[t]) & 0xffffffff;
            e = d;
            d = c;
            c = ROTL(b, 30);
            b = a;
            a = T;
        }

        // 4 - compute the new intermediate hash value
        H0 = (H0+a) & 0xffffffff;  // note 'addition modulo 2^32'
        H1 = (H1+b) & 0xffffffff; 
        H2 = (H2+c) & 0xffffffff; 
        H3 = (H3+d) & 0xffffffff; 
        H4 = (H4+e) & 0xffffffff;
    }

    return H0.toHexStr() + H1.toHexStr() + H2.toHexStr() + H3.toHexStr() + H4.toHexStr();
}

//
// function 'f' [4.1.1]
//
function f(s, x, y, z) 
{
    switch (s) {
    case 0: return (x & y) ^ (~x & z);
    case 1: return x ^ y ^ z;
    case 2: return (x & y) ^ (x & z) ^ (y & z);
    case 3: return x ^ y ^ z;
    }
}

//
// rotate left (circular left shift) value x by n positions [3.2.5]
//
function ROTL(x, n)
{
    return (x<<n) | (x>>>(32-n));
}

//
// extend Number class with a tailored hex-string method 
//   (note toString(16) is implementation-dependant, and  
//   in IE returns signed numbers when used on full words)
//
Number.prototype.toHexStr = function()
{
    var s="", v;
    for (var i=7; i>=0; i--) { v = (this>>>(i*4)) & 0xf; s += v.toString(16); }
    return s;
}
function resetForm() {
	
	for(i=1;i<76;i++) {
	document.getElementById('q'+i).disabled = false;
	}
	document.forms[0].reset();
}

