Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assignment 03-18
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
emmanuel.gutzmore
Assignment 03-18
Commits
bb4e5a40
Commit
bb4e5a40
authored
Jan 07, 2019
by
Emman
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
61 additions
and
25 deletions
+61
-25
AssessmentPartThree.java
src/AssessmentPartThree.java
+61
-25
No files found.
src/AssessmentPartThree.java
View file @
bb4e5a40
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
// 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 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
private
static
String
letters
=
"a"
;
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
return
'a'
;
int
index
=
-
1
;
for
(
int
i
=
0
;
i
<
letters
.
length
();
i
++)
{
char
ch
=
letters
.
charAt
(
i
);
if
(
ch
==
theChar
)
{
index
=
i
;
}
}
if
(
index
==
-
1
)
{
for
(
int
i
=
0
;
i
<
letters
.
toUpperCase
().
length
();
i
++)
{
char
ch
=
letters
.
toUpperCase
().
charAt
(
i
);
if
(
ch
==
theChar
)
{
index
=
i
;
}
}
if
(
index
==
-
1
)
return
theChar
;
else
{
if
(
theOffset
<
0
)
{
if
(
index
+
theOffset
<
0
)
return
letters
.
toUpperCase
().
charAt
(
26
+
(
index
+
theOffset
)
%
26
);
return
letters
.
toUpperCase
().
charAt
(
index
+
theOffset
%
26
);
}
return
letters
.
toUpperCase
().
charAt
(
index
+
theOffset
%
26
);
}
}
if
(
theOffset
<
0
)
{
if
(
index
+
theOffset
<
0
)
return
letters
.
charAt
(
26
+
(
index
+
theOffset
)
%
26
);
return
letters
.
charAt
(
index
+
theOffset
%
26
);
}
return
letters
.
charAt
(
index
+
theOffset
%
26
);
}
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
return
"Encryptred message"
;
String
str
=
""
;
if
(
null
!=
theMessage
&&
!
theMessage
.
trim
().
isEmpty
())
{
for
(
int
i
=
0
;
i
<
theMessage
.
length
();
i
++)
{
str
+=
enryptedCharacter
(
theMessage
.
charAt
(
i
),
theOffset
);
}
}
return
str
;
}
}
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