Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nirmalathasa_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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Abhisha Nirmalathas
nirmalathasa_comp30023_2019_project-2
Commits
f7bed6d2
Commit
f7bed6d2
authored
May 13, 2019
by
Abhisha Nirmalathas
Browse files
Options
Downloads
Patches
Plain Diff
completed diffie hellman exchange
parent
798da93e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
DiffieHellman.c
+13
-37
13 additions, 37 deletions
DiffieHellman.c
pwd6sha256
+0
-0
0 additions, 0 deletions
pwd6sha256
with
13 additions
and
37 deletions
DiffieHellman.c
+
13
−
37
View file @
f7bed6d2
...
@@ -22,7 +22,6 @@ int modulo(int a, int b, int n){
...
@@ -22,7 +22,6 @@ int modulo(int a, int b, int n){
}
}
int
main
(
int
argc
,
char
*
argv
[]){
int
main
(
int
argc
,
char
*
argv
[]){
printf
(
"rnning main
\n
"
);
int
g
,
p
;
int
g
,
p
;
g
=
15
;
g
=
15
;
...
@@ -41,15 +40,9 @@ int main(int argc, char *argv[]){
...
@@ -41,15 +40,9 @@ int main(int argc, char *argv[]){
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
char
privKey
[
5
];
char
privKey
[
5
];
// memset(privKey,0,0);
memcpy
(
privKey
,
argv
[
2
],
2
);
memcpy
(
privKey
,
argv
[
2
],
2
);
privKey
[
2
]
=
'\0'
;
privKey
[
2
]
=
'\0'
;
printf
(
"privKey is %s
\n\n
"
,
privKey
);
// char hex[10];
// snprintf(hex, 2, "0x%s",privKey);
// printf("hex is %s\n\n", hex);
int
b
=
(
int
)
strtol
(
privKey
,
NULL
,
16
);
int
b
=
(
int
)
strtol
(
privKey
,
NULL
,
16
);
printf
(
"b is %d
\n\n
"
,
b
);
portno
=
7800
;
portno
=
7800
;
/* Translate host name into peer's IP address ;
/* Translate host name into peer's IP address ;
...
@@ -92,25 +85,18 @@ int main(int argc, char *argv[]){
...
@@ -92,25 +85,18 @@ int main(int argc, char *argv[]){
printf
(
"send username
\n
"
);
printf
(
"send username
\n
"
);
char
*
username
=
"nirmalathasa"
;
char
*
username
=
"nirmalathasa"
;
n
=
write
(
sockfd
,
username
,
strlen
(
username
));
n
=
write
(
sockfd
,
username
,
strlen
(
username
));
printf
(
"n is %d
\n
"
,
n
);
n
=
write
(
sockfd
,
"
\n
"
,
1
);
n
=
write
(
sockfd
,
"
\n
"
,
1
);
printf
(
"n is %d
\n
"
,
n
);
if
(
n
<
0
)
if
(
n
<
0
)
{
{
perror
(
"ERROR writing to socket"
);
perror
(
"ERROR writing to socket"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
printf
(
"g: %d, b: %d, p: %d
\n
"
,
g
,
b
,
p
);
int
client_secret
=
modulo
(
g
,
b
,
p
);
// long int numerator = (int)pow(g,b);
printf
(
"my key is is %d
\n
"
,
client_secret
);
// printf("numerator: %ld\n", numerator);
char
secret
[
100
];
// int val = numerator%p;
sprintf
(
secret
,
"%d"
,
client_secret
);
int
val
=
modulo
(
g
,
b
,
p
);
for
(
int
i
=
0
;
i
<
strlen
(
secret
);
i
++
){
printf
(
"my key is is %d
\n
"
,
val
);
n
=
write
(
sockfd
,
&
secret
[
i
],
1
);
char
value
[
100
];
sprintf
(
value
,
"%d"
,
val
);
for
(
int
i
=
0
;
i
<
strlen
(
value
);
i
++
){
printf
(
"write value is %s
\n
"
,
value
);
n
=
write
(
sockfd
,
value
,
1
);
if
(
n
<
0
)
if
(
n
<
0
)
{
{
perror
(
"ERROR writing to socket"
);
perror
(
"ERROR writing to socket"
);
...
@@ -118,26 +104,16 @@ int main(int argc, char *argv[]){
...
@@ -118,26 +104,16 @@ int main(int argc, char *argv[]){
}
}
}
}
n
=
write
(
sockfd
,
"
\n
"
,
1
);
n
=
write
(
sockfd
,
"
\n
"
,
1
);
printf
(
"write newline n is %d
\n
"
,
n
);
while
(
1
){
n
=
read
(
sockfd
,
buffer
,
255
);
n
=
read
(
sockfd
,
buffer
,
255
);
printf
(
"read n is %d
\n
"
,
n
);
printf
(
"bufferrr %s and size if %d
\n\n
"
,
buffer
,
strlen
(
buffer
));
if
(
!
strncmp
(
buffer
,
"
\n
"
,
1
)){
if
(
!
strncmp
(
buffer
,
"
\n
"
,
1
)){
printf
(
"is newline"
);
buffer
[
n
]
=
0
;
buffer
[
n
]
=
0
;
break
;
}
// buffer[n] = 0;
}
}
buffer
[
n
]
=
0
;
buffer
[
n
]
=
0
;
int
responseDiffie
=
atoi
(
buffer
);
int
responseDiffie
=
atoi
(
buffer
);
printf
(
"response is %d
\n
"
,
responseDiffie
);
char
shared_value
[
100
];
char
sec
[
100
];
sprintf
(
shared_value
,
"%d"
,
modulo
(
responseDiffie
,
b
,
p
));
sprintf
(
sec
,
"%d"
,
modulo
(
val
,
responseDiffie
,
p
));
for
(
int
i
=
0
;
i
<
strlen
(
shared_value
);
i
++
){
printf
(
"final is %s
\n
"
,
sec
);
n
=
write
(
sockfd
,
&
shared_value
[
i
],
1
);
for
(
int
i
=
0
;
i
<
strlen
(
value
);
i
++
){
n
=
write
(
sockfd
,
value
,
1
);
if
(
n
<
0
)
if
(
n
<
0
)
{
{
perror
(
"ERROR writing to socket"
);
perror
(
"ERROR writing to socket"
);
...
...
This diff is collapsed.
Click to expand it.
pwd6sha256
0 → 100644
+
0
−
0
View file @
f7bed6d2
File added
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