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
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TAILLE_MAX 6
const char* alphabet = "abcdefghij"; // alphabet de 10 lettres
int int_value(char c, const char* alphabet) {
const char* cur = alphabet;
for (; *cur; ++cur)
if (*cur == c) return cur - alphabet;
return -1;
}
int str_to_int(const char* mdp) {
int res = 0;
for (; *mdp; res*=10)
res+=int_value(*mdp++, alphabet);
return res/10;
}
void int_to_str(char* buf, int nb, int len) {
int i;
for (i = len; i-- > 0; nb /= 10)
*(buf+i) = *(alphabet+nb%10);
buf[len] = '\0';
}
void thread1()
{
char current_str[4] = "aaaaa";
char searched_str[4] = "outil";
// char end_str[4] = "bbbbb";
unsigned char limit = 'l', is_not_equal;
do {
is_not_equal = ((current_str[0] != searched_str[0]) || (current_str[1] != searched_str[1]) || (current_str[2] != searched_str[2]) || (current_str[3] != searched_str[3]) || (current_str[4] != searched_str[4]));
printf("%s\n", current_str);
++current_str[4];
if (current_str[4] >= limit) {
current_str[4] = 'a';
++current_str[3];
if (current_str[3] >= limit) {
current_str[3] = 'a';
++current_str[2];
if (current_str[2] >= limit) {
current_str[2] = 'a';
++current_str[1];
if (current_str[1] >= limit) {
current_str[1] = 'a';
printf(current_str[1]);
++current_str[0];
if (current_str[0] >= limit) {
current_str[0] = 'a';
is_not_equal = 0; // quit
}
}
}
}
}
} while (is_not_equal);
}
int main()
{
FILE* fichier = NULL;
char chaine[TAILLE_MAX] = ""; // Chaîne vide de taille TAILLE_MAX
fichier = fopen("C:\\Users\\User\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Accessories\\mdp.txt", "r+");
if (fichier != NULL)
{
fgets(chaine, TAILLE_MAX, fichier);
// On peut lire et écrire dans le fichier
printf("Le mot de passe contenu dans le fichier est: ");
printf("%s", chaine,"\n"); // On affiche la chaîne
//printf("\nLe fichier a ete ouvert sans soucis.");
fclose(fichier);
thread1();
printf("\nLe mot de passe n'est pas dans ce thread");
}
else
{
// On affiche un message d'erreur si on veut
printf("Impossible d'ouvrir le fichier mdp.txt");
}
return 0;
} |
Partager