Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
videid
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0a342774
authored
7 years ago
by
videid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lab13
parent
a1de719d
master
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
0 deletions
lab13/lab13.c
lab13/lab13.exe
lab13/lab13.o
lab13/lab13.c
0 → 100644
View file @
0a342774
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
void
encrypt
(
char
*
mes
,
int
k
);
;
int
main
(
void
){
char
mes
;
int
a
;
printf
(
"enter message
\n
"
);
scanf
(
"%s"
,
&
mes
);
puts
(
&
mes
);
int
k
;
printf
(
"enter key"
);
scanf
(
"%d"
,
&
k
);
printf
(
"%d"
,
k
);
printf
(
"do you want to 1-encrypt or 2-Decrypt? 1,2"
);
//there is no safety f the user enters another value than expected because i believe this is beside the point of the exercise
scanf
(
"%d"
,
&
a
);
if
(
a
==
1
){
encrypt
(
&
mes
,
k
);
}
else
if
(
a
==
2
){
encrypt
(
&
mes
,
-
k
);
}
else
{
printf
(
"none"
);}
return
0
;
}
void
encrypt
(
char
*
mes
,
int
k
){
int
len
=
strlen
(
mes
);
int
i
;
char
*
new
=
NULL
;
new
=
calloc
(
len
+
1
,
sizeof
(
char
));
for
(
i
=
0
;
i
<
len
;
i
++
)
{
char
c
=
mes
[
i
];
int
c_int
=
(
int
)
c
;
if
(
!
isalpha
(
c_int
))
{
new
[
i
]
=
mes
[
i
];
continue
;
}
if
(
isupper
(
c_int
))
{
new
[
i
]
=
(((
c_int
-
'A'
)
+
k
)
%
26
)
+
'A'
;
if
(
new
[
i
]
<
'A'
)
{
new
[
i
]
=
'Z'
+
1
-
(
'A'
-
new
[
i
]);
}
}
else
{
new
[
i
]
=
(((
c_int
-
'a'
)
+
k
)
%
26
)
+
'a'
;
if
(
new
[
i
]
<
'a'
)
{
new
[
i
]
=
'z'
+
1
-
(
'a'
-
new
[
i
]);
}
}
}
printf
(
"result message: %s"
,
new
);
}
This diff is collapsed.
Click to expand it.
lab13/lab13.exe
0 → 100644
View file @
0a342774
File added
This diff is collapsed.
Click to expand it.
lab13/lab13.o
0 → 100644
View file @
0a342774
File added
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment