begin process at 2010 02 10 00:55:51
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Sécurité & Cryptage

 > CRYPTAGE

CRYPTAGE


 Information sur la source

Note :
Aucune note
Catégorie :Sécurité & Cryptage Niveau :Débutant Date de création :04/11/2004 Date de mise à jour :04/11/2004 10:53:09 Vu :4 215

Auteur : cgmorpheus

Ecrire un message privé
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

Et bien c'est tout simple. C'est un programme en C ANSI (console dos) qui crypte le fichier passer en argument.
Le cryptage utilise une clé et la fonction "pseudo aléatoire". En clair chaque caractères de votre fichier subbit une inversion de bit avec un caractère pris "au hasard" dans votre mot de passe.
Ca peut paraît dangereux mais y a pas de soucis on retrouvera toujours son fichier une fois décrypter, enfin si on se trompe pas de password parceque dans ce cas là je vous souhaite bien du courage pour retrouver votre fichier.

Source

  • #include <stdio.h>
  • #include <stdlib.h>
  • #include <string.h>
  • #include <time.h>
  • #include <conio.h>
  • struct trans
  • {
  • char o_chemin[256];
  • char o_fichier[256];
  • char dest_chemin[256];
  • char dest_fichier[256];
  • };
  • long fsize(FILE*);
  • void transfert(struct trans *,int );
  • int decrypt(int ,int );
  • int crypt(int ,int );
  • int main(int argc, char **argv)
  • {
  • int T_char;
  • int reper = 0;
  • int i;
  • char fichier[256];
  • char chemin[256];
  • struct trans *tr;
  • char choix;
  • if(argc==2)
  • {
  • /* décompose l'adresse du fichier en 2 */
  • /* son Chemin dans "chemin" et son nom dans "fichier" */
  • strcpy(fichier,argv[1]);
  • T_char = strlen(fichier);
  • while(fichier[T_char-(++reper)] != 92); /* != '\' */
  • reper--;
  • strncpy(chemin,fichier,T_char-reper);
  • chemin[T_char-reper] = '\0';
  • i = reper;
  • while(fichier[T_char-reper-1] != '\0')
  • fichier[i-reper] = fichier[T_char-(reper--)];
  • /**********************************************************************************/
  • /* définir la structure trans pour le cryptage */
  • tr = (struct trans*)malloc(1 * sizeof(struct trans));
  • strcpy(tr->o_chemin,chemin);
  • strcpy(tr->o_fichier,fichier);
  • strcpy(tr->dest_chemin,chemin);
  • strcpy(tr->dest_fichier,"cryp_");
  • strcat(tr->dest_fichier,fichier);
  • /**********************************************************************************/
  • printf("\n\n");
  • printf("\t\tÉÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n");
  • printf("\t\tº 1 º Crypter le fichier º\n");
  • printf("\t\tÌÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n");
  • printf("\t\tº 2 º Decrypter le fichier º\n");
  • printf("\t\tÈÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n\n\n");
  • do
  • {
  • printf("Entrez votre choix : ");
  • scanf("%c", &choix);
  • printf("\n\n\n",choix);
  • }while((choix!='1') && (choix!='2'));
  • fflush(stdin);
  • transfert(tr, choix);
  • }
  • return(EXIT_SUCCESS);
  • }
  • void transfert(struct trans *ploc,int choix)
  • {
  • char pwd[128];
  • char pwd2[128];
  • int T_char;
  • char origin[256];
  • char dest[256];
  • long oct = 0;
  • long size = 0;
  • int c;
  • int i = 0;
  • FILE *fcopier = NULL;
  • FILE *fcoller = NULL;
  • time_t start, finish;
  • double durer;
  • do
  • {
  • printf("\n\tVeuillez entrer votre mot de passe : ");
  • fgets(pwd,128,stdin);
  • printf("\tConfirmer votre mot de passe : ");
  • fgets(pwd2,128,stdin);
  • }while(strcmp(pwd,pwd2)!=0);
  • T_char=strlen(pwd);
  • strcpy(origin,ploc->o_chemin);
  • strcat(origin,ploc->o_fichier);
  • strcpy(dest,ploc->dest_chemin);
  • strcat(dest,ploc->dest_fichier);
  • printf("%s\n",dest);
  • start = time(NULL);
  • fcoller=fopen(dest,"wb");
  • fcopier=fopen(origin,"rb");
  • size = fsize(fcopier);
  • switch(choix)
  • {
  • case '1':
  • printf("\n\n\t\tCRYPTAGE\n\n");
  • while((c = getc(fcopier)) != EOF)
  • {
  • c = crypt(c,pwd[rand() % T_char]);
  • putc(c,fcoller);
  • if(oct++%(size/100) == 0)
  • printf("%d%%\r",i++);
  • }
  • break;
  • case '2':
  • printf("\n\n\t\tDECRYPTAGE\n\n");
  • while((c = getc(fcopier)) != EOF)
  • {
  • c = decrypt(c,pwd[rand() % T_char]);
  • putc(c,fcoller);
  • if(oct++%(size/100) == 0)
  • printf("%d%%\r",i++);
  • }
  • break;
  • }
  • printf("\n");
  • fclose(fcopier);
  • fclose(fcoller);
  • finish = time(NULL);
  • durer = difftime(finish,start);
  • printf("%d octect en %.0f secondes\n\n",size,durer);
  • system("pause");
  • remove(origin);
  • rename(dest,origin);
  • }
  • /*taille du fichier (binaire, pas texte) */
  • long fsize(FILE* fd)
  • {
  • long savepos, size;
  • savepos = ftell(fd); /* sauvegarder la position */
  • fseek(fd, 0, SEEK_END); /* aller en fin */
  • size = ftell(fd); /* lire la taille */
  • fseek(fd, savepos, SEEK_SET); /* rétablir la position */
  • return size;
  • }
  • int crypt(int c,int d)
  • {
  • return(d^c);
  • }
  • int decrypt(int c, int d)
  • {
  • return(d^c);
  • }
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <conio.h>

