answer1 = "tralalala";
q = new Array();
correct = 0;

q['q1'] = 'b760d01dd1a722369fe627129e6932695e724e17';
q['q2'] = 'fc6ae58d24b376b46f4c04d8725f78e929ad2deb';
q['q3'] = '76edf49e9cfa4df3a27f3a2249f56455eb443f29';
q['q4'] = 'e1c89849f06822d7c8296b53b6fc8058300432f4';
q['q5'] = '6e40d1131fa5ad30866b3d6e33bced3b0555cee1';
q['q6'] = 'ca0ec25b811b356701f1a25edba2ac8ff59d35ab';
q['q7'] = 'c7826d03612a62a0489ce7dda938ec37a22f2642';
q['q8'] = '6191e72d249c3e23f36e7fbeb1323dc07d6318ef';
q['q9'] = '736937ac5591f98b958a88685f31ca942b512e5e';
q['q10'] = '9e89110cf9bc2917a0d32dff44dbdc6675162f73';
q['q11'] = '31dbc75e50e3a54064f9bf6b834911f4cecca783';
q['q12'] = '043ef83e9708f29e09ae14a97366735bfcf75940';
q['q13'] = '21a94b4dacf768e37279eeef1154ceecff194284';
q['q14'] = 'b45e72e707a4f87486e72f4f3846852b10d0bdd1';
q['q15'] = 'd3acc430cd46714bc5682916313031a30ad65b5c';
q['q16'] = '1a9f5b056aaec94e28049fe509f236e6428d2397';
q['q17'] = 'b1831b213e7e1353fc6994ebc492e76e92e4b227';
q['q18'] = 'fb620d3af778269c0226f841c233aa385be0c7ca';
q['q19'] = 'be7973c53788dde47212931cc1eaf269c3601fa8';
q['q20'] = '309291ddc79bbab57a43de953526bf77478d6a0a';
q['q21'] = 'e946cc7e46f9537b4a4e43caf498b382b700653e';
q['q22'] = '865f925a970265708155d2835fd5962509aa1d4c';
q['q23'] = '18d55a17e81d7d23b6205a6494707652f96ab0fa';
q['q24'] = '7f166be254b870fc4190a25e09bb307ce20f5061';
q['q25'] = '54f4137e9f168fbc10c7b64e903528f536cbc057';
q['q26'] = 'e39f5b8840e40982fa0d8b2d00a3c3f58e0d2945';
q['q27'] = '9bd3ae8c169ebacd61546bde90248317f21b16a5';
q['q28'] = '4e629a008dfe510bb48e8cbdb57a402876671ad1';
q['q29'] = 'bc9694c7fc11bbed24d9326f602469aee41efcaa';
q['q30'] = 'b6c18b8a52bff466f8ec533f8a1bf3cd39646026';
q['q31'] = '18537596308e75fb2eec4e41248733c8a861fb14';
q['q32'] = '200449a3c6c7e2e0ccbf0a60c6a00fb796a0b5cf';
q['q33'] = '187055f2fae213bcc06110ddc9b3dba6223b6af3';



function checkQ(str) {
	if(sha1Hash(document.getElementById(str).value.toUpperCase()) == q[str])
	{
		validate1(str);
	}
	else
	{
		validate2(str);
	}
	//document.getElementById("hash").innerHTML=sha1Hash(document.getElementById(str).value.toUpperCase());
}

function validate1(qstr) {
	document.getElementById(qstr).disabled = true;
	document.getElementById(qstr).style.border = '2px solid #00FF00'; 
	correct++;
	document.getElementById('correct').innerHTML = correct;
}

function validate2(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<34;i++) {
	document.getElementById('q'+i).disabled = false;
	}
	document.forms[0].reset();
}
