, 나는 단지 기본을 알고 나는이 같은 간단한 해쉬 암호를 발견 프로그램을 만들어야합니다C에서 스레드를 사용하여 간단한 프로그램을 만드는 방법은 무엇입니까? 나는 C 개발에 새로운 해요
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <crypt.h>
#include <stdlib.h>
#define SIZE_HASH 256
#define SIZE_PASSWORD 4
/* Get the hash from a passwod and put the result in hash. The array hash shoud have at lest 14 elements. */
void calculate_hash_password(const char *password, char *hash);
void increment_password(char *password);
void test_password(const char *p_hash, const char *password);
int main(int argc, char *argv[]) {
int i;
char password[SIZE_PASSWORD + 1];
if (argc != 2) {
printf("Use: %s <hash>", argv[0]);
return 1;
}
for (i = 0; i < SIZE_PASSWORD; i++) {
password[i] = 'a';
}
password[SIZE_PASSWORD] = '\0';
while (1) {
test_password(argv[1], password);
increment_password(password);
}
return 0;
}
void test_password(const char *p_hash, const char *password) {
char hash_calculado[SIZE_HASH + 1];
calculate_hash_password(password, hash_calculado);
if (!strcmp(p_hash, hash_calculado)) {
printf("Achou! %s\n", password);
exit(0);
}
}
void increment_password(char *password) {
int i;
i = SIZE_PASSWORD - 1;
while (i >= 0) {
if (password[i] != 'z') {
password[i]++;
i = -2;
} else {
password[i] = 'a';
i--;
}
}
if (i == -1) {
printf("Não achou!\n");
exit(1);
}
}
void calculate_hash_password(const char *password, char *hash) {
struct crypt_data data;
data.initialized = 0;
strcpy(hash, crypt_r(password, "aa", &data));
}
내가 이것 만 사용하는 것과 같은 일을해야합니다 C의 스레드. 어떻게하면됩니까?
man pthread_create
가주의 깊게 읽고, 스레드를 사용하는 방법에 대한 매우 설명 예를 제공주의 사항 : 리눅스 쉘에
편집
에서 살펴볼 것이다. 나는 당신이 그것을 볼 수 있도록 그것의 이미지로 내 게시물을 업데이 트합니다. –
여기에 나와있는 것처럼 (long) arg에 대한 컴파일 오류 변경 (int) arg을 해결합니다. http : //stackoverflow.com/questions/1640423/error-cast-from-void-to-int-loses-precision –
@Valter Henrique : 이상한 오류입니다. 해당 라인에서'int'를'long' (또는'long long')으로 변경하여 호환 가능한 크기를 찾으십시오. – wallyk