IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Explication code source Cesar


Sujet :

C

  1. #1
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Septembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2013
    Messages : 32
    Points : 18
    Points
    18
    Par défaut Explication code source Cesar
    Bonjour

    j'ai le code source ça marche bien mais je comprend pas le code source
    SVP jai besoin d'aide
    et merci d'avance :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <windows.h>
     
    #define TAILLE_MAX 500
     
    void clean_stdin (void);
    void pause (int); 
     
    char *openfichier()
    {
    	static char str[2000] = "";
     
    	FILE* fichier = NULL;
    	char chaine[TAILLE_MAX] = "";
     
        fichier = fopen("readme.txt", "r");	
     
    	if (fichier != NULL)
    	{
    		printf ("\n---== Texte a crypter ==---\n\n\n");
    		while (fgets(chaine, TAILLE_MAX, fichier) != NULL) 
            {
    			strcat(str, chaine);
                printf("%s", chaine); 
    	    }
    		printf ("\n\n\n---== Texte a crypter ==---");
            fclose(fichier); 
    	}
    	else
    	{
    		system("cls");
    		printf("\n\nImpossible d'ouvrir le fichier readme.txt\n\n");
    		pause (1);
    		exit(EXIT_FAILURE);
    	} 
    	return str;
     
    }
     
     
    void cesar_crypt (int decallage, char *texte)
    {
    	char c;
    	int decMin = decallage - 'a';
    	decallage -= 'A';
    	while(c = *texte) 
    	{
    		if(c > 'z') goto nextCHR;
    		if(c < 'A') goto nextCHR;
    		if(c <= 'Z') goto goMAJ;
    		if(c < 'a') goto nextCHR;
    		c = 'a' + (c + decMin) % 26;
    		goto goREPLACE;
            goMAJ:
    		c = 'A' + (c + decallage) % 26;
            goREPLACE: *texte = c;
            nextCHR: texte++;
      } 
    }
     
    int main(int argc, char *argv[])
    {
    	int menu = 0;
     
    	printf("\n==== Menu ====\n\n\n");
    	printf("1. Cryptage\n\n");
    	printf("2. Decryptage\n\n");
    	printf("3. Quitter\n\n\n");
    	scanf("%d", &menu);
     
    	printf("\n");	
     
    	if (menu == 1)
    	{
    		int decalage;
    		int crypter = 0;
     
    		FILE* fichier = NULL;	
     
    		char *texte;
    		texte = openfichier();	
     
    		system("cls");
    		printf ("\n\nUtiliser un decallage de combien de lettres pour crypter ce fichier ?\n\n");
    		scanf  ("%d", &decalage);
     
    		printf ("\n\nVoulez-vous vraiment crypter ce texte en utilisant un decalage de %d lettres ?\n\n", decalage);
     
    		printf ("Ecrivez 1 pour Oui ou 0 pour Non\n\n");
    		scanf  ("%d", &crypter);
     
    		if (crypter == 1)
    		{
    			system ("cls");		
    			cesar_crypt (decalage, texte);
    			printf ("\n---== Texte apres chiffrement ==---\n\n\n");
    			printf ("%s\n", texte);
    			printf ("\n\n---== Texte apres chiffrement ==---\n\n");
     
    			fichier = fopen("readme.txt", "a+");
     
    			if (fichier != NULL)
    			{
    				fprintf(fichier, "\n\nTexte Crypte : \n\n%s", texte);
    				fclose(fichier); 
    			}    
    			pause (1);	 
    		}
    		else if (crypter == 0)
    		{
    			system ("cls");
    			printf ("\nAu revoir, et bonne journee\n\n");
    			pause (1);		
    		}
    		else if (crypter < 0 || crypter > 1)
    		{
    			printf ("\nVeuillez entrer 0 ou 1\n\n");
    			scanf ("%d", &crypter);
     
    			while (crypter < 0 || crypter > 1)
    			{
    				printf ("\nVeuillez entrer 0 ou 1\n\n");
    				scanf ("%d", &crypter);
    			}
     
    			if (crypter == 1)
    			{
    				system ("cls");		
    				cesar_crypt (3, texte);
    				printf ("\n---== Texte apres chiffrement ==---\n\n\n");
    				printf ("%s\n", texte);
    				printf ("\n\n---== Texte apres chiffrement ==---\n\n");
     
    				fichier = fopen("readme.txt", "a+");
     
    				if (fichier != NULL)
    				{
    					fprintf(fichier, "\n\nTexte Crypte : \n\n%s", texte);
    					fclose(fichier); 
    				} 
    				pause (1);	 
    			}
    			else if (crypter == 0)
    			{
    				system ("cls");
    				printf ("\nAu revoir, et bonne journee\n\n");
    				pause (1);			
    			}
    		}
    	}
     
    	if (menu == 2)
    	{
    		int decalage = 26 ;	
     
    		FILE* fichier = NULL;	
     
    		char *texte;
    		texte = openfichier();
     
    		while (decalage > 0)
    		{
    			cesar_crypt (decalage, texte);
     
    			fichier = fopen("readme.txt", "a+");
    			if (fichier != NULL)
    			{
    				fprintf(fichier, "\n\n%s", texte);
    				fclose(fichier); 
    			} 
    			decalage--;		
    		}
     
    		system("cls");
    		printf("\n\nDecryptage reussi, disponible dans le fichier readme.txt\n\n");
    		pause(1);
    	}
     
    	if (menu == 3)
    	{
    		getchar();
    	}
    	if (menu > 3 || menu < 1)
    	{
    		exit(EXIT_FAILURE);
    	}
    }
     
    void clean_stdin (void) 
    {
        int c = 0;
        do
        {
          c = getchar();
        } 
    	while (c != '\n' && c != EOF);
    }
     
    void pause (int b)
    {
        printf ("\nAppuyez sur Entrer pour quitter\n");
        if (b==0)
            getchar ();
        else if (b==1)
        {
            clean_stdin ();
            getchar ();
        }
    }
    /*Merci a SoftEvans, Melem et Pouet_forever*/

  2. #2
    Membre expérimenté

    Homme Profil pro
    Collégien
    Inscrit en
    Juillet 2010
    Messages
    545
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Afghanistan

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Juillet 2010
    Messages : 545
    Points : 1 429
    Points
    1 429
    Par défaut
    Il va falloir que tu nous aide un peu plus STP.
    Qu'est ce que tu ne comprends pas?

    Si par exemple je balance une phrase l'air du genre:

    "Je ne comprends pas le klingon j'ai besoin d'aide SVP"
    Tu avoueras que ça ne sers à rien....

  3. #3
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Septembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2013
    Messages : 32
    Points : 18
    Points
    18
    Par défaut ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    void cesar_crypt (int decallage, char *texte)
    {
    	char c;
    	int decMin = decallage - 'a';
    	decallage -= 'A';
    	while(c = *texte) 
    	{
    		if(c > 'z') goto nextCHR;
    		if(c < 'A') goto nextCHR;
    		if(c <= 'Z') goto goMAJ;
    		if(c < 'a') goto nextCHR;
    		c = 'a' + (c + decMin) % 26;
    		goto goREPLACE;
            goMAJ:
    		c = 'A' + (c + decallage) % 26;
            goREPLACE: *texte = c;
            nextCHR: texte++;
      } 
    }

Discussions similaires

  1. explication code source
    Par tintine dans le forum Basic
    Réponses: 0
    Dernier message: 27/04/2015, 11h56
  2. explication de code source
    Par mirafrance dans le forum Langage
    Réponses: 2
    Dernier message: 21/01/2011, 22h28
  3. Explication sur un code source
    Par Sarah! dans le forum C++
    Réponses: 5
    Dernier message: 04/06/2008, 10h40
  4. Je cherche le code-source d'un interface de Windows
    Par Robert A. dans le forum Windows
    Réponses: 5
    Dernier message: 02/06/2003, 09h45
  5. [VB6] Code source pour modifier MsgBox
    Par khany dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 25/02/2003, 15h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo