Accueil > > > CRYPTAGE
CRYPTAGE
Information sur la source
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
Commentaires et avis
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
WIN APIWIN API par omarino_007
Cliquez pour lire la suite par omarino_007
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|