struct trans
{
	char o_chemin[256];
	char o_fichier[256];
	char dest_chemin[256];
	char dest_fichier[256];
};

long fsize(FILE*);
void transfert(struct trans *,int );
int decrypt(int ,int );
int crypt(int ,int );

int main(int argc, char **argv)
{
	int T_char;
	int reper = 0;
	int i;
	char fichier[256];
	char chemin[256];
	struct trans *tr;
	char choix;

	if(argc==2)
	{
		/* décompose l'adresse du fichier en 2 */
		/* son Chemin dans "chemin" et son nom dans "fichier" */
		strcpy(fichier,argv[1]);
		T_char = strlen(fichier);
		while(fichier[T_char-(++reper)] != 92);	/* != '\'	*/
		reper--;
		strncpy(chemin,fichier,T_char-reper);
		chemin[T_char-reper] = '\0';
		i = reper;
		while(fichier[T_char-reper-1] != '\0')
			fichier[i-reper] = fichier[T_char-(reper--)];
/**********************************************************************************/
		/* définir la structure trans pour le cryptage */
		tr = (struct trans*)malloc(1 * sizeof(struct trans));
		strcpy(tr->o_chemin,chemin);
		strcpy(tr->o_fichier,fichier);
		strcpy(tr->dest_chemin,chemin);
		strcpy(tr->dest_fichier,"cryp_");
		strcat(tr->dest_fichier,fichier);
/**********************************************************************************/
		printf("\n\n");
		printf("\t\tÉÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n");
		printf("\t\tº   1   º    Crypter le fichier    º\n");
		printf("\t\tÌÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n");
		printf("\t\tº   2   º   Decrypter le fichier   º\n");
		printf("\t\tÈÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n\n\n");

		do
		{
			printf("Entrez votre choix : ");
			scanf("%c", &choix);
			printf("\n\n\n",choix);
		}while((choix!='1') && (choix!='2'));

		fflush(stdin);
		transfert(tr, choix);
	}
	return(EXIT_SUCCESS);
}

