void writeKeys(Keys key){
	
	FILE * fp;
	char out[50],out1[50];
	
	do{
		printf("Enter your name: ");
		scanf("%s",out);
		myFlush();
		printf("\nPlease re-enter your name to confirm: ");
		scanf("%s",out1);
		myFlush();
	}while(strcmp(out,out1) != 0? printf("\nNames do not match.\n"):0);

	char* priv = strcat(out,"_priv.txt");
	char* pub = strcat(out1,"_pub.txt");
	
	fp = fopen (priv, "w+");
	fprintf(fp,"%d;%d",key.n,key.d);
	fclose(fp);
	
	fp = fopen (pub, "w+");
	fprintf(fp,"%d;%d",key.n,key.e);
	fclose(fp);

}
Beispiel #2
0
void CallMethod( vtkOBJ_TYPE *O , char *met , real v ){
  /*Real valued methods*/
  Call_1( SetOperation   	     , v );
  Call_1( SetReorientDifferenceCells , v);
  Call_1( SetTolerance   	     , v );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
Beispiel #3
0
void CallMethod( vtkOBJ_TYPE *O , char *met ){
  /*[]-valued methods*/
  Call_0( ________________ );
  Call_0( ________________ );
  Call_0( ________________ );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
Beispiel #4
0
void CallMethod( vtkOBJ_TYPE *O , char *met , char *v ){
  /*String valued methods*/
  Call_1( ________________   , v );
  Call_1( ________________   , v );
  Call_1( ________________   , v );	
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush(); 
}
void encryptBin(){
	
	Keys key = readPubKey();
	FILE* fp;

	int* arr;
	size_t size;
	
	printf("File name to encrypt: ");
	char* name;
	scanf("%s",name);
	myFlush();
	

	if(fp = fopen(name,"rb")){
		
		arr = readBin(fp,&size,name);
		encryptBytes(arr, size, key);
		
		writeToFile(arr, size,'b');
		free(arr);
	}else{
		printf("Error reading %s", name);
	}
	
	Keys empty = {0};
	key = empty;
	menu();
	
}
Keys readPrivKey(){
	
	FILE* fp;
	Keys key;
	char name[100], in[100];
	size_t size;
		
	printf("Name of private key file you would like to use(e.g. xxx_priv.txt): ");
	scanf("%s",name);
	myFlush();
	
	if(fp = fopen(name, "r")){
		fseek(fp,0,SEEK_END);
		size = ftell(fp);
		rewind(fp);
		size_t ret_code = fread(in, 1, size, fp);
		if(ret_code==size){
			const char tok[2] = ";";
			char* token = strtok(in, tok);
			key.n = atoi(token);
			token = strtok(NULL,tok);
			key.d = atoi(token);
			return key;
		}else{
			printf("\nError reading file %s\n", name);
			readPrivKey();
		}
	}else{
		printf("\nError reading file %s\n", name);
		readPrivKey();
	}
	
}
void writeToFile(int* C,int size, char type){
	
	FILE * fp;
	char name[50];
	
	printf("\nEnter output file name: ");
	scanf("%s",name);
	myFlush();
	
	if(type == 'b'){
		fp = fopen (name, "wb");
		
		for(int i = 0; i < size; i++){
			fprintf(fp,"%d;",C[i]);
		}
		
		fclose(fp);
	}else{
		fp = fopen (name, "w");
		
		for(int i = 0; i < size; i++){
			fprintf(fp,"%d;",C[i]);
		}
		
		fclose(fp);
	}
	
}
Beispiel #8
0
void CallMethod( vtkOBJ_TYPE *O , char *met ) {
    Call_0( AddCubeVertexPlanes         );
    Call_0( AddCubeEdgePlanes           );
    Call_0( AddCubeFacePlanes           );
    mexWarnMsgTxt("Invalid Method: ");
    mexPrintf(" %s\n", met );
    myFlush();
}
Beispiel #9
0
void CallMethod( vtkOBJ_TYPE *O , char *met ){
  /*[]-valued methods*/
  Call_0( SetOperationToUnion 	     );
  Call_0( SetOperationToIntersection );
  Call_0( SetOperationToDifference   );
  Call_0( ReorientDifferenceCellsOn  );
  Call_0( ReorientDifferenceCellsOff );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
Beispiel #10
0
void CallMethod( vtkOBJ_TYPE *O , char *met , real v ){
  Call_1( SetBoundaryEdges      , v );
  Call_1( SetFeatureEdges       , v );
  Call_1( SetFeatureAngle       , v );
  Call_1( SetNonManifoldEdges   , v );
  Call_1( SetColoring           , v );
  Call_1( SetManifoldEdges      , v );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
void CallMethod( vtkOBJ_TYPE *O , char *met , real v ){
  Call_1( SetFeatureAngle         , v );
  Call_1( SetSplitting            , v );
  Call_1( SetConsistency          , v );
  Call_1( SetAutoOrientNormals    , v );
  Call_1( SetComputePointNormals  , v );
  Call_1( SetComputeCellNormals   , v );
  Call_1( SetFlipNormals          , v );
  Call_1( SetNonManifoldTraversal , v );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
Beispiel #12
0
void CallMethod( vtkOBJ_TYPE *O , char *met ){
  Call_0( PreserveTopologyOn        );
  Call_0( PreserveTopologyOff       );
  Call_0( SplittingOn               );
  Call_0( SplittingOff              );
  Call_0( PreSplitMeshOn            );
  Call_0( PreSplitMeshOff           );
  Call_0( AccumulateErrorOn         );
  Call_0( AccumulateErrorOff        );
  Call_0( BoundaryVertexDeletionOn  );
  Call_0( BoundaryVertexDeletionOff );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
Beispiel #13
0
void CallMethod( vtkOBJ_TYPE *O , char *met ){
  Call_0( ManifoldEdgesOn       );
  Call_0( ManifoldEdgesOff      );
  Call_0( ColoringOn            );
  Call_0( ColoringOff           );
  Call_0( NonManifoldEdgesOn    );
  Call_0( NonManifoldEdgesOff   );
  Call_0( FeatureEdgesOn        );
  Call_0( FeatureEdgesOff       );
  Call_0( BoundaryEdgesOn       );
  Call_0( BoundaryEdgesOff      );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
void menu() {
	
	int choice;
	

	do{
		printf("\n--------------------------------------------------------------\n");
		printf("\nAction Menu:\n1. Create a key pair\n2. Encrypt Message\n3. Encrypt Binary File\n4. Decrypt Message\n5. Decrypt Binary File\n6. Exit\nYour choice: ");
		scanf("%d", &choice);
		myFlush();
		printf("\n--------------------------------------------------------------\n");
	}while(choice < 1 || choice > 6);
	(choice == 1)? genKey() : (choice == 2) ? encrypt() :  (choice == 3) ? encryptBin() : (choice == 4) ? decrypt() : (choice == 5) ? decryptBin() : (choice == 6 ) ? printf("Goody Bye.") : 0;

}
Beispiel #15
0
void CallMethod( vtkOBJ_TYPE *O , char *met , real v ){
  Call_1( SetTargetReduction        , v );
  Call_1( SetPreserveTopology       , v );
  Call_1( SetFeatureAngle           , v );
  Call_1( SetSplitting              , v );
  Call_1( SetSplitAngle             , v );
  Call_1( SetPreSplitMesh           , v );
  Call_1( SetMaximumError           , v );
  Call_1( SetAccumulateError        , v );
  Call_1( SetErrorIsAbsolute        , v );
  Call_1( SetAbsoluteError          , v );
  Call_1( SetBoundaryVertexDeletion , v );
  Call_1( SetDegree                 , v );
  Call_1( SetInflectionPointRatio   , v );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
void CallMethod( vtkOBJ_TYPE *O , char *met ){
  Call_0( SplittingOn               );
  Call_0( SplittingOff              );
  Call_0( ConsistencyOn             );
  Call_0( ConsistencyOff            );
  Call_0( AutoOrientNormalsOn       );
  Call_0( AutoOrientNormalsOff      );
  Call_0( ComputePointNormalsOn     );
  Call_0( ComputePointNormalsOff    );
  Call_0( ComputeCellNormalsOn      );
  Call_0( ComputeCellNormalsOff     );
  Call_0( FlipNormalsOn             );
  Call_0( FlipNormalsOff            );
  Call_0( NonManifoldTraversalOn    );
  Call_0( NonManifoldTraversalOff   );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush();
}
void writeDeBin(int* C, int size){
	
	FILE * fp;
	char name[50];
	
	printf("\nEnter output file name: ");
	scanf("%s",name);
	myFlush();
	
	fp = fopen (name, "wb");
	
	for(int i = 0; i < size; i++){
		fprintf(fp,"%c",C[i]);
	}
	
	fclose(fp);
}
//===========================Function by Jia Hao, mostly decryption====================================
Keys readPrivKey2(){
	
	size_t size; //store the size of the stream of file, declare outside so others can use
	
	//get the private key file
	char name[100];
	printf("\nName of private key file you would like to use(e.g. xxx_priv.txt): ");
	scanf("%s",name);
	myFlush();
	
	//open it
	FILE* fp;
	Keys key;
	key.n = 0;
	key.d = 0;
	
	if(fp = fopen(name,"r")){ //open the file in read mode, if it exists do these
		
		//get total size of the stream
		fseek(fp, 0, SEEK_END); //seek the stream of fp, from o, to the end of stream
		size = ftell(fp); //stores how many character are in the sream, including the EOF, each chara is 1 byte
		
		rewind(fp); //rewind so won't get segment fault
		
		//using token, split the n and d of the Key
		char in[100];
		fread(in, 1, size, fp);
		const char tok[2] = ";";
		char* token = strtok(in, tok);
		key.n = atoi(token);
		token = strtok(NULL, tok);
		key.d = atoi(token);
		fclose(fp);
		return key;
		
	}else{
		fclose(fp);
		printf("\nError reading file \"%s\"\n", name);
		//return key;
		readPrivKey2();
		
	}
	return key;
	
}
char* getEncryptedFileName(){
	//get encrypted file
	static char name[100]; //need to defind as static as C don't allow the return of the address of a local variable to outside of the function
	printf("\nName of encrypted file you would like to decrypt(e.g. abc.txt): ");
	scanf("%s",name);
	myFlush();
	
	FILE* fp;
	
	if(fp = fopen(name, "r")){
		fclose(fp);
		return name;
	}else{
		printf("Error reading file \"%s\"\n",name);
		fclose(fp);
		getEncryptedFileName();
	}
	
}
Beispiel #20
0
void CallMethod( vtkOBJ_TYPE *O , char *met , real *v ){
//   Call_1( SetFileName                 , v );
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush(); 
}
Beispiel #21
0
void CallMethod( vtkOBJ_TYPE *O , char *met , real *v ){
  /*Array valued methods*/
  mexWarnMsgTxt("Invalid Method: "); mexPrintf(" %s\n", met ); myFlush(); 
}
Beispiel #22
0
void CallMethod( vtkOBJ_TYPE *O , char *met , real v ) {
    Call_1( AddRecursiveSpherePlanes       , v );
    mexWarnMsgTxt("Invalid Method: ");
    mexPrintf(" %s\n", met );
    myFlush();
}
Beispiel #23
0
void CallMethod( vtkOBJ_TYPE *O , char *met , real *v ) {
    Call_1( AddPlane                       , v );
    mexWarnMsgTxt("Invalid Method: ");
    mexPrintf(" %s\n", met );
    myFlush();
}