Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Part03
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
Assessment
Part03
Commits
39bb1959
Commit
39bb1959
authored
Dec 03, 2018
by
neil.whitehead
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
12:08 03/12/18
parent
e56f0d16
Pipeline
#377
failed with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
19 deletions
+50
-19
AssessmentPartThree.java
src/AssessmentPartThree.java
+50
-19
No files found.
src/AssessmentPartThree.java
View file @
39bb1959
...
...
@@ -8,25 +8,56 @@ public class AssessmentPartThree {
// - so a becomes b, b becomes c, etc
// If a value of -2 is chosen a becomes y, b becomes z and so on
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
return
'a'
;
}
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
//Uppercase characters
if
((
theChar
>=
65
)
&&
(
theChar
<=
90
))
//65 to 90 = A to B
{
theChar
=
(
char
)
(((
theChar
-
65
+
theOffset
)
%
26
)
+
65
);
}
//Lowercase characters
else
if
((
theChar
>=
97
)
&&
(
theChar
<=
122
))
// 97 to 122 = a to b
{
theChar
=
(
char
)
(((
theChar
-
97
+
theOffset
)
%
26
)
+
97
);
}
/*
theChar = (char) (((theChar - 97 + theOffset) % 26) + 97); formulae
(theChar - 97 - ASCII a/A to give value between 1 and 26
+ theOffset) + the offset value
( % 26) % modulo ensures value is always between 1 and 26
( + 97) + ASCII a/A to return result to ASCII char
(char) result needs to be casted to char
*/
return
theChar
;
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
char
chaMessageArr
[]
=
theMessage
.
toCharArray
();
char
[]
chaResultArr
=
new
char
[
chaMessageArr
.
length
];
//initialising Arrays
for
(
int
i
=
0
;
i
<
chaMessageArr
.
length
;
i
++)
//loop to run through each character in encrypted message
{
chaResultArr
[
i
]
=
enryptedCharacter
(
chaMessageArr
[
i
],
theOffset
);
//passing each character to decryption method and saving result in array
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
return
"Encryptred message"
;
}
return
(
new
String
(
chaResultArr
));
//converting result array into string, and returning this
}
}
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