void transfert(struct trans *ploc,int choix)
{
	char pwd[128];
	char pwd2[128];
	int T_char;
	char origin[256];
	char dest[256];
	long oct = 0;
	long size = 0;
	int c;
	int i = 0;
	FILE *fcopier = NULL;
	FILE *fcoller = NULL;
	time_t start, finish;
	double durer;
	do
	{
		printf("\n\tVeuillez entrer votre mot de passe : ");
		fgets(pwd,128,stdin);
		printf("\tConfirmer votre mot de passe : ");
		fgets(pwd2,128,stdin);
	}while(strcmp(pwd,pwd2)!=0);
	T_char=strlen(pwd);

	strcpy(origin,ploc->o_chemin);
	strcat(origin,ploc->o_fichier);
	strcpy(dest,ploc->dest_chemin);
	strcat(dest,ploc->dest_fichier);
	printf("%s\n",dest);
	start = time(NULL);
	fcoller=fopen(dest,"wb");
	fcopier=fopen(origin,"rb");
	size = fsize(fcopier);
	switch(choix)
	{
	case '1':
		printf("\n\n\t\tCRYPTAGE\n\n");
		while((c = getc(fcopier)) != EOF)
		{
			c = crypt(c,pwd[rand() % T_char]);
			putc(c,fcoller);
			if(oct++%(size/100) == 0)
				printf("%d%%\r",i++);
		}
		break;
	case '2':
		printf("\n\n\t\tDECRYPTAGE\n\n");
		while((c = getc(fcopier)) != EOF)
		{
			c = decrypt(c,pwd[rand() % T_char]);
			putc(c,fcoller);
			if(oct++%(size/100) == 0)
				printf("%d%%\r",i++);
		}
		break;
	}
	printf("\n");
	fclose(fcopier);
	fclose(fcoller);
	finish = time(NULL);
	durer = difftime(finish,start);
	printf("%d octect en %.0f secondes\n\n",size,durer);
	system("pause");
	remove(origin);
	rename(dest,origin);
}

/*taille du fichier (binaire, pas texte) */
long fsize(FILE* fd)
{
	long savepos, size;

	savepos = ftell(fd); /* sauvegarder la position */
	fseek(fd, 0, SEEK_END); /* aller en fin */
	size = ftell(fd); /* lire la taille */
	fseek(fd, savepos, SEEK_SET); /* rétablir la position */
	return size; 
}

int crypt(int c,int d)
{
	return(d^c);
}

int decrypt(int c, int d)
{
	return(d^c);
}

 Conclusion

Le code est un peu brouillon mais pour ma défence c'est l'un de mes premier code alors je testais souvent plusieurs truc dans un programme, mais bon ça marche.
Il y a aussi un menu "Crypter/DECRYPTER" au cas ou je trouverai une autre manière de crypter mais en faite non : la fonction crypt() et decrypt sont identique. Comme le code est assez simple vous devriez pas avoir de soucis pour le modifier.
En faite pour la petit astuce j'ai mis le prog dans "%USERPROFILE%\SendTo" ça simplifie encore plus les chose.


 Historique

04 novembre 2004 10:53:10 :
petit erreur j'avais mis "if(argc>1)" alors que le prog ne traite qu'un seul fichier

 Sources de la même categorie

Source avec Zip Source avec une capture CRYPTEUR-DÉCRYPTEUR-IP par antho974
Source avec Zip Source avec une capture ELGAMALCIPHER par CHAR As Human
Source avec Zip CRYPTER-DECRYPTER EN UTILISANT L'ALGORITHME DE CESAR par Antoinejdu44
Source avec Zip CRYPT-O-MATIC "DARKCHOCOLATE" par FrancoisGauthier
Source avec Zip CREEP SECURITY ALGORITHM par nanonavich

Commentaires et avis

Commentaire de Saros le 05/11/2004 21:10:50

Il y a un truc que je ne comprend pas :
si tu utilises rand() dans ta procédure de cryptage (enfin dans ta boucle), comment tu peux être sûr, en introduisant le [pseudo-]hasard, que tu vas décrypter de manière correcte le message ?
Merci d'avance

Commentaire de Saros le 05/11/2004 21:12:24

En fait je viens de lire la description de ton prog (c'est un peu tard je sais ^^), mais je vois toujours pas pourquoi...

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,452 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales