summaryrefslogtreecommitdiff
path: root/ws2a/gencaptcha.c
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-05-10 13:18:51 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-05-10 13:18:51 -0400
commit3b86442432c407c7e0ea5cdbc26b7bbc8bdb0cf8 (patch)
treeee54d95135e7d0f9e59ccd6065434a60a4889a05 /ws2a/gencaptcha.c
parent63afc7fa94363bb22f90a58fcb15e13f1fe88505 (diff)
downloadwebpage-3b86442432c407c7e0ea5cdbc26b7bbc8bdb0cf8.tar.gz
webpage-3b86442432c407c7e0ea5cdbc26b7bbc8bdb0cf8.tar.bz2
webpage-3b86442432c407c7e0ea5cdbc26b7bbc8bdb0cf8.zip
Created captcha generator
Diffstat (limited to 'ws2a/gencaptcha.c')
-rw-r--r--ws2a/gencaptcha.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/ws2a/gencaptcha.c b/ws2a/gencaptcha.c
index 74a7e96..850cca7 100644
--- a/ws2a/gencaptcha.c
+++ b/ws2a/gencaptcha.c
@@ -1,16 +1,73 @@
#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';
+}
int main(){
+ srand(time(NULL));
+ char randwords[LONGADJ+LONGNOU+1];
+ createRandomWords(randwords);
+
+ int barraldis1 = rand()%10;
+ int barraldis2 = rand()%10;
+ int arcdis = rand()%100;
+ char command[1024];
+ sprintf(command,"convert -background white -fill black -pointsize 48 label:\"%s\" \"../ws2a/captchas/%s.png\"",randwords,randwords);
+ system(command);
+ sprintf(command,"convert \"../ws2a/captchas/%s.png\" -distort Barrel \"0.0%d 0.0 0.0%d\" \"../ws2a/captchas/%s.png\"",randwords,barraldis1,barraldis2,randwords);
+ system(command);
+ sprintf(command,"convert \"../ws2a/captchas/%s.png\" -virtual-pixel White -distort Arc %d \"../ws2a/captchas/%s.png\"",randwords,arcdis,randwords);
+ system(command);
+
FILE* imgfile;
- imgfile = fopen("../ws2a/testcaptcha.png","r");
+ char filepath[100];
+ sprintf(filepath,"../ws2a/captchas/%s.png","r");
+ imgfile = fopen(filepath,"r");
if(imgfile == NULL){
return 1;
}