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
COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE?COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE? par Matthieu MEZIL
Avec EF, les vues doivent être mappées sur des entity types. Le problème c'est que les entity types doivent avoir une clé. Avec EF, nous avons les complex type qui n'ont pas de clé mais les vues ne peuvent pas être mappées dessus. Avec EF4, il est possibl...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL?[WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL? par JeremyJeanson
Certain d'entre vous on peut être vécu cette situation embarrassante après quelques temps passer avec WF4 : Au début avec mon " ActivityDesigner" , tout allait bien. Et puis un jour j'ai au des problèmes de " Binding" . Alors nous sommes allé sur le site ...
Cliquez pour lire la suite de l'article par JeremyJeanson MYTIC - SHAREPOINT 2010 : DéJà UN MYTHE MICROSOFT ?MYTIC - SHAREPOINT 2010 : DéJà UN MYTHE MICROSOFT ? par junarnoalg
La prochaine session de MyTIC aura lieu à Namur, le 23 mars prochain. Pendant presque une heure, nous parlerons de SharePoint 2010. Voici un aperçu du programme.
Accueil : 17h30 Début de la session : 18h00 - Les nouvelles int...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
ERREUR DE POINTEURERREUR DE POINTEUR par africanwinners
Cliquez pour lire la suite par africanwinners CLISTCTRLCLISTCTRL par dorras7
Cliquez pour lire la suite par dorras7
Logiciels
Academy System (10.9.4.0)ACADEMY SYSTEM (10.9.4.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods
|