begin process at 2012 05 27 15:29:26
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Sécurité & Cryptage

 > DECRYPTER : VIGENÈRE/CÉSAR

DECRYPTER : VIGENÈRE/CÉSAR


 Information sur la source

Note :
8,67 / 10 - par 3 personnes
8,67 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Sécurité & Cryptage Niveau :Débutant Date de création :13/08/2001 Vu :14 032

Auteur : fhr

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

 Description

Permet de décoder un fichier codé avec mon prog "CRYPTER : VIGENERE/CESAR" avec le fichier codé et celui contenant la clé

Source

  • #include<conio.h>
  • #include<stdio.h>
  • #include<stdlib.h>
  • #include<string.h>
  • void warning (void);
  • void error (void);
  • int main(int argc,char *argv[]) /* ex : fh decrypto crypto.txt cle.txt donne : nomcrypt = crypto.txt, nomcle = cle.txt*/
  • {
  • char *nomcrypt, *nomcle, *nomresult;
  • char *crypto ,*decrypto, *motcle, *falsemotcle ;
  • FILE *crypt, *cle, *result;
  • char bidule [2000];
  • int i=0,j, rep;
  • int choix, nombre;
  • char c='0';
  • if(argc!=1 && argc !=3)
  • {
  • printf("Nombre d'arguments errone !.\nFin du programme.");
  • exit(1);
  • }
  • if(argc==3)
  • strcpy(bidule,argv[1]);
  • else
  • {
  • printf("Donnez le nom du fichier ou est contenu le resultat : ");
  • gets(bidule);
  • }
  • if(!(nomcrypt = (char *) malloc (strlen(bidule))))
  • warning();
  • strcpy(nomcrypt,bidule);
  • if(!(crypt=fopen(nomcrypt, "r")))
  • error();
  • fseek(crypt, 42, 0);
  • while((c= fgetc(crypt)) != EOF)
  • i++;
  • fseek(crypt, 42, 0);
  • fgets(bidule, ++i, crypt);
  • if(!(crypto = (char *) malloc (strlen(bidule))))
  • warning();
  • if(!(decrypto = (char *) malloc (strlen(bidule))))
  • warning();
  • strcpy(crypto,bidule);
  • fclose(crypt);
  • if(argc==3)
  • strcpy(bidule,argv[2]);
  • else
  • {
  • printf("Donnez le nom du fichier ou est contenue la cle : ");
  • gets(bidule);
  • }
  • if(!(nomcle = (char *) malloc (strlen(bidule))))
  • warning();
  • strcpy(nomcle,bidule);
  • if(!(cle=fopen(nomcle, "r")))
  • error();
  • fseek(cle,39,0);
  • fscanf(cle,"%d", &choix);
  • switch(choix)
  • {
  • case 1: fseek(cle,85,0);
  • fscanf(cle,"%d", &nombre);
  • for(i=0;crypto[i]!='\0';decrypto[i] = (crypto[i] - nombre)%256,i++)
  • ;
  • break;
  • case 2: fseek(cle, 83, 0);
  • i=0;
  • while((c= fgetc(cle)) != EOF)
  • i++;
  • fseek(cle, 83, 0);
  • fgets(bidule, ++i, cle);
  • fclose(cle);
  • if(!(falsemotcle = (char *) malloc (strlen(bidule))))
  • warning();
  • strcpy(falsemotcle, bidule);
  • if(!(motcle = (char *) malloc (strlen(crypto))))
  • warning();
  • for(i=0,j=0;strlen(motcle) <strlen(crypto);motcle[j] = bidule[i], j++,i++)
  • if(i == strlen(bidule) )
  • i=0;
  • for(i=0;crypto[i]!='\0';decrypto[i] = (crypto[i] - motcle[i])%256,i++)
  • ;
  • break;
  • default: printf("\nErreur dans le fichier !. Fin du programme.");
  • exit(1);
  • }
  • printf("\n\n\nResultat du decryptage = %s", decrypto);
  • printf("\n\n\nVoulez enregistrer le resultat du decryptage dans un fichier (o/n) ?");
  • if((rep = getch()) == 'o')
  • {
  • getchar();
  • printf("Donnez le nom du fichier ou vous voulez enregistrer le resultat : ");
  • gets(bidule);
  • if(!(nomresult = (char *) malloc (strlen(bidule))))
  • warning();
  • strcpy(nomresult, bidule);
  • if(!(result=fopen(nomresult, "w")))
  • error();
  • fprintf(result, "Resultat du decryptage. Le resultat est = \n%s", decrypto);
  • fclose(result);
  • printf("Resultat enregistre dans %s\n", nomresult);
  • }
  • printf("Fin du programme");
  • getchar();
  • }
  • void warning(void)
  • {
  • printf("\n\tAllocation memoire impossible !!\nFin du programme.");
  • getchar();
  • exit(1);
  • }
  • void error(void)
  • {
  • printf("\n\tErreur d'ouverture du fichier.\nFin du programme.");
  • getchar();
  • exit(1);
  • }
#include<conio.h>

#include<stdio.h>
#include<stdlib.h>
#include<string.h>


void warning (void);
void error (void);

