Taking an online class and they use some stupid code to do their tests.
Here's the code to one of the tests.... anyone know how to decrypt the answers? Should be fairly easy I would assume. I understand some of it but my knowledge is very limited and I started getting a headache so I decided to post here.
<script language='JavaScript1.1'>
<!--
// Copyright (c) 2000 FSCreations, Inc.
var listMap = '1111111111111111111111111111111111111111';
var qtypeMap = '2222222222222222222222222222222222222222';
var ansMap = new Array(40);
ansMap[0] = '45';
ansMap[1] = '43';
ansMap[2] = '40';
ansMap[3] = '45';
ansMap[4] = '41';
ansMap[5] = '44';
ansMap[6] = '43';
ansMap[7] = '4b';
ansMap[8] = '48';
ansMap[9] = '48';
ansMap[10] = '4f';
ansMap[11] = '4e';
ansMap[12] = '49';
ansMap[13] = '4a';
ansMap[14] = '4e';
ansMap[15] = '52';
ansMap[16] = '55';
ansMap[17] = '56';
ansMap[18] = '51';
ansMap[19] = '55';
ansMap[20] = '56';
ansMap[21] = '57';
ansMap[22] = '55';
ansMap[23] = '5b';
ansMap[24] = '5b';
ansMap[25] = '58';
ansMap[26] = '5f';
ansMap[27] = '5d';
ansMap[28] = '5e';
ansMap[29] = '5a';
ansMap[30] = '5e';
ansMap[31] = '40';
ansMap[32] = '40';
ansMap[33] = '40';
ansMap[34] = '40';
ansMap[35] = '44';
ansMap[36] = '47';
ansMap[37] = '44';
ansMap[38] = '4c';
ansMap[39] = '4b';
function HandleSubmit(f, forceSubmit)
{
var numCorrect = 0;
var numPossible = 0;
var numBlank = 0;
var index;
var msg;
var i;
f.student_name.value = StripSpaces(f.student_name.value);
f.student_id.value = StripSpaces(f.student_id.value);
f.student_email.value = StripSpaces(f.student_email.value);
FixMTF(f);
index = 0;
for (i=0; i < f.length; ++i) {
if (f.elements.name.indexOf(":") > 0) {
if (listMap.charAt(index) == "1") {
listIndex = f.elements.selectedIndex;
text = f.elements.options[listIndex].text;
} else {
f.elements.value = StripSpaces(f.elements.value);
text = f.elements.value;
}
if (text.length == 0)
++numBlank;
++index;
}
}
if (f.student_name.value == "") {
alert("Student name cannot be blank.");
return(false);
}
if (numBlank > 0) {
if (numBlank == 1)
msg = "1 question";
else
msg = numBlank + " questions";
if (!confirm("You have not answered " + msg +
" Are you sure you want to end the test?"))
return(false);
}
index = 0;
f.score_details.value = "";
for (i=0; i < f.length; ++i) {
if (f.elements.name.indexOf(":") > 0) {
if (ansMap[index] == "")
f.score_details.value += "?";
else {
isCorrect = ScoreAnswer(index, f.elements);
if (isCorrect) {
++numCorrect;
f.score_details.value += " ";
} else
f.score_details.value += "X";
++numPossible;
}
++index;
}
}
f.score_correct.value = numCorrect;
f.score_possible.value = numPossible;
if (numPossible > 0)
f.score_percent.value = Math.round(100.0 * numCorrect / numPossible);
else
f.score_percent.value = 0;
if (forceSubmit) {
f.submit();
return(false);
}
return(true);
}
function ScoreAnswer(answerIndex, answer)
{
var listIndex;
var responseText;
var answerText;
if (listMap.charAt(answerIndex) == "1") {
listIndex = answer.selectedIndex;
responseText = answer.options[listIndex].text;
} else
responseText = answer.value;
answerText = TranslateAnswer(ansMap[answerIndex], answerIndex);
if (qtypeMap.charAt(answerIndex) == "4")
return(NumericCompare(responseText, answerText));
else if (qtypeMap.charAt(answerIndex) == "5")
return(MultiCompare(responseText, answerText));
else if (responseText.toUpperCase() == answerText.toUpperCase())
return(true);
else
return(false);
}
function TranslateAnswer(s, answerIndex)
{
var value;
var newString;
var code;
var i;
value = (answerIndex % 31) + 1;
newString = "";
for (i=0; i < s.length; i += 2) {
code = parseInt(s.substring(i, i + 2), 16);
newString += String.fromCharCode(code ^ value);
}
return(newString);
}
function StripSpaces(s)
{
var len;
var i;
len = s.length;
for (i=len - 1; i >= 0 && s.charAt(i) == " "; --i)
len = i;
if (len == 0)
s = "";
else if (len != s.length)
s = s.substring(0, len);
return(s);
}
function NumericCompare(s1, s2)
{
var s1Sign;
var s2Sign;
var tempString;
var decimalCount;
var decimalPos;
var numToDelete;
var len;
var ch;
var i;
s1.toUpperCase();
s2.toUpperCase();
if (s1 == s2)
return(true);
else {
s1Sign = 1;
s2Sign = 1;
tempString = "";
for (i=0; i < s1.length; ++i) {
ch = s1.charAt(i);
if (ch == "-" && tempString.length == 0)
s1Sign = -1;
else if ((ch >= "0" && ch <= "9") || ch == ".")
tempString += ch;
}
s1 = tempString;
decimalCount = 0;
decimalPos = -1;
for (i=0; i < s1.length; ++i) {
if (s1.charAt(i) == '.') {
++decimalCount;
if (decimalPos < 0)
decimalPos = i;
}
}
if (decimalCount == 1 && decimalPos >= 0) {
len = s1.length;
for (i=len - 1; i >= decimalPos; --i) {
if (i == decimalPos || s1.charAt(i) == '0')
len = i;
else
break;
}
if (len < s1.length)
s1 = s1.substring(0, len);
if (s1.length == 0)
s1 = "0";
}
numToDelete = 0;
for (i=0; i < s1.length; ++i) {
if (s1.charAt(i) == "0")
++numToDelete;
else
break;
}
if (numToDelete > 0) {
if (numToDelete == s1.length)
--numToDelete;
if (numToDelete > 0)
s1 = s1.substring(numToDelete);
}
/////////////////////////////////////////////
tempString = "";
for (i=0; i < s2.length; ++i) {
ch = s2.charAt(i);
if (ch == "-" && tempString.length == 0)
s2Sign = -1;
else if ((ch >= "0" && ch <= "9") || ch == ".")
tempString += ch;
}
s2 = tempString;
decimalCount = 0;
decimalPos = -1;
for (i=0; i < s2.length; ++i) {
if (s2.charAt(i) == '.') {
++decimalCount;
if (decimalPos < 0)
decimalPos = i;
}
}
if (decimalCount == 1 && decimalPos >= 0) {
len = s2.length;
for (i=len - 1; i >= decimalPos; --i) {
if (i == decimalPos || s2.charAt(i) == '0')
len = i;
else
break;
}
if (len < s2.length)
s2 = s2.substring(0, len);
if (s2.length == 0)
s2 = "0";
}
numToDelete = 0;
for (i=0; i < s2.length; ++i) {
if (s2.charAt(i) == "0")
++numToDelete;
else
break;
}
if (numToDelete > 0) {
if (numToDelete == s2.length)
--numToDelete;
if (numToDelete > 0)
s2 = s2.substring(numToDelete);
}
if (s1Sign == s2Sign && s1 == s2)
return(true);
}
return(false);
}
function MultiCompare(responseText, answerText)
{
var startIndex;
var endIndex;
var partialText;
responseText = responseText.toUpperCase();
answerText = answerText.toUpperCase();
startIndex = 0;
do {
endIndex = answerText.indexOf("\r", startIndex);
if (endIndex < 0)
partialText = answerText.substring(startIndex);
else
partialText = answerText.substring(startIndex, endIndex);
if (responseText == partialText)
return(true);
startIndex = endIndex + 1;
} while (endIndex > 0);
return(false);
}
function FixMTF(f)
{
var text;
var letter;
var theList;
var listIndex;
var number;
var i;
for (i=0; i < f.length; ++i) {
if (f.elements.name.indexOf("MTF:") == 0) {
number = parseInt(f.elements.name.substring(4), 10);
theList = f["MTF-" + number + "-1"];
if (theList) {
listIndex = theList.selectedIndex;
letter = theList.options[listIndex].text;
} else
letter = "";
text = StripSpaces(f["MTF-" + number + "-2"].value);
if (text == "")
f.elements.value = letter;
else
f.elements.value = letter + "," + text;
}
}
}
function AllowReset()
{
return(window.confirm("Do you want to clear all of your answers?"));
}
// -->
</script>
Here's the code to one of the tests.... anyone know how to decrypt the answers? Should be fairly easy I would assume. I understand some of it but my knowledge is very limited and I started getting a headache so I decided to post here.
<script language='JavaScript1.1'>
<!--
// Copyright (c) 2000 FSCreations, Inc.
var listMap = '1111111111111111111111111111111111111111';
var qtypeMap = '2222222222222222222222222222222222222222';
var ansMap = new Array(40);
ansMap[0] = '45';
ansMap[1] = '43';
ansMap[2] = '40';
ansMap[3] = '45';
ansMap[4] = '41';
ansMap[5] = '44';
ansMap[6] = '43';
ansMap[7] = '4b';
ansMap[8] = '48';
ansMap[9] = '48';
ansMap[10] = '4f';
ansMap[11] = '4e';
ansMap[12] = '49';
ansMap[13] = '4a';
ansMap[14] = '4e';
ansMap[15] = '52';
ansMap[16] = '55';
ansMap[17] = '56';
ansMap[18] = '51';
ansMap[19] = '55';
ansMap[20] = '56';
ansMap[21] = '57';
ansMap[22] = '55';
ansMap[23] = '5b';
ansMap[24] = '5b';
ansMap[25] = '58';
ansMap[26] = '5f';
ansMap[27] = '5d';
ansMap[28] = '5e';
ansMap[29] = '5a';
ansMap[30] = '5e';
ansMap[31] = '40';
ansMap[32] = '40';
ansMap[33] = '40';
ansMap[34] = '40';
ansMap[35] = '44';
ansMap[36] = '47';
ansMap[37] = '44';
ansMap[38] = '4c';
ansMap[39] = '4b';
function HandleSubmit(f, forceSubmit)
{
var numCorrect = 0;
var numPossible = 0;
var numBlank = 0;
var index;
var msg;
var i;
f.student_name.value = StripSpaces(f.student_name.value);
f.student_id.value = StripSpaces(f.student_id.value);
f.student_email.value = StripSpaces(f.student_email.value);
FixMTF(f);
index = 0;
for (i=0; i < f.length; ++i) {
if (f.elements.name.indexOf(":") > 0) {
if (listMap.charAt(index) == "1") {
listIndex = f.elements.selectedIndex;
text = f.elements.options[listIndex].text;
} else {
f.elements.value = StripSpaces(f.elements.value);
text = f.elements.value;
}
if (text.length == 0)
++numBlank;
++index;
}
}
if (f.student_name.value == "") {
alert("Student name cannot be blank.");
return(false);
}
if (numBlank > 0) {
if (numBlank == 1)
msg = "1 question";
else
msg = numBlank + " questions";
if (!confirm("You have not answered " + msg +
" Are you sure you want to end the test?"))
return(false);
}
index = 0;
f.score_details.value = "";
for (i=0; i < f.length; ++i) {
if (f.elements.name.indexOf(":") > 0) {
if (ansMap[index] == "")
f.score_details.value += "?";
else {
isCorrect = ScoreAnswer(index, f.elements);
if (isCorrect) {
++numCorrect;
f.score_details.value += " ";
} else
f.score_details.value += "X";
++numPossible;
}
++index;
}
}
f.score_correct.value = numCorrect;
f.score_possible.value = numPossible;
if (numPossible > 0)
f.score_percent.value = Math.round(100.0 * numCorrect / numPossible);
else
f.score_percent.value = 0;
if (forceSubmit) {
f.submit();
return(false);
}
return(true);
}
function ScoreAnswer(answerIndex, answer)
{
var listIndex;
var responseText;
var answerText;
if (listMap.charAt(answerIndex) == "1") {
listIndex = answer.selectedIndex;
responseText = answer.options[listIndex].text;
} else
responseText = answer.value;
answerText = TranslateAnswer(ansMap[answerIndex], answerIndex);
if (qtypeMap.charAt(answerIndex) == "4")
return(NumericCompare(responseText, answerText));
else if (qtypeMap.charAt(answerIndex) == "5")
return(MultiCompare(responseText, answerText));
else if (responseText.toUpperCase() == answerText.toUpperCase())
return(true);
else
return(false);
}
function TranslateAnswer(s, answerIndex)
{
var value;
var newString;
var code;
var i;
value = (answerIndex % 31) + 1;
newString = "";
for (i=0; i < s.length; i += 2) {
code = parseInt(s.substring(i, i + 2), 16);
newString += String.fromCharCode(code ^ value);
}
return(newString);
}
function StripSpaces(s)
{
var len;
var i;
len = s.length;
for (i=len - 1; i >= 0 && s.charAt(i) == " "; --i)
len = i;
if (len == 0)
s = "";
else if (len != s.length)
s = s.substring(0, len);
return(s);
}
function NumericCompare(s1, s2)
{
var s1Sign;
var s2Sign;
var tempString;
var decimalCount;
var decimalPos;
var numToDelete;
var len;
var ch;
var i;
s1.toUpperCase();
s2.toUpperCase();
if (s1 == s2)
return(true);
else {
s1Sign = 1;
s2Sign = 1;
tempString = "";
for (i=0; i < s1.length; ++i) {
ch = s1.charAt(i);
if (ch == "-" && tempString.length == 0)
s1Sign = -1;
else if ((ch >= "0" && ch <= "9") || ch == ".")
tempString += ch;
}
s1 = tempString;
decimalCount = 0;
decimalPos = -1;
for (i=0; i < s1.length; ++i) {
if (s1.charAt(i) == '.') {
++decimalCount;
if (decimalPos < 0)
decimalPos = i;
}
}
if (decimalCount == 1 && decimalPos >= 0) {
len = s1.length;
for (i=len - 1; i >= decimalPos; --i) {
if (i == decimalPos || s1.charAt(i) == '0')
len = i;
else
break;
}
if (len < s1.length)
s1 = s1.substring(0, len);
if (s1.length == 0)
s1 = "0";
}
numToDelete = 0;
for (i=0; i < s1.length; ++i) {
if (s1.charAt(i) == "0")
++numToDelete;
else
break;
}
if (numToDelete > 0) {
if (numToDelete == s1.length)
--numToDelete;
if (numToDelete > 0)
s1 = s1.substring(numToDelete);
}
/////////////////////////////////////////////
tempString = "";
for (i=0; i < s2.length; ++i) {
ch = s2.charAt(i);
if (ch == "-" && tempString.length == 0)
s2Sign = -1;
else if ((ch >= "0" && ch <= "9") || ch == ".")
tempString += ch;
}
s2 = tempString;
decimalCount = 0;
decimalPos = -1;
for (i=0; i < s2.length; ++i) {
if (s2.charAt(i) == '.') {
++decimalCount;
if (decimalPos < 0)
decimalPos = i;
}
}
if (decimalCount == 1 && decimalPos >= 0) {
len = s2.length;
for (i=len - 1; i >= decimalPos; --i) {
if (i == decimalPos || s2.charAt(i) == '0')
len = i;
else
break;
}
if (len < s2.length)
s2 = s2.substring(0, len);
if (s2.length == 0)
s2 = "0";
}
numToDelete = 0;
for (i=0; i < s2.length; ++i) {
if (s2.charAt(i) == "0")
++numToDelete;
else
break;
}
if (numToDelete > 0) {
if (numToDelete == s2.length)
--numToDelete;
if (numToDelete > 0)
s2 = s2.substring(numToDelete);
}
if (s1Sign == s2Sign && s1 == s2)
return(true);
}
return(false);
}
function MultiCompare(responseText, answerText)
{
var startIndex;
var endIndex;
var partialText;
responseText = responseText.toUpperCase();
answerText = answerText.toUpperCase();
startIndex = 0;
do {
endIndex = answerText.indexOf("\r", startIndex);
if (endIndex < 0)
partialText = answerText.substring(startIndex);
else
partialText = answerText.substring(startIndex, endIndex);
if (responseText == partialText)
return(true);
startIndex = endIndex + 1;
} while (endIndex > 0);
return(false);
}
function FixMTF(f)
{
var text;
var letter;
var theList;
var listIndex;
var number;
var i;
for (i=0; i < f.length; ++i) {
if (f.elements.name.indexOf("MTF:") == 0) {
number = parseInt(f.elements.name.substring(4), 10);
theList = f["MTF-" + number + "-1"];
if (theList) {
listIndex = theList.selectedIndex;
letter = theList.options[listIndex].text;
} else
letter = "";
text = StripSpaces(f["MTF-" + number + "-2"].value);
if (text == "")
f.elements.value = letter;
else
f.elements.value = letter + "," + text;
}
}
}
function AllowReset()
{
return(window.confirm("Do you want to clear all of your answers?"));
}
// -->
</script>