Obfuscated Vote Counting Contest
Daniel Horn writes "In a flash of inspiration coming from the Obfuscated C code contest and the current E-voting scandals, I wondered if there shouldn't be a similar code obfuscation contest based on obfuscating voting results, that is, C code that appears correct but does the wrong thing when counting votes. Submit your obfuscated vote-counting code now, and the two winners will be selected on November 2 and will receive a free Vega Strike CD. Obviously incorrect code, however, is not welcome."
If I were doing this, I would hide the date analysis and vote rigging in another part of the program. For example, the code used to handle the screen and menus, or the network stack.
Then, you could obfuscate a call to jump the program pointer to that part of memory directly, run a tiny bit of code that appears to deal with graphics, but does something else when called with the correct offset.
The devious would be scattered about, rather than in one single vote counting function.
Is welcome the code inside Smartmatic Votting machines used in Venezuela?
Well, you must have misread. They use Windows CE. I shit you not.
"Anyone who attempts to generate random numbers by deterministic means is living in a state of sin." -- John von Neumann
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <setjmp.h>
jmp_buf escape;
/* NOTE: to save memory, the low byte of results is used as a buffer *\
\* NOTE: notice the shifts (and adding 256 for each vote) to fix it. */
vcc(int vote, int results[4]);
int main(void)
{
int results[4];
if (!setjmp(escape))
do {
vcc(read(0, results, 1), results);
} while (1);
results[0] >>= 8;
results[1] >>= 8;
results[2] >>= 8;
results[3] >>= 8;
printf("Bush: %d Kerry: %d Nader: %d Other: %d\n", results[0], results[1], results[2], results[3]);
}
vcc(int vote, int results[4])
{
if (vote == EOF)
longjmp(escape, 1);
if (!isspace(vote))
switch (vote)
{
case 'K': results[1]+=256; break;
case 'B': results[0]+=256; break;
case 'N': results[2]+=256; break;
default: results[3]+=256; break;
}
}
Is it sad that I just ran your code? It worked, by the way. See the results here.
I am a viral sig. Please help me spread.
try to make a point and the only thing people notice is the syntax errors... only on slashdot
Indeed. Everywhere else normal people would just get the point presented in the form of a C program, but not the nerds on Slashdot! But seriously, I was sure that all of the errors in your code was just meant to be examples of real errors that might change the election outcome:
All in all, not counting the Perlish elsif there are no syntax errors, while every single logic error might be used on purpose in a vote-counting code to change the election outcome while being hard to spot in a large and complicated spaghetti code. Did I really miss something?
Actually, I was very surprised reading all of the posts fixing the bugs in your code. "Weren't such bugs the whole point of a contest writing 'C code that appears correct but does the wrong thing when counting votes' after all," I thought to myself? [emphasis added]
But now I am even more surprised! Were those really unintentional errors? Because when I first read your comment I though: "What a brilliant example with so many subtle errors in every single statement!" Have I really overestimated the brilliance of your code? I do really hope that I have not, because it was surely one of the best examples posted so far, the foolish down-moderation notwithstanding.
Was I completely wrong? Doubtful. Was I fooled? I don't think so. Am I stupid? Highly unlikely. So what's wrong?
Sincerely,
Pan Tarhei Hosé, PhD.
"Homo sum et cogito ergo odi profanum vulgus et libido."