Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
asignment
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
thomas.unsworth
asignment
Commits
6773ebee
Commit
6773ebee
authored
Jan 02, 2019
by
tomun
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
part three
parent
2378f3da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
0 deletions
+102
-0
AssessmentPartThree.java
assessment03-18/src/AssessmentPartThree.java
+102
-0
No files found.
assessment03-18/src/AssessmentPartThree.java
0 → 100644
View file @
6773ebee
public
class
AssessmentPartThree
{
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
// An offset value is chosen to encrypt a message. Each letter is replaced by the
// letter that that number of places away from it.
// So if an offset value of 1 is chosen, each letter is replaced by the one after it
// - 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
int
charNum
=
(
int
)
theChar
;
if
((
65
<=
charNum
&&
charNum
<=
90
))
{
if
(
theOffSet
>
0
)
{
for
(
int
i
=
theOffSet
;
i
!=
0
;
i
--)
{
charNum
=
charNum
+
1
;
if
(
charNum
>
90
)
{
charNum
=
65
;
}
}
theChar
=
(
char
)
charNum
;
return
theChar
;
}
else
{
for
(
int
i
=
theOffSet
;
i
!=
0
;
i
++)
{
charNum
=
charNum
-
1
;
if
(
charNum
<
65
)
{
charNum
=
90
;
}
}
theChar
=
(
char
)
charNum
;
return
theChar
;
}
}
else
if
(
97
<=
charNum
&&
charNum
<=
122
)
{
if
(
theOffSet
>
0
)
{
for
(
int
i
=
theOffSet
;
i
!=
0
;
i
--)
{
charNum
=
charNum
+
1
;
if
(
charNum
>
122
)
{
charNum
=
97
;
}
}
theChar
=
(
char
)
charNum
;
return
theChar
;
}
else
{
for
(
int
i
=
theOffSet
;
i
!=
0
;
i
++)
{
charNum
=
charNum
-
1
;
if
(
charNum
<
97
)
{
charNum
=
122
;
}
}
theChar
=
(
char
)
charNum
;
return
theChar
;
}
}
else
{
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
String
encryptedMessage
=
""
;
for
(
int
i
=
0
;
i
<
theMessage
.
length
();
i
++)
{
encryptedMessage
+=
enryptedCharacter
(
theMessage
.
charAt
(
i
),
theOffSet
);
}
return
encryptedMessage
;
}
}
thomas.unsworth
@thomas.unsworth
mentioned in commit
0a27dfb6
·
Jan 02, 2019
mentioned in commit
0a27dfb6
mentioned in commit 0a27dfb623579ca4f482f07b0426748fbd68019c
Toggle commit list
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