Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp30023-2019-project-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Zhang
comp30023-2019-project-2
Commits
4e8fad81
Commit
4e8fad81
authored
6 years ago
by
ChouTatsumi
Browse files
Options
Downloads
Patches
Plain Diff
modify makefile, add check_guess method
parent
1d09b6ac
Loading
Loading
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Makefile
+4
-5
4 additions, 5 deletions
Makefile
crack.c
+62
-1
62 additions, 1 deletion
crack.c
with
66 additions
and
6 deletions
Makefile
+
4
−
5
View file @
4e8fad81
CC
=
gcc
CC
=
gcc
CFLAGS
=
-std
=
c99
-O3
-Wall
-Wpedantic
CFLAGS
=
-std
=
c99
-O3
-Wall
-Wpedantic
EXE
=
crack
EXE
=
crack
CFILE
=
crack.c
all
:
$(EXE)
all
:
$(EXE)
$(EXE)
:
$(CFILE)
sha256.o
:
sha256.c sha256.h
$(
CC
)
$(
CFLAGS
)
-
o
$(
EXE
)
$<
$(
CC
)
$(
CFLAGS
)
-
c
sha256.c
# %: %.c
$(EXE)
:
crack.c sha256.o
#
$(CC) $(CFLAGS) -o $
@ $<
$(
CC
)
$(
CFLAGS
)
-o
$
(
EXE
)
crack.c sha256.o
clean
:
clean
:
rm
$(
EXE
)
rm
$(
EXE
)
This diff is collapsed.
Click to expand it.
crack.c
+
62
−
1
View file @
4e8fad81
...
@@ -3,14 +3,75 @@
...
@@ -3,14 +3,75 @@
#include
<stdlib.h>
#include
<stdlib.h>
#include
<string.h>
#include
<string.h>
#include
"sha256.h"
// constants
// constants
#define PWD4_FILENAME "pwd4sha256"
#define PWD4_FILENAME "pwd4sha256"
#define PWD6_FILENAME "pwd6sha256"
#define PWD6_FILENAME "pwd6sha256"
#define PWD_NUMBERS 30
#define BUFFERSIZE 256
// methods reference
// methods reference
void
check_guess
(
BYTE
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
]);
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
printf
(
"test Makefile
\n
"
);
if
(
argc
==
1
)
{
FILE
*
pwdfp
;
unsigned
char
buffer
[
SHA256_BLOCK_SIZE
];
pwdfp
=
fopen
(
PWD4_FILENAME
,
"rb"
);
// read 32 bytes to buffer
fread
(
buffer
,
SHA256_BLOCK_SIZE
,
1
,
pwdfp
);
fclose
(
pwdfp
);
}
else
if
(
argc
==
2
)
{
}
else
if
(
argc
==
3
)
{
FILE
*
guessfp
;
FILE
*
pwdfp
;
char
buffer
[
BUFFERSIZE
];
guessfp
=
fopen
(
argv
[
1
],
"r"
);
pwdfp
=
fopen
(
argv
[
2
],
"rb"
);
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
guessfp
)
!=
NULL
)
{
printf
(
"%s"
,
buffer
);
}
fclose
(
guessfp
);
fclose
(
pwdfp
);
}
return
0
;
return
0
;
}
}
void
check_guess
(
BYTE
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
])
{
SHA256_CTX
ctx
;
BYTE
buf
[
SHA256_BLOCK_SIZE
];
size_t
guess_len
=
strlen
(
guess
);
int
i
;
sha256_init
(
&
ctx
);
sha256_update
(
&
ctx
,
guess
,
guess_len
);
sha256_final
(
&
ctx
,
buf
);
if
(
guess_len
==
4
)
{
for
(
i
=
0
;
i
<
10
;
i
++
)
{
if
(
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
printf
(
"%s %d
\n
"
,
guess
,
i
+
1
);
}
}
}
else
if
(
guess_len
==
6
)
{
for
(
i
=
10
;
i
<
30
;
i
++
)
{
if
(
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
printf
(
"%s %d
\n
"
,
guess
,
i
+
1
);
}
}
}
else
{
fprintf
(
stderr
,
"ERROR, undefine guess length
\n
"
);
exit
(
0
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment