/****************************txt2vrml.c*********************************/ /* This program is written as a part of the "Cryptogram" project by */ /* Zoltan Szegedy-Maszak. If you create your own key from a 3D object */ /* by reducing its vertices to 256, and save it to a text file, with */ /* the "txt2vrml" program you can encrypt any text file to virtual */ /* "sculptures" (Cryptograms). You can use this program to decode any */ /* text from Cryptograms. */ /* The "keyfile" must be in pure ascii format, the vertex points */ /* should be separated with newline characters, and the X, Y */ /* and Z coordinates of each point with spaces. (See the cavalier.txt */ /* file for reference.) */ /* The program needs 3 arguments: the keyfile, the wrl-file to be */ /* decoded, and the filneme of the output (text-) filename. */ /* Example: txt2vrml key.txt message.wrl message.txt, where "key.txt" */ /* is the filename (with full path if not located in the same */ /* directory) of the keyfile with the vertices, "message.wrl" (with */ /* full path if not located in the same directory) is the filename */ /* of the "sculpture" to be decoded and "message.txt" is the output. */ /* ************* */ /* Created: 20-02-1996 Last modified: 29-04-1996 */ /* Author: Zoltan Szegedy-Maszak */ #define _MAX_PATH 255 #define EOL '\n' #include #include #include #include #include FILE *fopen(), *keyfile, *textfile, *vrmlfile; char line[64]; char vert[256][64]; static char vfile[_MAX_PATH], infile[_MAX_PATH], outfile[_MAX_PATH]; int i; void read_keyfile(); void decode(); void main(int argc, char *argv[]) { if(argc!=4) { fprintf(stderr,"error: missing or wrong arguments\n\nusage: \n vrml2txt keyfilename textfilename wrlfilename\n"); exit(1); } strcpy(vfile,argv[1]); strcpy(infile,argv[2]); strcpy(outfile,argv[3]); printf("keyfile: %s inputfile: %s outputfile: %s\n\nplease wait...\n\n",vfile,infile,outfile); read_keyfile(); decode(); printf("done..."); exit( 0 ); } void decode() { char str[] ="point [", str2[] ="]",str3[] ="coordIndex [", str4[] ="]"; char c=0,character[255],delimiter[]=","; char *token; int vertex[2],prevvert[2]; int numvertex=0; int corrupt=0; if ((vrmlfile=fopen(infile,"rt"))==NULL) { fprintf(stderr,"error opening keyfile: %s",vfile ); exit(1); } if ((textfile=fopen(outfile,"w"))==NULL) { fprintf(stderr,"error opening outputfile: %s",outfile); exit(1); } /*****************************vertices->used characters in the text***************************/ do { fgets(line,64,vrmlfile); if(strstr( line, str )) break; }while(!strstr(line,"EOF")); printf("Characters of the text:\n"); do { fgets(line,64,vrmlfile); for(i=0;i<256;i++) { if(strstr(line,vert[i])) { character[numvertex]=i; printf("%c",character[numvertex]); numvertex++; break; } } }while(!strstr(line, str2)); /********************************order of faces->order of characters=text******************************/ printf("\n\nThe decoded text:\n"); do { fgets(line,64,vrmlfile); if(strstr( line, str3 )) break; }while(!strstr(line,"EOF")); fgets(line,64,vrmlfile); token = strtok( line, delimiter ); vertex[0]=atoi(token); token = strtok( NULL, delimiter ); vertex[1]=atoi(token); token = strtok( NULL, delimiter ); vertex[2]=atoi(token); prevvert[0]=vertex[0];prevvert[1]=vertex[1]; fprintf(stderr,"%c%c",character[vertex[0]],character[vertex[1]]); fprintf(textfile,"%c%c",character[vertex[0]],character[vertex[1]]); while(!strstr(line, str4)) { printf("%c",character[vertex[2]]); fprintf(textfile,"%c",character[vertex[2]]); if (vertex[0]!=prevvert[0]) corrupt++; if (vertex[1]!=prevvert[1]) corrupt++; prevvert[0]=vertex[1];prevvert[1]=vertex[2]; fgets(line,64,vrmlfile); if(strstr(line, str4)) break; token = strtok( line, delimiter ); vertex[0]=atoi(token); token = strtok( NULL, delimiter ); vertex[1]=atoi(token); token = strtok( NULL, delimiter ); vertex[2]=atoi(token); } if(corrupt) { printf("\nWarning!\nThe wrl-file is corrupt or was not created by txt2vrml!\n %d mismatches found,\nI did my best, so all the work is ",corrupt); fprintf(textfile,"\nWarning!\nThe wrl-file is corrupt or was not created by txt2vrml using your key!\n %i mismatches found,\n I did my best...",corrupt); } else printf("\n\nWell "); fclose(textfile); fclose(vrmlfile); } void set_up_points() { } void read_keyfile() { char tmp[64]; if ((keyfile=fopen(vfile,"rt"))==NULL) { fprintf(stderr,"error opening keyfile: %s",vfile ); exit(1); } for(i=0;i<256;i++) { fgets(tmp,64,keyfile); /*reading lines and*/ strncpy(vert[i],tmp,strlen(tmp)-1); /*removing newlines*/ } fclose(keyfile); }