• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programers... Who wants to help me cheat?

Status
Not open for further replies.

retardboy

Member
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>
 

retardboy

Member
But that wouldn't tell me how the answer are encrypted... Actually it could if I just took the TranslateAnswers function out and tested it out but as I said, my knowledge is limited. I'm sure someone here would be able to do it.
 

8bit

Knows the Score
That's only the answer handler for the quiz, isn't it? You'll need an example of a question and the associated code to check it properly.
 

retardboy

Member
Alright, here's the first question
and the code that goes with it


real simple question... answer is obviously d

1.
Applications software is used to ____.
a. facilitate communications and as a business tool
b. assist with graphics and multimedia projects
c. support home, personal, and educational activities
d. all of the above




<!-- BEGIN: QUESTION -83891:1 -->
<tr valign='baseline'>
<td>
<select name='MC:1' align='top'>
<option value=' '>
<option value='A'>A
<option value='B'>B
<option value='C'>C
<option value='D'>D
</select>
</td>
<td>
<p class='qnumber'>1.&nbsp;</p>
</td>
<td width='100%'>
<div><span style='font-family:"Times New Roman", "Times", serif; font-size:12pt;
color:#000000'>Applications software is used to ____.</span></div><div
style='font-size:2pt'></div><table cellpadding='0' cellspacing='0' width='83%' border='0'><tr
valign='baseline'><td><div><span style='font-family:"Times New Roman", "Times", serif;
font-size:12pt; color:#000000'>a.</span></div></td><td><div><span
style='font-family:"Times New Roman", "Times", serif; font-size:12pt; color:#000000'>facilitate
communications and as a business tool</span></div></td></tr><tr valign='baseline'><td><div><span
style='font-family:"Times New Roman", "Times", serif; font-size:12pt;
color:#000000'>b.</span></div></td><td><div><span style='font-family:"Times New Roman", "Times",
serif; font-size:12pt; color:#000000'>assist with graphics and multimedia
projects</span></div></td></tr><tr valign='baseline'><td><div><span
style='font-family:"Times New Roman", "Times", serif; font-size:12pt;
color:#000000'>c.</span></div></td><td><div><span style='font-family:"Times New Roman", "Times",
serif; font-size:12pt; color:#000000'>support home, personal, and educational
activities</span></div></td></tr><tr valign='baseline'><td><div><span
style='font-family:"Times New Roman", "Times", serif; font-size:12pt;
color:#000000'>d.</span></div></td><td><div><span style='font-family:"Times New Roman", "Times",
serif; font-size:12pt; color:#000000'>all of the above</span></div></td></tr><tr height='0'
style='border:none'><td width='5%' style='width:18pt; padding:0'></td><td width='95%'
style='width:405pt; padding:0'></td></tr></table>
<div class='spacer'>&nbsp;</div>
</td>
</tr>
<!-- END: QUESTION -83891:1 -->
 

Ferrio

Banned
<!-- BEGIN: QUESTION -83891:1 -->
<tr valign='baseline'>
<td>
<select name='MC:1' align='top'>
<option value=' '>
<option value='A'>A
<option value='B'>B
<option value='C'>C
<option value='D'>D
</select>
</td>
<td>
<p class='qnumber'>1.&nbsp;</p>
</td>
<td width='100%'>
<div><span style='font-family:"Times New Roman", "Times", serif; font-size:12pt;
color:#000000'>Applications software is used to ____.</span></div><div
style='font-size:2pt'></div><table cellpadding='0' cellspacing='0' width='83%' border='0'><tr
valign='baseline'><td><div><span style='font-family:"Times New Roman", "Times", serif;
font-size:12pt; color:#000000'>a.</span></div></td><td><div><span
style='font-family:"Times New Roman", "Times", serif; font-size:12pt; color:#000000'>facilitate
communications and as a business tool</span></div></td></tr><tr valign='baseline'><td><div><span
style='font-family:"Times New Roman", "Times", serif; font-size:12pt;
color:#000000'>b.</span></div></td><td><div><span style='font-family:"Times New Roman", "Times",
serif; font-size:12pt; color:#000000'>assist with graphics and multimedia
projects</span></div></td></tr><tr valign='baseline'><td><div><span
style='font-family:"Times New Roman", "Times", serif; font-size:12pt;
color:#000000'>c.</span></div></td><td><div><span style='font-family:"Times New Roman", "Times",
serif; font-size:12pt; color:#000000'>support home, personal, and educational
activities</span></div></td></tr><tr valign='baseline'><td><div><span
style='font-family:"Times New Roman", "Times", serif; font-size:12pt;
color:#000000'>d.</span></div></td><td><div><span style='font-family:"Times New Roman", "Times",
serif; font-size:12pt; color:#000000'>all of the above</span></div></td></tr><tr height='0'
style='border:none'><td width='5%' style='width:18pt; padding:0'></td><td width='95%'
style='width:405pt; padding:0'></td></tr></table>
<div class='spacer'>&nbsp;</div>
</td>
</tr>
<!-- END: QUESTION -83891:1 -->

