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
f85758b3
Commit
f85758b3
authored
Jan 04, 2019
by
neil.whitehead
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FINAL
parent
ff9e8560
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
AssessmentPartThree.java
src/AssessmentPartThree.java
+24
-24
No files found.
src/AssessmentPartThree.java
View file @
f85758b3
/**
* <b>Assessment</b> part three<br>
* <b>Created</b> 08/11/18<br>
* <b>Modified</b> 04/01/18<br>
* @author <a href = "mailto:neil.whitehead@yorksj.ac.uk"> Neil Whitehead</a>, <a href = "mailto:a.guest@yorksj.ac.uk">Andrew Guest</a>
*/
public
class
AssessmentPartThree
public
class
AssessmentPartThree
{
{
/**
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
* Descripts characters using Caesar cipher <br>
// An offset value is chosen to encrypt a message. Each letter is replaced by the
* Assumes that no validation checks are required.
// letter that that number of places away from it.
* @param theChar char
// So if an offset value of 1 is chosen, each letter is replaced by the one after it
* @param theOffset int
// - so a becomes b, b becomes c, etc
* @return theChar char
// If a value of -2 is chosen a becomes y, b becomes z and so on
*/
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
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
//Dealing with negative offsets
//Dealing with negative offsets
theOffset
=
(
theOffset
<
0
)
?
26
+
theOffset
:
theOffset
;
theOffset
=
(
theOffset
<
0
)
?
26
+
theOffset
:
theOffset
;
//ensures that the offset will
"wrap around" by finding corresponding
positive value
//ensures that the offset will
properly "wrap around" by finding complementary
positive value
//Uppercase characters
//Uppercase characters
if
((
theChar
>=
65
)
&&
(
theChar
<=
90
))
//65 to 90 = A to B
if
((
theChar
>=
65
)
&&
(
theChar
<=
90
))
//65 to 90 = A to B
...
@@ -40,18 +38,21 @@ public class AssessmentPartThree
...
@@ -40,18 +38,21 @@ public class AssessmentPartThree
( + 97) + ASCII a/A to return result to ASCII char
( + 97) + ASCII a/A to return result to ASCII char
(char) result needs to be casted to char
(char) result needs to be casted to char
*/
*/
return
theChar
;
return
theChar
;
//any non alphabetical chars will fall through and return original char
//any non alphabetical chars will fall through and return original char
}
}
/**
* Decripts strings using Caesar cipher <br>
* Assumes that no validation checks are required.
* @param theMessage string
* @param theOffset int
* @return chaResultArr string
*/
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
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
chaMessageArr
[]
=
theMessage
.
toCharArray
();
char
[]
chaResultArr
=
new
char
[
chaMessageArr
.
length
];
char
[]
chaResultArr
=
new
char
[
chaMessageArr
.
length
];
//initialising Arrays
//initialising Arrays
...
@@ -62,7 +63,6 @@ public class AssessmentPartThree
...
@@ -62,7 +63,6 @@ public class AssessmentPartThree
chaResultArr
[
i
]
=
enryptedCharacter
(
chaMessageArr
[
i
],
theOffset
);
chaResultArr
[
i
]
=
enryptedCharacter
(
chaMessageArr
[
i
],
theOffset
);
//passing each character to decryption method and saving result in array
//passing each character to decryption method and saving result in array
}
}
return
(
new
String
(
chaResultArr
));
return
(
new
String
(
chaResultArr
));
//converting result array into string, and returning this
//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