int main(int argc,char *argv[]) /* ex :  fh decrypto  crypto.txt cle.txt     donne :  nomcrypt = crypto.txt, nomcle = cle.txt*/
{
    char *nomcrypt, *nomcle, *nomresult;
    char *crypto ,*decrypto, *motcle, *falsemotcle ;
    FILE *crypt, *cle, *result;
    char bidule [2000];
    int i=0,j, rep;
    int choix, nombre;
    char c='0';

    if(argc!=1 && argc !=3)
    {
        printf("Nombre d'arguments errone !.\nFin du programme.");
        exit(1);
    }


    if(argc==3)
        strcpy(bidule,argv[1]);

    else
    {
        printf("Donnez le nom du fichier ou est contenu le resultat : ");
        gets(bidule);
    }

    if(!(nomcrypt = (char *) malloc (strlen(bidule))))
        warning();
    strcpy(nomcrypt,bidule);


    if(!(crypt=fopen(nomcrypt, "r")))
        error();

    fseek(crypt, 42, 0);
    while((c= fgetc(crypt)) != EOF)
        i++;

    fseek(crypt, 42, 0);
    fgets(bidule, ++i, crypt);
    if(!(crypto = (char *) malloc (strlen(bidule))))
        warning();
    if(!(decrypto = (char *) malloc (strlen(bidule))))
        warning();
    strcpy(crypto,bidule);
    fclose(crypt);

    if(argc==3)
       strcpy(bidule,argv[2]);

    else
    {
        printf("Donnez le nom du fichier ou est contenue la cle : ");
        gets(bidule);
    }

    if(!(nomcle = (char *) malloc (strlen(bidule))))
        warning();
    strcpy(nomcle,bidule);
    if(!(cle=fopen(nomcle, "r")))
        error();

    fseek(cle,39,0);
    fscanf(cle,"%d", &choix);

    switch(choix)
    {
    case 1: fseek(cle,85,0);
            fscanf(cle,"%d", &nombre);

            for(i=0;crypto[i]!='\0';decrypto[i] = (crypto[i] - nombre)%256,i++)
                ;
            break;
    case 2: fseek(cle, 83, 0);
            i=0;
            while((c= fgetc(cle)) != EOF)
                i++;
            fseek(cle, 83, 0);
            fgets(bidule, ++i, cle);
            fclose(cle);

            if(!(falsemotcle = (char *) malloc (strlen(bidule))))
                warning();
            strcpy(falsemotcle, bidule);

            if(!(motcle = (char *) malloc (strlen(crypto))))
                warning();
            for(i=0,j=0;strlen(motcle) <strlen(crypto);motcle[j] = bidule[i], j++,i++)
                if(i == strlen(bidule) )
                    i=0;

            for(i=0;crypto[i]!='\0';decrypto[i] = (crypto[i] - motcle[i])%256,i++)
                ;
            break;
    default: printf("\nErreur dans le fichier !. Fin du programme.");
             exit(1);
    }
    printf("\n\n\nResultat du decryptage = %s", decrypto);

    printf("\n\n\nVoulez enregistrer le resultat du decryptage dans un fichier (o/n) ?");
    if((rep = getch()) == 'o')
    {
        getchar();
        printf("Donnez le nom du fichier ou vous voulez enregistrer le resultat : ");
        gets(bidule);
        if(!(nomresult = (char *) malloc (strlen(bidule))))
            warning();
        strcpy(nomresult, bidule);
        if(!(result=fopen(nomresult, "w")))
            error();
        fprintf(result, "Resultat du decryptage. Le resultat est = \n%s", decrypto);
        fclose(result);
        printf("Resultat enregistre dans %s\n", nomresult);
    }
    printf("Fin du programme");
    getchar();

}

void warning(void)
{
    printf("\n\tAllocation memoire impossible !!\nFin du programme.");
    getchar();
    exit(1);
}
void error(void)
{
    printf("\n\tErreur d'ouverture du fichier.\nFin du programme.");
    getchar();
    exit(1);
}



 Sources du même auteur

CRYPTER : VIGENÈRE/CÉSAR
DECIMAL-&GT; TOUT !

 Sources de la même categorie

PROJET DE CRYPTOGRAPHIE: RSA À JEU REDUIT D'INSTRUCTION par samatarahmed
Source avec Zip Source avec une capture CRYPTOSYSTÈME ELGAMAL LIBRAIRIE GMP par louelh95
Source avec Zip Source .NET (Dotnet) NOUVEL ALGORITHME D'ENCRYPTION-DÉSENCRYPTION DYNAMIQUE (INFA... par vletktol
Source avec Zip A2DCRYPT - CRYPTAGE 2048 BITS par darkor
Source avec Zip Source avec une capture CRYPTEUR-DÉCRYPTEUR-IP par antho974

Commentaires et avis

Commentaire de Sloft le 28/04/2002 15:56:58

Le décryptage ne marche pas correctement, les 2 derniers octets sont mals décryptés. Je n'ai jamais trouvé une source en c++ de decryptage qui fonctionne correctement. Facile de crypter, mais décrypter c toujours foireux !

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
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,608 sec (3)

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