I had the idea (I'm uncertain if it is original [pdf]) of mixing two distinct elements to make a better CAPTCHA.
The problem is that there are essentially two ways to solve a CAPTCHA. The first is by designing some kind of image recognition system, this is an OCR problem and there are indications that nearly every major CAPTCHA has been broken.
The other main avenue of attack seems to come down to paying people to crack them. This is a much tougher nut to crack because CAPTCHAs are not designed to prevent humans from cracking them; in some sense, this attack isn't a break of the system at all, but a design goal of CAPTCHAs. But much like the mathematician in that old joke, this definition of acceptable wouldn't sit well with some.
The solution is to pose a question in such a way that is very hard for a computer to perceive but at the same time hard for a person to solve by herself. As an example, imagine a cryptographically hard problem posed in a way that a computer couldn't readily interpret, and a person would find difficult (or impossible) to solve by hand. This could be the source code for a simple discrete logarithm solver. The code would be obscured in the normal way that a CAPTCHA is (wavy text, visual noise, etc.) The user is instructed to type the code into a text box (where a built-in solver, client-side, can operate on it), and then use the result for entry into the protected resource. It would be easy to tune the toughness of the discrete log problem (randomly chosen of course) to generate any penalty you want. This penalty would cost an attacker any amount of CPU time that the challenger desires.
By mixing a character-recognition task (that a human is good at) with a number-crunching task (which a computer is good at, but can be made arbitrarily CPU-intensive and thus slow) you protect from both types of attacks:
If an OCR program can read your text, they still must compute a computationally expensive value.
If humans are being used to circumvent the OCR task, a computer must be used to compute the expensive task as well, still incurring most of the penalty (by tweaking the exact type and hardness of the one-way function, this part can come to dominate the time needed for a successful break).
Some ideas on how to make the computation time more palatable for a legitimate user:
Make this be the first question on a form that the user has to fill out.
Grant the user provisional access to the site while the computation proceeds in the background.
I was reading Hal's blog the other day when I thought that I'd try and implement a clock that uses the hexadecimal time that he talks about. I have seen a bunch of these so-called binary clocks that display the time is some nifty format (blinkenlights). The thing is, what they display is usually binary coded decimal (i.e. 1100:111011 = 12:59). Sometimes they even code each digit: 0001 0010:0101 1001!
Hal defined the hexadecimal second to be 1/2^16 of a day, making 65,536 "hexeconds" per day. Since there are 86,400 seconds in a day, there are about 1.318 sec/hxs. Naturally, there are FF hexeconds in a "hexinute." A hexinute is 1/2^8 of a day, making each 337.5 seconds long, or 5.625 minutes (5 min, 37.5 sec). This leads to a nice property (besides being easily convertible to binary), A day then is recursive, there are 256 hxm per day and there are 256 hxs per hxm. Much better than 24 hours, with 60 minutes with 60 seconds! Who could remember that? You just have to get used to your clock displaying a time like: BE|EF (~64,440 seconds into your day or 5:54 PM, clearly not a vegetarian dinner time).
Another thing that I thought about was the "stability" of a given digit. Each digit "stays put" for 16 times as long as the digit to it's right. The fastest-changing digit advances each ~1.318 second, to its left the 16's place advances each 16*1.318 = ~21 seconds. In the one's place in the hexinutes each advances 337.5 seconds (or 5.625 minutes), lastly, the most stable digit advances each every 90 minutes. That's great for measuring the orbital period of the space shuttle, each orbit is 10|00 long! That's my proposal for writing the time, by the way, for the programmers out there it will be evocative of a bitwise OR; if you think of the time as something like 0xAB00 | 0xCD.
Without further ado:
I guess I shouldn't be surprised by anything that turns up within a million-line codebase, but I was.
I had been looking around for a way to keep contacts, you know, collections of vital stats: name, e-mail address and if I have it postal address. I've had such a file hanging around for years now my nickname for it is snailmail. I know that the term has traditionally meant more or less: "things one can send through the postal service." But seeing as how e-mail is dead (TIC), it grows increasingly apropos. But anyway, I digress.
I have this file of info and I wanted to keep it up to date, generate lists of names, generate those mailto: links and etc. In keeping with what I feel is the the *NIX way, I thought I should create a bunch of shell scripts that operate on my flat file in various ways. So I wrote a few scripts that would dig through the file and spit out whatever it was that I wanted. Okay, I can't resist, I wanted to include one of the ones that I wrote in scheme (guile):
So it is cake to read out the lines of this file. What I wondered more about was how to update and tend this file?
Emacs to the rescue! I found out about forms-mode this does what you would expect, that is to create and fill out forms. There are two components to the form, the first is your data file. In my case it looks like this
And so on. Next we need an emacs lisp file to tell Emacs how to parse that file and what the form should look like:
When you launch emacs and point it at that file emacs -nw sform.el, emacs will ask if you want parse it (answer 'yes') And then there are helpful commands at the bottom of the screen. The only basic one omitted is the one to create new entries, C-c C-o does the trick.
Sometimes I want to post code to a website, but they have utterly broken filters (I'm looking at you Yahoo! Answers). So that when I paste nicely indented code it goes from this:
def double(x):
return x+x
to this:
def double(x):
return x+x
It is annoying in C or Lisp, but it is wrong in python where the syntax relies on proper indentation. When websites do this it is broken.
So I wrote a little program to rectify the situation. It processes a source file so that it looks the same or similar on the web as in your text editor.
usage: webindent < source.c > page.html
#include <stdio.h>
#define true 1
#define false 0
/* main(): get characters from stdin, replace
* leading spaces with ' '
* and replace leading tabs with 4 ' 's
* This code is donated to the public domain */
int main()
{
int start = true; /* we're at the start of a line */
char *space = " ";
char *fourspaces = " ";
char c; /* the current char */
while ((c = getchar()) != EOF) {
if (c == ' ') {
if (start)
printf(space);
else
putchar(c);
} else if (c == '\t') {
if (start)
printf(fourspaces);
else
putchar(c);
} else if (c == '<') {
printf("<");
} else if (c == '>') {
printf(">");
} else if (c == '\n') {
printf("<br />");
putchar(c);
start = true;
} else if (c == '&') {
printf("&");
} else {
if (start)
start = false;
putchar(c);
}
}
return 0;
}
It does a bit more than is stated in that comment, because it has to remove '&', '<' and '>' for it to be a well-formed HTML fragment. Note that I used this program to process itself.
I had been wondering about how to create a printed book from the novel that I had written a couple of years ago and I just now got it in my head to put everything together. I'll list the steps that I took from a big ASCII file to the printed page.
Alternatively, if you're starting from an existing PDF (which is what I had to do, I had lost the LaTeX source) you can run pdftops to get to this step.
Run psbook -q -s 8 novel.ps > novel_bookorder.ps — this rearranges the postscript file so that pages are in the following order 8, 1, 2, 7, 6, 3, 4, and 5. The -s 8 means use a signature of size 8. This will be useful during the next step.
Run psnup -q -n 2 -p letter novel_bookorder.ps > novel_book.ps this puts two pages onto each 8.5x11 output page. Print the pages back to back. We will now have 4 pages on each sheet, two on the front and two on the back. The page will be in landscape orientation, but the printing will be side-by-side portrait. Coupled with the previous command we can now fold over two pages to form an 8-page signature
Combine the signatures (sewing, stapling, choose your method)
clamp the sewn signatures and run hot glue along the spine of the book, this would be the time to add a cover.
This should work reasonably well. Though I have not had much luck with staples, they seem to contribute too much thickness to the spine and make clamping awkward. Sewing would likely work much better but I don't have any good suggestions for technique.
If anyone is actually intending on installing dehexer, here is the manpage:
.\" Dehexer
.TH dehexer 1 "20 April 2008" "1.0" "dehexer"
.SH NAME
.B dehexer
is a simple program that converts a file of ascii characters into
the equivalent binary file. Any character not in the range 0-9 or
letters not A-F or a-f are simply ignored.
.SH EXAMPLES
dehexer <
.I ASCII_FILE
>
.I BINARY_FILE
.SH DESCRIPTION
dehexer is used to convert a human-readable (i.e. description of
the bytes) into an actual binary file. Thus we get "0a" is
transformed into the byte 00001010 on disk (of course, it would
actually be the bits themselves).
.SH OPTIONS
None, just do normal I/O redirection.
.SH FILES
.P
.I /usr/share/man/man1/dehexer.1.gz
.SH SEE ALSO
.BR hexer(1)
.SH BUGS
No known bugs at this time.
.SH AUTHOR
.nf
Chris Wilson (christopher.j.wilson@gmail.com)
This program is dedicated to the public domain.
.fi
.SH HISTORY
2008 - Written as a compliment to Hal Canary's hexer program.
I was looking through Hal's blog when I came across his hexer program. I thought that I should write the complimentary program, that is, given an ascii file of hex characters (e.g. "01CAFEBABE") it will write actual bytes to stdout.
It seems to work (I changed the name to 'helloworld' because doing
cat a.out | ./hexer | ./dehexer > a.out
seems to clobber the file in a bad way.
Without further ado:
/* dehexer - Convert an ascii file of hex characters into the
corresponding binary file. Any non-hex characters are silently
skipped (newlines, tabs, etc.)
Copyright 2008 Christopher Wilson, based in part on hexer by Hal
Canary (also DTPD)
Dedicated to the Public Domain */
/* cc -o dehexer dehexer.c */
#include
#include
int main (int argc, char *argv[])
{
char x;
int char_out = 0;
int low = 0; // LSBs, 1 for true
while (fread(&x, sizeof(x), 1, stdin) == 1) {
if (x > 47 && x < 58) {
// digit is 0-9
x = x - 48;
handle_byte(x, &char_out, low);
} else if (x > 64 && x < 71) {
// digit is A-F
x = x - 55;
handle_byte(x, &char_out, low);
} else if (x > 96 && x < 103) {
// digit a-f
x = x - 87;
handle_byte(x, &char_out, low);
} else {
// skip anything that isn't 0-9A-Z, or a-z
continue;
}
low = (low + 1) % 2; // flip the high/low bit marker
}
return(0);
}
/* handle_byte - if low is true then it prints the full byte. If low
is false, set char_out to 16 times x.
*/
int handle_byte(int x, char *char_out, int low)
{
if(low) {
*char_out += x;
putc(*char_out, stdout);
} else {
*char_out = x * 16;
}
return 0;
}
/* EOF */
A sciency type, but trying to branch out into other areas. After several years out in the science jungle, I'm headed back to school to see what I can make of the other side of the brain.