/****************************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 */ /* this program you can encrypt any text file to virtual "sculptures" */ /* (Cryptograms). To decode the encrypted text one has to have your */ /* "key-file", and the program "vrml2txt". */ /* 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 textfile to be */ /* encrypted, and the filneme of the output (vrml-) filename. */ /* Example: txt2vrml key.txt message.txt message.wrl, where "key.txt" */ /* is the filename (with full path if not located in the same */ /* directory) of the keyfile with the vertices, "message.txt" (with */ /* full path if not located in the same directory) containing the */ /* text to be encrypted and "message.wrl" is the output-file. */ /* ************* */ /* 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; int i,f; int tpoint[256]; static char vfile[_MAX_PATH], infile[_MAX_PATH], outfile[_MAX_PATH]; char vert[256][64]; char c=0; int numvertex; void set_up_points(); void write_vrmlfile(); void read_keyfile(); void main(int argc, char *argv[]) { if(argc!=4) { fprintf(stderr,"error: missing or wrong arguments\n\nusage: \n txt2vrml \n"); fprintf(stderr,"example: txt2vrml key.txt message.txt message.wrl\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, encrypting...\n\n",vfile,infile,outfile); read_keyfile(); set_up_points(); write_vrmlfile(); exit( 0 ); } void write_vrmlfile() { int facevert[2]; if ((vrmlfile=fopen(outfile,"w"))==NULL) { fprintf(stderr,"error opening outputfile: %s",outfile); exit(1); } fprintf(vrmlfile,"#VRML V1.0 ascii\n"); fprintf(vrmlfile,"\n"); fprintf(vrmlfile,"Separator { \n"); fprintf(vrmlfile," \tDirectionalLight{ \n"); fprintf(vrmlfile," \t \tdirection 0 0 -1 \n"); fprintf(vrmlfile," \t \t \t} \n"); fprintf(vrmlfile," \tDirectionalLight{ \n"); fprintf(vrmlfile," \t \tdirection 0 0 1 \n"); fprintf(vrmlfile," \t \t \t} \n"); fprintf(vrmlfile,"\n"); fprintf(vrmlfile,"PerspectiveCamera { \n"); fprintf(vrmlfile," \t \tposition 0 3 600 \n"); fprintf(vrmlfile," \t \torientation 0 0 1 0 \n"); fprintf(vrmlfile," \t \tfocalDistance 10 \n"); fprintf(vrmlfile," \t \theightAngle 0.78 \n"); fprintf(vrmlfile," \t \t} \n"); fprintf(vrmlfile,"\n"); fprintf(vrmlfile," \tSeparator { \n"); fprintf(vrmlfile," \t \tCoordinate3 { \n"); fprintf(vrmlfile," \t \t \tpoint [ \n \t \t \t \t"); /***********************************points********************************/ for (f=0;fnumvertex) { tpoint[numvertex]=i; numvertex=numvertex + 1; } } while(c!=EOF); fclose(textfile); } void read_keyfile() { char tmp[64]=""; /*****************************************************reading keyfile***************/ 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*/ strncpy(vert[i],tmp,strlen(tmp)-1); /*and removing newlines*/ } fclose(keyfile); /* for (f=0;f<256;f++) { printf("%d=%s\n",f,vert[f]); } */ }