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
CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET IIS7 - COMPRESSION GZIPIIS7 - COMPRESSION GZIP par cyril
La compression GZIP permet d'améliorer les performances de navigation en compressant ce qu'envoie le serveur à un client. Pour comprendre comment cela fonctionne, regardons ce qu'il se passe au niveau HTTP lorsqu'un client tente d'accéder à une ress...
Cliquez pour lire la suite de l'article par cyril
Forum
ARBRE BINAIREARBRE BINAIRE par pacotheking
Cliquez pour lire la suite par pacotheking
Logiciels
Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning Academy System (17.1.3.0)ACADEMY SYSTEM (17.1.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|