diff options
Diffstat (limited to 'ws2a/gencaptcha.c')
| -rw-r--r-- | ws2a/gencaptcha.c | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/ws2a/gencaptcha.c b/ws2a/gencaptcha.c deleted file mode 100644 index cc57651..0000000 --- a/ws2a/gencaptcha.c +++ /dev/null @@ -1,91 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -//convert label.png -virtual-pixel White -distort Arc 60 arctest.png - -//convert -background gray -fill cyan -pointsize 72 label:Alex label.png - -//convert label.png -virtual-pixel white -distort Barrel "0.2 0.0 0.0 1.0" barrel.png -#define ADJNUM 200 -#define NOUNUM 1524 -#define AVGADJ 7 -#define AVGNOU 7 -#define LONGADJ 14 -#define LONGNOU 15 - -void createRandomWords(char* buf){ - long adjnum = rand() % ADJNUM; - long nounum = rand() % NOUNUM; - FILE* adjfile; - FILE* noufile; - adjfile = fopen("../ws2a/adj.txt","r"); - noufile = fopen("../ws2a/nouns.txt","r"); - //Instead of getting a particular line, seek an average length, and find the next word. - if(adjfile == NULL || noufile == NULL){ - printf("Something has gone serirously wrong!"); - } - fseek(adjfile,adjnum*AVGADJ,0); - fseek(noufile,nounum*AVGNOU,0); - - while(fgetc(adjfile) != '\n'){} - while(fgetc(noufile) != '\n'){} - int pos = 0; - char tchar = fgetc(adjfile); - do{ - buf[pos] = tchar; - pos++; - tchar = fgetc(adjfile); - }while(tchar != '\n'); - buf[pos] = ' '; - pos++; - tchar = fgetc(noufile); - do{ - buf[pos] = tchar; - pos++; - tchar = fgetc(noufile); - }while(tchar != '\n'); - buf[pos] = '\0'; -} - - -unsigned long hash(unsigned char *str){ - unsigned long hash = 5381; - int c; - - while (c = *str++) - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - - return hash; -} - -int main(){ - - srand(time(NULL)); - char randwords[LONGADJ+LONGNOU+1]; - createRandomWords(randwords); - - int barraldis1 = rand()%10; - int barraldis2 = rand()%10; - int arcdis = (rand()%45)+45; - char command[1024]; - unsigned long rhash = hash(randwords); - sprintf(command,"convert -background white -fill black -pointsize 48 label:\"%s\" \"../ws2a/captchas/%lu.png\"",randwords,rhash); - system(command); - sprintf(command,"convert \"../ws2a/captchas/%lu.png\" -distort Barrel \"0.0%d 0.0 0.0%d\" \"../ws2a/captchas/%lu.png\"",rhash,barraldis1,barraldis2,rhash); - system(command); - sprintf(command,"convert \"\"../ws2a/captchas/%lu.png\" -virtual-pixel White -distort Arc %d \"../ws2a/captchas/%lu.png\"",rhash,arcdis,rhash); - system(command); - - printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); - printf("%lu",rhash); - - FILE* tfile; - char filepath[100]; - sprintf(filepath,"../ws2a/captchas/%s.txt",randwords); - tfile = fopen(filepath,"w"); - fprintf(tfile,"%lu",rhash); - fclose(tfile); - - return 0; -} |
