Skip to content
Snippets Groups Projects
Commit 0082280b authored by weijiel6's avatar weijiel6
Browse files

finshed zip file and push it

parent 4aa6a915
No related branches found
No related tags found
No related merge requests found
password password
pa55wo
pa5sw0
pas5wo
123456 123456
12345678 12345678
1234 1234
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <ctype.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/resource.h> #include <sys/resource.h>
...@@ -20,40 +21,55 @@ ...@@ -20,40 +21,55 @@
#define PWD4_SIZE 320 /* pwd4sha256 size */
#define PWD6_SIZE 640 /* pwd6sha256 size */
#define ASCII_ST 32 /* ascII start value */
#define ASCII_ED 127 /* ascII end value */
#define INT_ST 48 /* ascII integer start value */
#define INT_ED 58 /* ascII integer end value */
#define ALPHA_ST 97 /* ascII little alpah start value */
#define ALPHA_ED 124 /* ascII little alpah end value */
/****************************************************************/ /****************************************************************/
int check_guess(BYTE secrets[], BYTE hash[], int size); int check_guess(BYTE secrets[], BYTE hash[], int size);
int get_password(char *line, FILE *fp); int get_password(char *line, FILE *fp);
/****************************************************************/ /****************************************************************/
//get the password
int int get_password(char *line, FILE *fp) {
get_password(char *line, FILE *fp) {
int i = 0, c; int i = 0, c;
//if no eof or n or f, get the char
while(((c = fgetc(fp)) != EOF) && (c !='\n') && (c != '\r')) { while(((c = fgetc(fp)) != EOF) && (c !='\n') && (c != '\r')) {
line[i++] = c; line[i++] = c;
} }
//add \0 at final place
line[i] = '\0'; line[i] = '\0';
return 1; return 1;
} }
// check the guess result and return the flag
int check_guess(BYTE secrets[], BYTE hash[], int size) { int check_guess(BYTE secrets[], BYTE hash[], int size) {
//for(int i=0; i<32;i++){
// printf("%02x",hash[i]); //initialise the compare size and flag
//}
//printf("\n");
int compare_size = 32; int compare_size = 32;
int flag; int flag;
//find how many turns should run
int turn = (size /32) + 1; int turn = (size /32) + 1;
//printf("size is %d, turn is %d\n",size, turn);
//flag = true; //for each turn compare the hash value between data and secret
for(int i = 1 ; i < turn ; i++) { for(int i = 1 ; i < turn ; i++) {
flag = -1; flag = -1;
for(int k = (i - 1) *compare_size; k < i *compare_size; k++) { for(int k = (i - 1) *compare_size; k < i *compare_size; k++) {
//if not mach return 0
if (secrets[k] != hash[k-((i - 1) *compare_size)]) { if (secrets[k] != hash[k-((i - 1) *compare_size)]) {
flag = 0; flag = 0;
break; break;
...@@ -62,16 +78,14 @@ int check_guess(BYTE secrets[], BYTE hash[], int size) { ...@@ -62,16 +78,14 @@ int check_guess(BYTE secrets[], BYTE hash[], int size) {
} }
} }
// if match, return the place of the secret
if(flag == 1){ if(flag == 1){
//int num;
//num = flag * i;
//printf("this is true for %d\n", i);
//printf("true!!!!\n");
//printf("return value should be %d\n",num);
return flag * i; return flag * i;
} }
} }
//printf("%d\n", flag);
return flag; return flag;
} }
...@@ -82,12 +96,12 @@ int main( int argc, char **argv ) ...@@ -82,12 +96,12 @@ int main( int argc, char **argv )
/* check we have 0 argument, test for guessing password*/ /* check we have 0 argument, test for guessing password*/
if( argc < 2 ) if( argc < 2 )
{ {
//open fp and fp1 for pwd4sha256 and write found_pwd
FILE *fp; FILE *fp;
FILE *fp1; FILE *fp1;
int pwd4_size; int pwd4_size;
fp1 = fopen("out.txt", "w"); fp1 = fopen("found_pwds.txt", "w");
BYTE secrets[320]; BYTE secrets[PWD4_SIZE];
fp = fopen("pwd4sha256", "rb"); fp = fopen("pwd4sha256", "rb");
fread(secrets, 320, 1, fp); fread(secrets, 320, 1, fp);
/*Move file point at the end of file.*/ /*Move file point at the end of file.*/
...@@ -97,37 +111,37 @@ int main( int argc, char **argv ) ...@@ -97,37 +111,37 @@ int main( int argc, char **argv )
pwd4_size=ftell(fp); pwd4_size=ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
printf("size is %d\n", pwd4_size);
for(int i = 0; i < 320; i++){
printf("%02x", secrets[i]);
if(((i+1) %32) == 0) {
printf("\n");
}
}
//printf("all done\n");
fclose(fp); fclose(fp);
//initialise guess needed array and text
char guess[5]; char guess[5];
int secret_num; int secret_num;
SHA256_CTX ctx; SHA256_CTX ctx;
BYTE data[SHA256_BLOCK_SIZE]; BYTE data[SHA256_BLOCK_SIZE];
for(int i = 32; i < 127; i++) {
for(int j = 32; j < 127; j++) { //find for whole ascII
for(int l = 32; l < 127; l++) { for(int i = ASCII_ST; i < ASCII_ED; i++) {
for(int k = 32; k < 127; k++) { for(int j = ASCII_ST; j < ASCII_ED; j++) {
for(int l = ASCII_ST; l < ASCII_ED; l++) {
for(int k = ASCII_ST; k < ASCII_ED; k++) {
//store into guess
sprintf(guess, "%c%c%c%c", i, j, l, k); sprintf(guess, "%c%c%c%c", i, j, l, k);
//printf("%s\n",guess);
//hash the guess
sha256_init(&ctx); sha256_init(&ctx);
sha256_update(&ctx, (BYTE*)guess, strlen(guess)); sha256_update(&ctx, (BYTE*)guess, strlen(guess));
sha256_final(&ctx, data); sha256_final(&ctx, data);
//chech the hash
if (check_guess(secrets, data, pwd4_size) > 0) { if (check_guess(secrets, data, pwd4_size) > 0) {
secret_num = check_guess(secrets, data, pwd4_size); secret_num = check_guess(secrets, data, pwd4_size);
printf("%s %d\n",guess, secret_num); printf("%s %d\n",guess, secret_num);
fprintf(fp1, "%s %d\n", guess, secret_num); fprintf(fp1, "%s %d\n", guess, secret_num);
} }
//printf("%s\n", guess);
} }
} }
} }
...@@ -135,8 +149,10 @@ int main( int argc, char **argv ) ...@@ -135,8 +149,10 @@ int main( int argc, char **argv )
guess[5] = '\0'; guess[5] = '\0';
//open the pwd6sha256
FILE *fp3; FILE *fp3;
BYTE long_secrets[640]; BYTE long_secrets[PWD6_SIZE];
fp3 = fopen("pwd6sha256", "rb"); fp3 = fopen("pwd6sha256", "rb");
fread(long_secrets, 640, 1, fp3); fread(long_secrets, 640, 1, fp3);
int pwd6_size; int pwd6_size;
...@@ -147,36 +163,36 @@ int main( int argc, char **argv ) ...@@ -147,36 +163,36 @@ int main( int argc, char **argv )
pwd6_size=ftell(fp3); pwd6_size=ftell(fp3);
fseek(fp3, 0, SEEK_SET); fseek(fp3, 0, SEEK_SET);
printf("size is %d\n", pwd6_size);
for(int i = 0; i < 640; i++){
printf("%02x", long_secrets[i]);
if(((i+1) %32) == 0) {
printf("\n");
}
}
printf("\n");
//create longer gusee for 6 password guess
char long_guess[7]; char long_guess[7];
int long_secret_num; int long_secret_num;
SHA256_CTX long_ctx; SHA256_CTX long_ctx;
BYTE long_data[SHA256_BLOCK_SIZE]; BYTE long_data[SHA256_BLOCK_SIZE];
for(int i = 48; i < 58; i++) {
for(int j = 48; j < 58; j++) { //check all number guess
for(int l = 48; l < 58; l++) { for(int i = INT_ST; i < INT_ED; i++) {
for(int k = 48; k < 58; k++) { for(int j = INT_ST; j < INT_ED; j++) {
for(int n = 48; n < 58; n++) { for(int l = INT_ST; l < INT_ED; l++) {
for(int m = 48; m < 58; m++) { for(int k = INT_ST; k < INT_ED; k++) {
for(int n = INT_ST; n < INT_ED; n++) {
for(int m = INT_ST; m < INT_ED; m++) {
//store into long guess
sprintf(long_guess, "%c%c%c%c%c%c", i, j, l, k, n, m); sprintf(long_guess, "%c%c%c%c%c%c", i, j, l, k, n, m);
//printf("%s\n",guess);
//hash the long guess
sha256_init(&long_ctx); sha256_init(&long_ctx);
sha256_update(&long_ctx, (BYTE*)long_guess, strlen(long_guess)); sha256_update(&long_ctx, (BYTE*)long_guess, strlen(long_guess));
sha256_final(&long_ctx, long_data); sha256_final(&long_ctx, long_data);
//chech the hash
if (check_guess(long_secrets, long_data, pwd6_size) > 0) { if (check_guess(long_secrets, long_data, pwd6_size) > 0) {
long_secret_num = check_guess(long_secrets, long_data, pwd6_size); long_secret_num = check_guess(long_secrets, long_data, pwd6_size);
//add 10 for 10 later password
long_secret_num = long_secret_num + 10; long_secret_num = long_secret_num + 10;
//printf("long secret num should be %d\n", long_secret_num);
printf("%s %d\n",long_guess, long_secret_num); printf("%s %d\n",long_guess, long_secret_num);
fprintf(fp1, "%s %d\n", long_guess, long_secret_num); fprintf(fp1, "%s %d\n", long_guess, long_secret_num);
} }
...@@ -188,25 +204,33 @@ int main( int argc, char **argv ) ...@@ -188,25 +204,33 @@ int main( int argc, char **argv )
} }
long_guess[7] = '\0'; long_guess[7] = '\0';
//create alpha gusee for 6 password guess
char alpha_guess[7]; char alpha_guess[7];
int alpha_secret_num; int alpha_secret_num;
SHA256_CTX alpha_ctx; SHA256_CTX alpha_ctx;
BYTE alpha_data[SHA256_BLOCK_SIZE]; BYTE alpha_data[SHA256_BLOCK_SIZE];
for(int i = 97; i < 124; i++) {
for(int j = 97; j < 124; j++) { //check all little alpha guess
for(int l = 97; l < 124; l++) { for(int i = ALPHA_ST; i < ALPHA_ED; i++) {
for(int k = 97; k < 124; k++) { for(int j = ALPHA_ST; j < ALPHA_ED; j++) {
for(int n = 97; n < 124; n++) { for(int l = ALPHA_ST; l < ALPHA_ED; l++) {
for(int m = 97; m < 124; m++) { for(int k = ALPHA_ST; k < ALPHA_ED; k++) {
for(int n = ALPHA_ST; n < ALPHA_ED; n++) {
for(int m = ALPHA_ST; m < ALPHA_ED; m++) {
//store into little alpha guess
sprintf(alpha_guess, "%c%c%c%c%c%c", i, j, l, k, n, m); sprintf(alpha_guess, "%c%c%c%c%c%c", i, j, l, k, n, m);
//printf("%s\n",guess);
//hash the little alpha guess
sha256_init(&alpha_ctx); sha256_init(&alpha_ctx);
sha256_update(&alpha_ctx, (BYTE*)alpha_guess, strlen(alpha_guess)); sha256_update(&alpha_ctx, (BYTE*)alpha_guess, strlen(alpha_guess));
sha256_final(&alpha_ctx, alpha_data); sha256_final(&alpha_ctx, alpha_data);
//chech the hash
if (check_guess(long_secrets, alpha_data, pwd6_size) > 0) { if (check_guess(long_secrets, alpha_data, pwd6_size) > 0) {
alpha_secret_num = check_guess(long_secrets, alpha_data, pwd6_size); alpha_secret_num = check_guess(long_secrets, alpha_data, pwd6_size);
//add 10 for 10 later password
alpha_secret_num = alpha_secret_num + 10; alpha_secret_num = alpha_secret_num + 10;
//printf("long secret num should be %d\n", long_secret_num);
printf("%s %d\n",alpha_guess, alpha_secret_num); printf("%s %d\n",alpha_guess, alpha_secret_num);
fprintf(fp1, "%s %d\n", alpha_guess, alpha_secret_num); fprintf(fp1, "%s %d\n", alpha_guess, alpha_secret_num);
} }
...@@ -218,22 +242,47 @@ int main( int argc, char **argv ) ...@@ -218,22 +242,47 @@ int main( int argc, char **argv )
} }
alpha_guess[7] = '\0'; alpha_guess[7] = '\0';
//close all file
fclose(fp1);
fclose(fp3);
return 0; return 0;
} }
if( argc == 2 ) if( argc == 2 )
{ {
//if (isdigit(argv[1]) == 0) { // get the guess number and open diriction
// fprintf(stderr, "please entre a integer\n");
// return 0;
//}
int guess_num = atoi(argv[1]); int guess_num = atoi(argv[1]);
FILE *fp; FILE *fp;
char line[10000]; char line[10000];
char guess_word[100000][7];
fp = fopen("common_passwords.txt", "r"); fp = fopen("common_passwords.txt", "r");
for(int i = 0; i < guess_num; i++) { int fp_size;
fseek(fp, 0, SEEK_END);
fp_size=ftell(fp);
fseek(fp, 0, SEEK_SET);
//set all password into direction
for(int i = 0; i < fp_size; i++) {
get_password(line, fp); get_password(line, fp);
printf("%s\n", line); strncpy(guess_word[i], line, 6);
}
//print out guess based on require number
for(int i = 0; i < guess_num; i++) {
if(strlen(guess_word[i]) < 6 && strlen(guess_word[i]) > 0) {
for(int k = (strlen(guess_word[i]) - 1); k < 6; k++){
guess_word[i][k] = 'a';
}
guess_word[i][6] = '\n';
}
if(strlen(guess_word[i]) == 0) {
for(int k = 0; k < 6; k++){
guess_word[i][k] = 'a';
}
}
printf("%s\n", guess_word[i]);
} }
return 0; return 0;
...@@ -241,6 +290,7 @@ int main( int argc, char **argv ) ...@@ -241,6 +290,7 @@ int main( int argc, char **argv )
if( argc == 3 ) if( argc == 3 )
{ {
//open argument 1 and 2 file
FILE *fp1; FILE *fp1;
fp1 = fopen(argv[2], "rb"); fp1 = fopen(argv[2], "rb");
int fp1_size; int fp1_size;
...@@ -249,17 +299,12 @@ int main( int argc, char **argv ) ...@@ -249,17 +299,12 @@ int main( int argc, char **argv )
fseek(fp1, 0, SEEK_SET); fseek(fp1, 0, SEEK_SET);
BYTE secrets[fp1_size]; BYTE secrets[fp1_size];
fread(secrets, fp1_size, 1, fp1); fread(secrets, fp1_size, 1, fp1);
for(int i = 0; i < fp1_size; i++){
printf("%02x", secrets[i]);
if(((i+1) %32) == 0) {
printf("\n");
}
}
FILE *fp; FILE *fp;
char line[10000]; char line[10000];
fp = fopen(argv[1], "r"); fp = fopen(argv[1], "r");
int secret_num; int secret_num;
//check the password from first argument to the second
for(int i = 0; i < 10000 ; i++) { for(int i = 0; i < 10000 ; i++) {
get_password(line, fp); get_password(line, fp);
SHA256_CTX ctx; SHA256_CTX ctx;
...@@ -272,6 +317,8 @@ int main( int argc, char **argv ) ...@@ -272,6 +317,8 @@ int main( int argc, char **argv )
printf("%s %d\n", line, secret_num); printf("%s %d\n", line, secret_num);
} }
} }
//close all files
fclose(fp); fclose(fp);
fclose(fp1); fclose(fp1);
return 0; return 0;
......
4226 8
5226 3
5236 4
5237 5
8686 6
mcac 1
oca{ 10
reng 2
tuyy 9
weij 7
090909 25
360258 11
369258 13
379258 12
469258 29
asdzxc 27
fastca 21
kakash 17
newcas 16
oeotak 23
wdovan 20
weijie 19
wicked 30
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment