Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment03
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nouman.ashraf
Assessment03
Commits
07e98480
Commit
07e98480
authored
Jan 07, 2019
by
Dell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
e56f0d16
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
201 additions
and
17 deletions
+201
-17
AssessmentPartThree.java
src/AssessmentPartThree.java
+201
-17
No files found.
src/AssessmentPartThree.java
View file @
07e98480
...
...
@@ -10,23 +10,207 @@ public class AssessmentPartThree {
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
{
// 05 - encryptedCharacter
// Complete this method so that it returns the encrypted character for
// theChar when and offset of theOffset is used
// So if theChar='m' and theOffset is 3 the method will return 'p'
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
char
a
=
theChar
;
// store given character
int
b
=
a
;
// Stores ASCCI of given character
int
Add
=
0
;
// Add is use to check Offset and ASCII of given number
return
'a'
;
if
(
a
>=
'a'
&&
a
<=
'z'
)
// This condition executes when given charcter is a small Alphabet
{
if
(
theOffset
>=
0
)
// This condition will be executed when the given offset is positive
{
Add
=
b
+
theOffset
;
// Add Offset and ASCII of given number
if
(
Add
>
122
)
{
Add
-=
122
;
// Add = Add-122
Add
+=
96
;
//then add 96 in it.
a
=(
char
)
Add
;
//and change ASCII into character
}
else
{
b
+=
theOffset
;
a
=(
char
)
b
;
}
}
else
if
(
theOffset
<
0
)
// This condition will be executed when the given offset is Negative
{
Add
=
b
+
theOffset
;
if
(
Add
<
97
)
{
Add
-=
96
;
Add
+=
122
;
a
=(
char
)
Add
;
}
else
{
b
+=
theOffset
;
a
=(
char
)
b
;
}
}
}
// IF #1 End
else
if
(
a
>=
'A'
&&
a
<=
'Z'
)
// This condition executes when given charcter is a Capital Alphabet
{
if
(
theOffset
>=
0
)
// This condition will be executed when the given offset is positive
{
Add
=
b
+
theOffset
;
if
(
Add
>
90
)
{
Add
-=
90
;
Add
+=
64
;
a
=(
char
)
Add
;
}
else
{
b
+=
theOffset
;
a
=(
char
)
b
;
}
}
else
if
(
theOffset
<
0
)
// This condition will be executed when the given offset is Negative
{
Add
=
b
+
theOffset
;
if
(
Add
<
65
)
{
Add
-=
64
;
Add
+=
90
;
a
=(
char
)
Add
;
}
else
{
b
+=
theOffset
;
a
=(
char
)
b
;
}
}
}
// ELSE #1 END
return
a
;
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
{
String
eMessage
=
""
;
// Stores Encryptred message
int
b
;
// Stores ASCII of single Character
char
a
;
// Stores single character of String
String
s
=
theMessage
;
int
Add
=
0
;
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++)
// s.length() counts total charaters in a String and then For loop executes s.length() times
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
return
"Encryptred message"
;
a
=
s
.
charAt
(
i
);
// get specific character from String
b
=
a
;
if
(
a
>=
'a'
&&
a
<=
'z'
)
// This condition executes when given charcter is a small Alphabet
{
if
(
theOffset
>=
0
)
// This condition will be executed when the given offset is positive
{
Add
=
b
+
theOffset
;
// Add Offset and ASCII of given number
if
(
Add
>
122
)
{
Add
-=
122
;
Add
+=
96
;
a
=(
char
)
Add
;
eMessage
+=
a
;
// Add new character in a String
}
else
{
b
+=
theOffset
;
a
=(
char
)
b
;
eMessage
+=
a
;
}
}
else
if
(
theOffset
<
0
)
// This condition will be executed when the given offset is Negative
{
Add
=
b
+
theOffset
;
if
(
Add
<
97
)
{
Add
-=
96
;
Add
+=
122
;
a
=(
char
)
Add
;
eMessage
+=
a
;
}
else
{
b
+=
theOffset
;
a
=(
char
)
b
;
eMessage
+=
a
;
}
}
}
// IF #1 End
else
if
(
a
>=
'A'
&&
a
<=
'Z'
)
// ELSE #1 Start
{
if
(
theOffset
>=
0
)
// This condition will be executed when the given offset is Positive
{
Add
=
b
+
theOffset
;
if
(
Add
>
90
)
{
Add
-=
90
;
Add
+=
64
;
// by this we can get correct ascii for our character
a
=(
char
)
Add
;
// this will change ascii into character.
eMessage
+=
a
;
// and store inn eMessage.
}
else
{
b
+=
theOffset
;
a
=(
char
)
b
;
eMessage
+=
a
;
}
}
else
if
(
theOffset
<
0
)
// This condition will be executed when the given offset is Negative
{
Add
=
b
+
theOffset
;
if
(
Add
<
65
)
{
Add
-=
64
;
Add
+=
90
;
a
=(
char
)
Add
;
eMessage
+=
a
;
}
else
{
b
+=
theOffset
;
a
=(
char
)
b
;
eMessage
+=
a
;
}
}
}
// ELSE #1 END
else
if
(
b
==
32
)
// Use to check Space
{
a
=(
char
)
32
;
eMessage
+=
a
;
}
else
// when charcter is not an Alphabet
{
eMessage
+=
a
;
}
}
// End For Loop
return
eMessage
;
}
}
\ No newline at end of file
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