That's a tough one.
 

iapetus

Scary Euro Man
Based on the code and the sample question, it would actually be easier just to get all the questions right than it would be to reverse engineer the code.

You haven't provided enough details to reverse engineer the code properly anyway: we'd need the full HTML for the questions page. Not that I have any intention of doing this for you anyway. :p
 

xsarien

daedsiluap
I don't know much about what you're asking, but I do know that whomever formatted that HTML should be dragged out into the street and shot. :p
 

Hawksley

Member
Looks like it just takes your answers and sends them off to be marked. I don't think you're gonna be cheating with the code you've got.
 

retardboy

Member
Matlock said:
retardboy: You don't know how tempted I am to contact Long Beach City College about this. :p


:) Yeah yeah Haha I think the teachers there are dumber than me. They won't even know what you're talking about. Goodness I hate this class. What a freaken waste of time.
 

iapetus

Scary Euro Man
xsarien said:
I don't know much about what you're asking, but I do know that whomever formatted that HTML should be dragged out into the street and shot. :p

Actually, in this case I'd consider making an exception, vile as it is. It's supposed to be unreadable. :p
 

sefskillz

shitting in the alley outside your window
chances are the html is only unreadable on our end, its probably being generated by a script and im sure they aren't using templates for questions.. so on their end its probably properly formatted without any \n's so it just looks bad to us.
 

Lord Error

Insane For Sony
The unreadable HTML code you provided above is essentialy worthless. When you remove all the style and table tags (which is basically a windowdressing), you are left with this:

<select name='MC:1' align='top'>
<option value=' '>
<option value='A'>A
<option value='B'>B
<option value='C'>C
<option value='D'>D
</select>
<br>

1.<br>
Applications software is used to ____.<br>
a. facilitate
communications and as a business tool<br>
b. assist with graphics and multimedia
projects<br>
c. support home, personal, and educational
activities<br>
d. all of the above

So that HTML is used to just print the question on the screen. We still have no idea where and how are the function calls made to check if the answer you provided is correct.
 

retardboy

Member
The very first part called ansMap are the answers. They're just encrypted somehow. That's why there's that translateAns function which will translate the answers and there are subseqent fuctions that compare the answers and check to see if they're right. The rest is just html. There's really no point in reading it because it won't give you anything.
 

iapetus

Scary Euro Man
My one concern is whether it actually submits your answers. If not, then you should simply be able to modify the page so it ignores the whole marking process, and tell it you got 100% of the test (or more) correct.

If that's the case, then whoever set this up needs to be slapped.
 

Lord Error

Insane For Sony
If that's the case, then whoever set this up needs to be slapped.
Considering it took me whole five minutes to break it and find all the answers, he should be slapped anyways. I'm not 100% sure if the answers I've found are all corect though. The ones that I've found are all in the form of A/B/C/D, but in the code, there is a function for numeric comparision, which suggests there should also be questions that require numeric answers.

But yeah, in all the likeness you can just force the 'numCorrect' value to maximum number (40), as it seems everything is just stored locally and submitted alltogether after you've done the test.
 

retardboy

Member
It doesn't submit your answers... The guy who did it should be slapped, no question. At the end, it'll submit the number you got correct the questions you missed and what you answered. I can easily rig it to say I got 100%, but it'll list what my answers were and it'll list all of them as right, but you can easily tell they were wrong so I don't want to do that.

Marconelly: so...... wanna share how you did it?? :p
 

Lord Error

Insane For Sony
Ah, what the hell...
Look at the line 138 of your javascript source:

answerText = TranslateAnswer(ansMap[answerIndex], answerIndex);

It tells you everything you need to know. Print it's result, and for each given answerIndex (0-39), you'll get a correct answer (a text string containing A,B,C or D)

CRASH + BURN!!!
 

retardboy

Member
Excellent... But one problem... I don't know Java at all. Never tried it once. Only reason I know what most of it does is because it's similar to c++. Do you know how I could just modify the code to make it print the anwers in IE or whatever my browser is? Thanks!
 

Lord Error

Insane For Sony
OK... Since I've already told you pretty much everything...

Change the function 'ScoreAnswer' so that it looks like this:

ScoreAnswer(answerIndex, answer)
{
var listIndex;
var responseText;
var answerText;

answerText = TranslateAnswer(ansMap[answerIndex], answerIndex);
answersDiv.innerHTML += answerText + ' ';
}

So just delete a bunch of lines, and add the last two lines.

Then, at the very bottom, below the </script> tag, add this:
<body onLoad=for(answ=0;answ<40;answ++)ScoreAnswer(answ,1)>
<div id='answersDiv'></div>

Save that as an HTML file, run it in IE and that's it.
 

retardboy

Member
Hehehe thanks!
I actually figured it out right before I checked this thread
I just basically did a loop


in the ScoreAnswers function


for (index=0; index < ansMap.length; ++index) {
answerText = TranslateAnswer(ansMap[index], index);
document.write(answerText);
}

Anyway! Thank you thank you!
 
Status
Not open for further replies.
Top Bottom