Update caesar chipher
This commit is contained in:
		
							parent
							
								
									e58fb770ad
								
							
						
					
					
						commit
						ca47a6a637
					
				| @ -1,4 +1,4 @@ | ||||
| #include "cesar.h" | ||||
| #include "caesar.h" | ||||
| 
 | ||||
| /*
 | ||||
| 	s -> path source | ||||
| @ -6,17 +6,18 @@ | ||||
| 	key -> key of encryption | ||||
| 	This function encrypt data | ||||
| */ | ||||
| int cryptCesar(const char *s, const int key, const int countCharact, char *bufferDst) { | ||||
| int cryptCaesar(const char *s, const int key, const int countCharact, char *bufferDst) { | ||||
| 	char *buffer; | ||||
| 	int i; | ||||
| 	int error = countCharact; | ||||
| 	char c = 0; | ||||
| 
 | ||||
| 	if(error == -1) return error; | ||||
| 
 | ||||
| 	/* Allocation dynamique */ | ||||
| 	buffer = malloc(countCharact + 1); /* + 1 for '\0' */ | ||||
| 
 | ||||
| 	/* Copy the data of file in the buffer[] */ | ||||
| 	/* Copy the data of file into the buffer[] */ | ||||
| 	error = copyFile(s, buffer); | ||||
| 	if(error != 0) return error; | ||||
| 
 | ||||
| @ -25,17 +26,13 @@ int cryptCesar(const char *s, const int key, const int countCharact, char *buffe | ||||
| 		int val = 0; | ||||
| 		/* For characters of A to Z */ | ||||
| 		if(buffer[i] >= 'A' && buffer[i] <= 'Z') { | ||||
| 			if(buffer[i] + key > 'Z') | ||||
| 				val = ((buffer[i] - 'A')-26) + key + 'A'; | ||||
| 			else | ||||
| 				val = (buffer[i] - 'A') + key + 'A'; | ||||
| 			c = buffer[i] - 'A'; | ||||
| 			val = ((c + key) % 26) + 'A'; | ||||
| 		} | ||||
| 		/* For characters of 'a' to 'z' */ | ||||
| 		else if(buffer[i] >= 'a' && buffer[i] <= 'z') { | ||||
| 			if(buffer[i] + key > 'z') | ||||
| 				val = ((buffer[i] - 'a')- 26) + key + 'A'; | ||||
| 			else | ||||
| 				val = (buffer[i] - 'a') + key + 'A'; | ||||
| 			c = buffer[i] - 'a'; | ||||
| 				val = ((c + key) % 26) + 'A'; | ||||
| 		} | ||||
| 		/* For others characters */ | ||||
| 		else val = buffer[i]; | ||||
| @ -56,7 +53,7 @@ int cryptCesar(const char *s, const int key, const int countCharact, char *buffe | ||||
| 	key -> key of decryption | ||||
| 	This function decryption by Cesar | ||||
| */ | ||||
| int decryptCesar(const char *s, const int key, const int countCharact, char *bufferDst) { | ||||
| int decryptCaesar(const char *s, const int key, const int countCharact, char *bufferDst) { | ||||
| 	int error = countCharact; | ||||
| 	char *buffer; | ||||
| 	int i; | ||||
| @ -67,7 +64,7 @@ int decryptCesar(const char *s, const int key, const int countCharact, char *buf | ||||
| 	/* Allocation dynamique */ | ||||
| 	buffer = malloc(countCharact + 1); /* +1 for '\0' */ | ||||
| 
 | ||||
| 	/* Copy the data from file to buffer */ | ||||
| 	/* Copy the data from file into buffer */ | ||||
| 	error = copyFile(s, buffer); | ||||
| 	if(error != 0) return error; | ||||
| 
 | ||||
							
								
								
									
										12
									
								
								caesar.h
									
									
									
									
									
										Executable file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										12
									
								
								caesar.h
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,12 @@ | ||||
| #ifndef H_INFLATE | ||||
| #define H_INFLATE | ||||
| 
 | ||||
| #define SIZE_MAX_FILE 8192 | ||||
| 
 | ||||
| #include "functions.h" | ||||
| 
 | ||||
| /* Functions */ | ||||
| int cryptCaesar(const char *s, const int key, const int countCharact, char *bufferDst); | ||||
| int decryptCaesar(const char *s, const int key, const int countCharact, char *bufferDst); | ||||
| 
 | ||||
| #endif | ||||
							
								
								
									
										13
									
								
								cesar.h
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										13
									
								
								cesar.h
									
									
									
									
									
								
							| @ -1,13 +0,0 @@ | ||||
| #ifndef H_INFLATE | ||||
| #define H_INFLATE | ||||
| 
 | ||||
| #define SIZE_MAX_FILE 8192 | ||||
| 
 | ||||
| #include "functions.h" | ||||
| 
 | ||||
| /* Functions */ | ||||
| void inflate(); | ||||
| int cryptCesar(const char *s, const int key, const int countCharact, char *bufferDst); | ||||
| int decryptCesar(const char *s, const int key, const int countCharact, char *bufferDst); | ||||
| 
 | ||||
| #endif | ||||
							
								
								
									
										2
									
								
								exec.sh
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								exec.sh
									
									
									
									
									
								
							| @ -1,3 +1,3 @@ | ||||
| #!/bin/sh | ||||
| 
 | ||||
| gcc -W main.c functions.c cesar.c vigenere.c -o main && ./main $1 $2 $3 $4 | ||||
| gcc -W main.c functions.c caesar.c vigenere.c -o main && ./main $1 $2 $3 $4 | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								main
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										
											BIN
										
									
								
								main
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										7
									
								
								main.c
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										7
									
								
								main.c
									
									
									
									
									
								
							| @ -1,5 +1,5 @@ | ||||
| #include "functions.h" | ||||
| #include "cesar.h" | ||||
| #include "caesar.h" | ||||
| #include "vigenere.h" | ||||
| 
 | ||||
| int main(int argc, char *argv[]) { | ||||
| @ -71,6 +71,7 @@ int main(int argc, char *argv[]) { | ||||
| 	buffer = malloc(sizeof(int) * numberCharacters); | ||||
| 	memset(buffer, 0, sizeof(int) * numberCharacters); | ||||
| 
 | ||||
|   // Caesar cipher
 | ||||
| 	if(strcmp(argv[1], "-c") == 0){ | ||||
| 		// Get key
 | ||||
| 		int key; | ||||
| @ -81,9 +82,9 @@ int main(int argc, char *argv[]) { | ||||
| 		}while(key < 1 || key > 26); | ||||
| 
 | ||||
| 		if(strcmp(hook, "crypt") == 0) | ||||
| 			error = cryptCesar(fileSrc, key, numberCharacters, buffer); | ||||
| 			error = cryptCaesar(fileSrc, key, numberCharacters, buffer); | ||||
| 		if(strcmp(hook, "decrypt") == 0) | ||||
| 			error = decryptCesar(fileSrc, key, numberCharacters, buffer); | ||||
| 			error = decryptCaesar(fileSrc, key, numberCharacters, buffer); | ||||
| 	} | ||||
| 	else if(strcmp(argv[1], "-v") == 0){ | ||||
| 		// Get key
 | ||||
|  | ||||
| @ -0,0 +1,2 @@ | ||||
| JGNNQ YQTNF! | ||||
| LG UWKU WP OGUUCIG GP ENCKT !! | ||||
| @ -1,2 +0,0 @@ | ||||
| HELLO WORLD! | ||||
| JE SUIS UN MESSAGE EN CLAIR !! | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user