Anda di halaman 1dari 31

UNIT 37 DEVELOPING

PROGRAMMING
SOLUTIONS
Kalvin Johnston

Contents
P1 | Development Environments........................................................................... 3
Legacy Environment........................................................................................... 3
Interactive Environment..................................................................................... 4
Shared Environment........................................................................................... 5
P2 | Software Development Process......................................................................5
Legacy vs. Modern Languages............................................................................5
Suitability of Languages..................................................................................... 6
Programming Languages.................................................................................... 6
High Level Programming Languages...............................................................6
Low Level Programming Languages................................................................6
Compilers, Interpreters and Parsers...................................................................7
Software Development Process..........................................................................7
Feasibility........................................................................................................ 7
Requirements Investigation & Analysis.........................................................7
Design............................................................................................................. 8
Implementation............................................................................................... 8
Testing............................................................................................................. 8
Maintenance.................................................................................................... 8
M1 | Software Specification................................................................................... 9
User Interface..................................................................................................... 9
Functional Specification.................................................................................... 10
Encryption Method 1 - Reverse......................................................................10
Decryption Method 1 - Reverse.....................................................................10
Encryption Method 2 Letter Substitution....................................................10
Decryption Method 2 - Letter Substitution.....................................................10
Encryption Method 3 Mixed.........................................................................11
Decryption Method 3 - Mixed.........................................................................11
Case Diagram................................................................................................... 11
P3 | Software Design............................................................................................ 12
Graphical User Interface................................................................................... 12
Pseudo Code..................................................................................................... 12
Reverse Encryption & Decryption..................................................................12
Addition Encryption....................................................................................... 12
Addition Decryption....................................................................................... 12
Mix Encryption............................................................................................... 13
1
Kalvin Johnston

Mix Decryption.............................................................................................. 13
Test Cases............................................................................................................ 13
P4 | Programming Solution..................................................................................14
Printed Code..................................................................................................... 14
Screenshots of the GUI & Button Functionality.................................................17
P5 | Debugging Techniques..................................................................................18
M2 | Appropriate Code Formatting.......................................................................20
P6 | Software Validation & Verification.................................................................21

2
Kalvin Johnston

P1 | Development Environments
Software Development Kits are required to build software. Typically each
programming language has its own kit. Most integrated development
environments have these included but have functionality to add more kits.
An integrated development environment (IDE) is a program that has tools to
coordinate with the development process. An IDE includes things like compilers
and text editors. Development environments usually have an ability to quickly
boot up the code youve written and allow you to test it. Examples of
development environments are: Microsoft Visual Studio and Notepad++. There
are many other alternatives that are also easy to use.
Some development environments are used for one specific programming
language, for example the IDE Eclipse is for the programming language Java.
Some IDEs allow use of plugins that can add more functionality. Notepad++
doesnt natively come with an execution feature, however you can use Plugin
Manager to search/find useful plugins.
All software development environments need some form of text editor to all code
to be created.

Legacy Environment

3
Kalvin Johnston

A legacy environment is
typically a text editor and a
compiler nothing else. You
have to write your code to a file
then call the compiler to
compile manually (usually by a
console). Testing, compiling,
etc. is usually a slower process,
as it takes longer to actually
navigate to the compiler.
FORTRAN is a legacy
programming language it has
no user interface. It consists of
the basic functions and no
graphical user interface.
FORTRAN is used for complex
mathematical and scientific
calculations. To compile
FORTRAN you have to write the
code to a file using a text editor
then save the file with an .f90
extension. From here you can
then proceed to compile using
the compiler this isnt built
into the text editor. FORTRAN is
not so different from modern
languages and is still used today. Most programming languages (modern or
legacy) all follow the same basic principles, using IF statements for example. You
can write machine code directly (without using a compiler), however developing
assembly line code is very error prone and time consuming.

Interactive Environment
An example of an interactive development environment is Microsoft Visual
Studio. This environment allows you to start producing C# and Visual Basic code
it already has the software development kits installed that are needed. It has all
the necessary tools required like a compiler and text editor Visual Studio also
comes with Syntax highlighting and predictive text that can be useful for
developers. Multiple files can also be opened inside one window of the
environment too which helps for easy of navigation. Most programming
languages (modern or legacy) all follow the same basic principles, for example
using IF statements, sequencing, assignment and loops. A windows developer
will typically use Visual Studio or Eclipse depending on their choice of language.
Interactive Environments are for single users. Emulators allow old software to run
and are often available with specific software development kits.

4
Kalvin Johnston

Shared Environment
A shared/collaborate environment allows multiple developers to work together on
a piece of software simultaneously. It is very useful for team projects. An
example is GitHub.
GitHub can be used in many ways. For example, it is possible to branch out of a
master copy and create a branch where others work. You never replace the
master copy with the newer version unless it has been fully tested. To the right is
a diagram of the concept of GitHub. The main repository is the black line. Newer
versions are branched off, created then tested before being added to the main
repository to ensure the newer version is stable.
GitHub has syntaxes stored for various languages and will allow you to see the
edits of each update (commit). They use red highlighting for removed code and
green for additions.

P2 | Software Development Process


Legacy vs. Modern Languages
When developing a new piece of software the choice of language needs to be
considered. A developer shouldnt rush straight into code but instead weigh up
the pros and cons of specific languages. There are a few considerations that
need to be thought of:

The time spent developing programming in machine code for example is


very time consuming and very error prone, meaning developers will spend
a lot of time getting the software to work flawlessly.
5

Kalvin Johnston

The cost of a redesign redesigning can be done for many reasons,


however is it worth the time and money needed to redesign? The cost will
have to be worth the advantages of the redesign. Typically a design isnt
worth the time and money therefore thinking about it would be unrealistic
for a business.
Future maintenance this is looking into the future and ensuring the
language you pick is well known and that another developer would easily
be able to pick off where you left off. Using more modern languages is
usually better for the long run maintenance-wise.
Support The software needs to be compatible with other operating
systems to run, having support for programming errors may also be hard
to find if the language used is not common. It is also good to have
premade libraries with common functions already made to save time.
Expansion Expanding the software already created may mean that other
languages will need to be used too. Software can be written in multiple
languages. It is also good to have premade libraries with common
functions already made to save time.

6
Kalvin Johnston

Suitability of Languages
Typically programming languages need to be compared for various reasons:

Development costs
Timescales certain languages can be more time consuming and error
prone.
Resources premade libraries.
Features premade libraries and interfaces linked to the code.
Scalability the combination of different software working together.
Code efficiency different programming languages have different
compilers that can affect code efficiency.
Processing power
Security exploits within languages may mean that it shouldnt be used.
Maintenance backwards compatibility is useful; using a language that
has backwards compatibility for every new version is advised (e.g.
FORTRAN).

Programming Languages
Programming languages can come in many forms, typically they are:

Object-orientated (e.g. C#). The concept is based from objects which can
contain data, attributes, etc.
Procedural (e.g. FORTRAN). Statements are structured into procedures
and subroutines.
Event driven (e.g. on button click in an application / on a website).
Operations are called when events happen.

High Level Programming Languages


High-level programming languages are languages that have structured
statements. These languages require compilers to translate the code into
machine code, however these compilers may reduce the efficiency of the code.
High-level programming languages arent dependant on a specific type of
computer, meaning they have a higher chance of compatibility.
Examples of high level programming languages: FORTRAN, and C#.

Low Level Programming Languages


Low-level programming assembler languages are specific to particular
microprocessors (e.g. 8/16/32 bit). Programming in these assembler languages
can improve code efficiency, as they arent translated via compilers. However,
these languages are very error prone and time consuming to ensure the code is
correct. Applications that are required to be built quickly shouldnt be made in a
low-level assembler language as it takes so much more time to create the
software.

7
Kalvin Johnston

Compilers, Interpreters and Parsers


Compilers, interpreters and parsers all have important roles within programming
languages.
Compilers allow for high level programming languages to be
converted/translated into machine code quickly. Compilers may not make the
code the most efficient; however if you dont need efficiency and prefer to have
software created quicker using a high level language and a compiler would be
the best option.
Interpreters directly execute high-level code into machine code and do not
require the compiling time. Often compiled programs run quicker than
interpreted software, however when testing small features/additions in code
interpreters save time for developers when testing especially as large programs
take a lot of time to compile. An interpreter is an alternative to a compiler.
Parsers are used with compilers to build data structures, giving a representation
of the data that was input (usually text). A parser is typically the reading function
of a piece of software.

Software Development
Process
A diagram of the waterfall
program development model is
to the right. The process is
broken into multiple stages:

Feasibility
The pros have to outweigh the
cons of creating the software. A
program must be worth the time
and money spent developing it
if its not, whats the point in
creating it? There is no point. Its a waste of time and money. A conclusion needs
to be made. It is often difficult to assess feasibility in advance when developing
software.

Requirements Investigation & Analysis


This is asking the customer for specific details and prompting them for answers
with questions. Its important to find out exactly what the customer needs the
software to do (functionality wise). This is to find the functional requirements of
the software. Customers may also specify how they want their interface to look
this is a non-functional requirement.
An investigation will need to take place to work out requirements (including
system requirements). A detailed report of the customers current system (even
operating system, etc.) should be made.
This is using all the information taken from the investigation and analysing it into
a written specification of what needs to be done. This will include the system
requirements, often both functional and non-functional requirements, the
programming language to use, etc. A conclusion and time estimation should be
given too.
8
Kalvin Johnston

This can be written in formats or as plain English. Using a more structured format
usually means that the requirements document isnt vague.

9
Kalvin Johnston

Design
This is taking a big problem and splitting it into multiple smaller sub tasks. In
order to break a problem into components you would use a design approach, and
would typically be pseudo code, flow charts and also classes to help break up
different areas of the code. Security issues/flaws should be taken into
consideration. Solutions for problems are thought of one at a time. Algorithms
need to be discussed for efficiency and speed.

Implementation
This involves taking flow charts, pseudo code and generating actual code in a
given programming language. Testing will take place in parallel with coding then
installing it onto machines (typically a few testing machines first).
Data structures and code are created/developed during Implementation.

Testing
Software should be given to a testing team to allow them to find flaws/issues in
the software. This prevents flawed software going onto the market and ensuring
there are no issues, therefore making your organisation look professional for
future projects.

Maintenance
Maintenance of software is important as future down the line an exploit or issue
(bug) may be found. The original source code should be easily readable and laid
out correctly to allow alternative developers to work on the code after youve
gone (e.g. proper indentations to keep code neat). Remote updates are usually a
good feature to have to fix bugs promptly.

10
Kalvin Johnston

M1 | Software Specification
A system that can encrypt and decrypt strings is required.
Each encryption method has a corresponding decryption method. If encryption
method 1 is used decryption method 1 must be used to undo the encryption.
There will be a total of 3 encryption/decryption methods.
A string is typed into the input textbox then the chosen decryption/encryption
method is chosen via radio buttons. This will result in a string being displayed to
the output textbox once the begin process button is clicked.
The system should be created using the programming language C#, which uses
the Visual Studio IDE.

User Interface
An input and output textbox is needed, along with a begin process button and 6
radio buttons to choose from the three encryption and three decryption methods.
Below is an interface design.

11
Kalvin Johnston

Functional Specification
Encryption Method 1 - Reverse
Input: string.
Source: input textbox.
Pre-conditions: input text from textbox in interface must be string and a non-null.
Function description: string from input textbox is taken and letters are reversed.
For example, the string abcd would be replaced by dcba. If the input string is
null an error message will be displayed.
Outputs: the encrypted string to output textbox.
Post-conditions: the output is the input string encrypted.

Decryption Method 1 - Reverse


Input: string.
Source: input textbox.
Pre-conditions: input text from textbox in interface must be string and a non-null.
Function description: string from input textbox is taken and letters are reversed.
For example, the string dcba would be replaced by abcd. If the input string is
null an error message will be displayed.
Outputs: the decrypted string to output textbox.
Post-conditions: the output is the input string decrypted.

Encryption Method 2 Letter Substitution


Input: string.
Source: input textbox.
Pre-conditions: input text from textbox in interface must be string and a non-null.
Function description: string from input textbox is taken. The letter is recorded as
the number in the alphabet then 6 is added onto it. For example, a is letter 1. 1
+ 6 = 7. Letter 7 in the alphabet is g, therefore a would be replaced by g.
If the input string is null an error message will be displayed.
Outputs: the encrypted string to output textbox.
Post-conditions: the output is the input string encrypted.

Decryption Method 2 - Letter Substitution


Input: string.
Source: input textbox.
Pre-conditions: input text from textbox in interface must be string and a non-null.
Function description: string from input textbox is taken. The letter is recorded as
the number in the alphabet then 6 is added to it. For example, a is letter 1. 1 6 = 7. Letter 7 in the alphabet is g, therefore a would be replaced by g. If
the input string is null an error message will be displayed.
Outputs: the encrypted string to output textbox.
Post-conditions: the output is the input string decrypted.

12
Kalvin Johnston

Encryption Method 3 Mixed


Input: string.
Source: input textbox.
Pre-conditions: input text from textbox in interface must be string and a non-null.
Function description: string from input textbox is taken and is reversed. For
example, the letter a would be replaced by z and the letter z would be
replaced by a.
The letters are now recorded as the number in the alphabet then 6 is added onto
it. For example, a is letter 1. 1 + 6 = 7. Letter 7 in the alphabet is g,
therefore a would be replaced by g. If the input string is null an error
message will be displayed.
Outputs: the encrypted string to output textbox.
Post-conditions: the output is the input string encrypted.

Decryption Method 3 - Mixed


Input: string.
Source: input textbox.
Pre-conditions: input text from textbox in interface must be string and a non-null.
Function description: string from input textbox is taken. The letters are now
recorded as the number in the alphabet then 6 is added onto it. The letters are
then reversed. For example, the letter a would be replaced by z and the
letter z would be replaced by a. If the input string is null an error message
will be displayed.
Outputs: the decrypted string to output textbox.
Post-conditions: the output is the input string decrypted.

Case Diagram
A user has access to all of the following operations:

13
Kalvin Johnston

Reverse
Encryption
Create Diagram
Reverse
Decryption
Create Elem ent
Letter
Substitution
Encryption
Select Elem ent
Us er

Letter
Substitution
Decryption
Move Elem ent
Mixed
Encryption
Res ize Elem ent
Mixed
Decryption
Define Elem ent

P3 | Software Design
Graphical User Interface
1. The user will input the text
they which to encrypt or
decrypt into the input
textbox.
2. The user will then tick an
option (radio button) for
what they wish to do (e.g.
they want to encrypt the
message using addition
encryption, therefore they
tick the corresponding tick
box).
3. Clicking on the begin
process will then begin the calculations using the algorithms and display
the output into the output textbox.

Pseudo Code
Data Variables
Inputarray
Outputarray

14
Kalvin Johnston

Reverse Encryption & Decryption


Input: inputarray: character array
Output: outputarray: character array
For I = 0 to inputarray.Length 1
outputarray[i] = inputarray[inputarray.Length 1 - i]

Letter Substitution Encryption


Input: inputarray: character array
Output: outputarray
abcdefghijklmnopqrstuvwxyzabcdef = alphabet.ToCharArray();

For I = 0 to inputarray.Length 1
For k = 0 to alphabet.Length
If inputarray[i] == alphabet[k]
outputarray[i] = alphabet[k+6]

Letter Substitution Decryption


Input: inputarray: character array
Output: outputarray
// same as encryption but alphabet is reversed

fedcbazyxwvutsrqponmlkjihgfedcba = alphabet.ToCharArray();

For I = 0 to inputarray.Length 1
For k = 0 to alphabet.Length
If inputarray[i] == alphabet[k]
outputarray[i] = alphabet[k+6]

Mix Encryption
The following methods are used in order:
1) Reverse Encryption
2) Letter Substitution Encryption

Mix Decryption
The following methods are used in order:
1) Letter Substitution Decryption
2) Reverse Decryption

Test Cases
The main functions above can be checked for corrections using unit testing.
These tests may be carried out in the alpha stage of development.
Name: Reverse Test (positive test)
Input: string = Hello World!
Expected outcome: string satisfies the precondition; output string should be !
dlroW olleH
Result: (Pass/Fail)
Name: Substitution Encryption Test (positive test)
15
Kalvin Johnston

Input: string = abCdEf


Expected outcome: string satisfies the precondition; output string should be
ghIjKl
Result: (Pass/Fail)
Name: Substitution Decryption Test (positive test)
Input: string = ghIjKl
Expected outcome: string satisfies the precondition; output string should be
abCdEf
Result: (Pass/Fail)

16
Kalvin Johnston

Name: Mixed Encryption Test (positive test)


Input: string = abCdEf
Expected outcome: string satisfies the precondition; output string should be
lKjIhg
Result: (Pass/Fail)
Name: Mixed Decryption Test (positive test)
Input: string = lKjIhg
Expected outcome: string satisfies the precondition; output string should be
abCdEf
Result: (Pass/Fail)
Name: Error Test (negative test)
Input: string = null
Expected outcome: display box with error message explaining input string is null
Result: (Pass/Fail)

P4 | Programming Solution
Observations and explanations are commented into the actual code (the green
text starting with //)
All datatypes and encryption/decryption methods are enclosed in a single class
below.

Printed Code
class Encryption // Stores data types and main encryption/decryption methods
{
// Main data types
public char[] inputarray;
public char[] outputarray;
public char[] mixarray;
public void BeginProcess(string input)
{
//Convert string into array and set other array max lengths to avoid errors
inputarray = input.ToCharArray();
outputarray = input.ToCharArray();
mixarray = input.ToCharArray();
}
public string GetResult()
{
// Return outputarray as string
return new string(outputarray);
}
//========[Encryption & Decryption 1]========//
public void ReverseEncryption()
{
for (int i = 0; i < inputarray.Length; i++)
{
// Set outputarray[i] inputarray's max - 1 - i
outputarray[i] = inputarray[inputarray.Length - 1 - i];
}
}
public void ReverseDecryption()
{
for (int i = 0; i < inputarray.Length; i++)
{

17
Kalvin Johnston

// Set outputarray[i] inputarray's max - 1 - i


outputarray[i] = inputarray[inputarray.Length - 1 - i];
}
}
//========[Encryption & Decryption 2]========//
public void AdditionEncryption()
{
char[] alphabetarray;
// Charaters we're willing to encrypt - duplications of last 6 letters to avoid errors
string alphabet = "abcdefghijklmnopqrstuvwxyzabcdef1234567890,.;:?/ @'#~][}{+=_()*&^%$!ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF";
alphabetarray = alphabet.ToCharArray();
for (int i = 0; i < inputarray.Length; i++)
{
for (int x = 0; x < alphabetarray.Length; x++)
{
if (inputarray[i] == alphabetarray[x])
{
outputarray[i] = alphabetarray[x+6];
break;
}
}
}
}
public void AdditionDecryption()
{
char[] alphabetarray;
// Encrypt2() alphabet reversed
string alphabet = "FEDCBAZYXWVUTSRQPONMLKJIHGFEDCBA!$%^&*)(_-=+{}
[]~#'@ /?:;.,0987654321fedcbazyxwvutsrqponmlkjihgfedcba";
alphabetarray = alphabet.ToCharArray();
for (int i = 0; i < inputarray.Length; i++)
{
for (int x = 0; x < alphabetarray.Length; x++)
{
if (inputarray[i] == alphabetarray[x])
{
outputarray[i] = alphabetarray[x + 6];
break;
}
}
}
}
//========[Encryption & Decryption 3]========//
public void MixEncryption()
{
char[] alphabetarray;
string alphabet = "abcdefghijklmnopqrstuvwxyzabcdef1234567890,.;:?/ @'#~][}{+=_()*&^%$!ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF";
alphabetarray = alphabet.ToCharArray();
// Reverse Encryption
for (int i = 0; i < inputarray.Length; i++)
{
mixarray[i] = inputarray[inputarray.Length - 1 - i];
}
// Addition Encryption to reversed encryption output (mixarray)
for (int i = 0; i < mixarray.Length; i++)
{
for (int x = 0; x < alphabetarray.Length; x++)

18
Kalvin Johnston

{
if (mixarray[i] == alphabetarray[x])
{
outputarray[i] = alphabetarray[x + 6];
break;
}
}
}
}
public void MixDecryption()
{
char[] alphabetarray;
string alphabet = "FEDCBAZYXWVUTSRQPONMLKJIHGFEDCBA!$%^&*)(_-=+{}
[]~#'@ /?:;.,0987654321fedcbazyxwvutsrqponmlkjihgfedcba";
alphabetarray = alphabet.ToCharArray();
// Addition Decryption
for (int i = 0; i < inputarray.Length; i++)
{
for (int x = 0; x < alphabetarray.Length; x++)
{
if (inputarray[i] == alphabetarray[x])
{
mixarray[i] = alphabetarray[x + 6];
break;
}
}
}
// Reverse decryption to addition decryption output (mixarray)
for (int i = 0; i < mixarray.Length; i++)
{
outputarray[i] = mixarray[mixarray.Length - 1 - i];
}
}
}

Code for the button functionality is below.

19
Kalvin Johnston

Screenshots of the GUI & Button Functionality


The interface for the encryption program is shown below.
The application cannot be
used in maximized mode.
Text inside the output
textbox is un-editable.
You can only copy/paste
the text in there.
Text inside the input
textbox is editable.
As shown in the
screenshot
to the left the
A sample execution of the program is carried out below, where
the
Mix Encryption works as
Input is in the left textbox and the encrypted text is in the right
expected.
textbox.
To use the program you
have to enter text into
the Input textbox (on the
left hand side) then
choose a method you
wish to apply. Then you
must click Begin

This is the code attaching buttons to the main functionality of the Encryption
class above.
private void button5_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(InputText.Text))
{
// If the input string is null return an error
MessageBox.Show("You have not gave input text!", "Invalid Input String",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
// Main code for the interface - attaches buttons with methods
encrypt.BeginProcess(InputText.Text);
if (radioButton6.Checked) encrypt.ReverseEncryption();
else if (radioButton1.Checked) encrypt.ReverseDecryption();
else if (radioButton4.Checked) encrypt.AdditionEncryption();
else if (radioButton2.Checked) encrypt.AdditionDecryption();
else if (radioButton5.Checked) encrypt.MixEncryption();
else if (radioButton3.Checked) encrypt.MixDecryption();
// Sets output text to result of encryption/decryption methods
OutputText.Text = encrypt.GetResult();
}
}

20
Kalvin Johnston

P5 | Debugging Techniques
When developing the application I used various techniques when debugging my
software. Below are screenshots of me using breakpoints to check the values
inside outputarray when testing the AdditionEncryption() function.

As you can see in the screenshots the input string is abCeDf then once
AdditionEncryption() is called the output string is ghIkJl this shows us that the
algorithm does work as it should. In my substitution method an a is changed to
g, etc. as shown above.
This is the second breakpoint at the end of the method.

21
Kalvin Johnston

As you can see in the screenshots the input string is ghIkJl then once
AdditionDecryption() is called the output string is abCeDf this shows us that
the algorithm does work as it should. In my substitution method a g is changed
to a, etc. as shown above.
This is the second breakpoint at the end of the method.
Using the watch list allows me to view the values of data variables as each
breakpoint is
reached.
As shown in the
screenshot to the
right an error has
occurred, but the

22
Kalvin Johnston

program can handle it and give out information regarding what is wrong and will
not continue.

23
Kalvin Johnston

M2 | Appropriate Code Formatting


Creating a consistent layout allows programmers to easily read structures and
the actual code. This helps developers to copy, change or maintain the code.
Good layout uses formatting to show emphasis on the structure of the code and
to make code easily readable. Some examples to help keep code clean and easy
to read are:

Write one statement per line


Write one declaration per line
Keep indentations as four spaces (one tab stop) if not done automatically
Keep at least one blank line between method definition and properties
Use of brackets in calculations to make calculations easier to
read/understand parentheses
Define data types / variables at the start of the function/method/class
Have braces ({ or }) lined up with each other when opening and
closing the brace

There are also some examples to help keep comments clean and easy to read:

Place comments on separate lines


Begin a comment text with an uppercase letter
End a comment with a period
Have a space between the // and the actual comment

An example of clean and easy to read code is below:


class Encryption // Stores data types and main encryption/decryption methods
{

// Main data types


public char[] inputarray;
public char[] outputarray;
public char[] mixarray;
public void AdditionDecryption()
{

char[] alphabetarray;
// Encrypt2() alphabet reversed
string alphabet = "FEDCBAZYXWVUTSRQPONMLKJIHGFEDCBA!$%^&*)(_-=+{}
[]~#'@ /?:;.,0987654321fedcbazyxwvutsrqponmlkjihgfedcba";
alphabetarray = alphabet.ToCharArray();
for (int i = 0; i < inputarray.Length; i++)
{
for (int x = 0; x < alphabetarray.Length; x++)
{
if (inputarray[i] == alphabetarray[x])
{
outputarray[i] = alphabetarray[x + 6];
break;
}
}
}
}
}

24
Kalvin Johnston

As you can see the example code above follows the guidelines listed above. The
application I have developed also follows them guidelines. I also have all my
functions and datatypes inside a class named Encryption.

P6 | Software Verification & Validation


Verification and validation (V&V) are stages of checking that a software system
meets the specification requirements and does its intended purpose. This is
usually carried out by software testers as part of the software development
lifecycle (SDLC).

Verification
This process provides confidence that a software application is consistent and
matches the requirements and design in the specification.
Software verification uses tests to check if an application is created correctly.

Verification Tests
Unit tests are tests that take place while code is still being developed. The
software is not complete yet. These tests prove each method coded is examined
thoroughly.
Integration tests are tests that take place after a prototype system has been built
and it satisfies the unit testing. These tests prove that individual methods work
together and can interact correctly within the user interface.
Large programs may have their tests generated by another program. Small
program tests are often carried out by the tester calling the program with
specific values, etc.

Validation
This process evaluates an application once the application has been developed
to determine if it meets the user requirements.
Validation checks that original specifications met the customers needs this lets
us know the product was completed correctly. Dynamic testing and other highlevel reviewing techniques are done to carry this out.
The customer can carry out validation tests as they would like to know that the
system has full functionality and performs well. The customer may also like to
check that the user interface is appropriate.

25
Kalvin Johnston

P7 | Verification and Validation Plan


Test Cases
Test cases are conditions which a tester uses to determine whether or not a
software system is working as intended by the creator. Many test cases provide
confidence in releasing a software system test cases show its ready for
release. At least two test cases should be carried out for each requirement: a
positive and a negative test.
Written cases should include descriptions of the functionality that needs testing.
Formal written test cases are characterized by a known input then using an
expected output which has been figured out before the test takes place. A known
input is a precondition and an expected output is a post condition.
During the actual coding of the application I used unit testing for each method to
ensure they worked correctly. Once I was happy with a method working I moved
on to the next method.

Examples
An example of requirements:
Input: string.
Source: input textbox.
Pre-conditions: input text from textbox in interface must be string and a non-null.
Function description: string from input textbox is taken and letters are reversed
via the alphabet. For example, the letter a would be replaced by z and the
letter z would be replaced by a. If the input string is null an error message
will be displayed.
Outputs: the encrypted string to output textbox.
Post-conditions: the output is the input string encrypted.
Example of testing:
Name: Mixed Decryption Test (positive test)
Input: string = lKjIhg
Expected outcome: string satisfies the precondition; output string should be
abCdEf
Result: (Pass/Fail) Pass
Name: Error Test (negative test)
Input: string = null
Expected outcome: display box with error message explaining input string is null
Result: (Pass/Fail) - Pass

26
Kalvin Johnston

Alpha Testing
Alpha tests are basic unit tests which help decide if individual methods work
correctly. These tests ensure that functionality in the specification requirements
is met. To test methods you could use break points and other debugging
techniques to view values, etc.
I have put my own basic unit tests in P3.

Beta Testing
Beta tests are complex unit tests which monitor and access the system when
processing long calculations, string, etc.
Using a long string (e.g. 256 characters) in the system I made would be an
example of beta testing.
Integration tests are also used to show that methods/components of the software
can work together. Several methods are tested together all at the same time.
Integration tests also ensure that the interface works with the methods (e.g.
buttons work, data being displayed are correct, data being input is correct, etc.).

Boundary Testing
Boundary tests are used to show that the system can withstand extreme inputs,
calculations, empty values, etc. The idea of boundary testing is that you want to
push the boundaries of your system to ensure it can cope. An example would be
can your program run correctly if an empty input string is entered does it crash
or give an error?

Customer Validation Testing


Customers want to validate their system is in fact what they stated in the
requirement specification. These pre-release tests are carried out by the end
user of the system.
Below are a few tests that would be carried out:

Do the encryption methods hide input text?


Does the system encrypt long strings quickly?
Is the graphical user interface (GUI) appropriate?
Can you decrypt the encrypted text?

If the answer to all the questions above are yes then the program should pass
customer validation tests.

27
Kalvin Johnston

P8 & M3 | Testing Programming Solution


Alpha Stage Unit Testing
Name: Reverse Test (positive test)
Input: string = Hello World!
Expected outcome: string satisfies the precondition; output string should be !
dlroW olleH
Result: (Pass/Fail) Pass
Name: Substitution
Encryption Test (positive test)
Input: string = abCdEf
Expected outcome: string
satisfies the precondition;
output string should be
ghIjKl
Result: (Pass/Fail) - Pass
Name: Substitution
Decryption Test (positive test)
Input: string = ghIjKl
Expected outcome: string satisfies the precondition; output string should be
abCdEf
Result: (Pass/Fail) - Pass
Name: Mixed Encryption Test (positive test)
Input: string = abCdEf
Expected outcome: string satisfies the precondition; output string should be
lKjIhg
Result: (Pass/Fail) - Pass
Name: Mixed Decryption Test (positive test)
Input: string = lKjIhg
Expected outcome: string satisfies the precondition; output string should be
abCdEf
Result: (Pass/Fail) Pass
Name: No Input Test
(negative test)
Input: string = null
Expected outcome: display
box with error message
explaining input string is
null
Result: (Pass/Fail) Pass
Comment: Error window
appears telling the user to
give an input.

28
Kalvin Johnston

Beta Stage Performance Testing


The speed of encryption and decryption was tested when using a long string. The
encryption and decryption was instantaneous; however, the size of the textboxes
could be increased for long encryptions as they are fairly small. Below is the
string used in the test. There is 553 characters in the string.
AAAAAAAAAAAAAAAbbbbbbbbCccccccccccccCDDDDDEeeeEEFFFFFFFFffffffffffff
ffGGGGGGGGGAAAAAAAAAAAAAAAbbbbbbbbCccccccccccccCDDDDDEeeeEEFFF
FFFFFffffffffffffffGGGGGGGGGAAAAAAAAAAAAAAAbbbbbbbbCccccccccccccCDDD
DDEeeeEEFFFFFFFFffffffffffffffGGGGGGGGGAAAAAAAAAAAAAAAbbbbbbbbCccccc
cccccccCDDDDDEeeeEEFFFFFFFFffffffffffffffGGGGGGGGGAAAAAAAAAAAAAAAbb
bbbbbbCccccccccccccCDDDDDEeeeEEFFFFFFFFffffffffffffffGGGGGGGGGAAAAAAA
AAAAAAAAbbbbbbbbCccccccccccccCDDDDDEeeeEEFFFFFFFFffffffffffffffGGGGGG
GGGAAAAAAAAAAAAAAAbbbbbbbbCccccccccccccCDDDDDEeeeEEFFFFFFFFffffffff
ffffffGGGGGGGGG.

Below is the output string:


MMMMMMMMMllllllllllllllLLLLLLLLKKkkkKJJJJJIiiiiiiiiiiiiIhhhhhhhhGGGGGGGGGGGGG
GGMMMMMMMMMllllllllllllllLLLLLLLLKKkkkKJJJJJIiiiiiiiiiiiiIhhhhhhhhGGGGGGGGGGG
GGGGMMMMMMMMMllllllllllllllLLLLLLLLKKkkkKJJJJJIiiiiiiiiiiiiIhhhhhhhhGGGGGGGGG
GGGGGGMMMMMMMMMllllllllllllllLLLLLLLLKKkkkKJJJJJIiiiiiiiiiiiiIhhhhhhhhGGGGGGG
GGGGGGGGMMMMMMMMMllllllllllllllLLLLLLLLKKkkkKJJJJJIiiiiiiiiiiiiIhhhhhhhhGGGGG
GGGGGGGGGGMMMMMMMMMllllllllllllllLLLLLLLLKKkkkKJJJJJIiiiiiiiiiiiiIhhhhhhhhGGG
GGGGGGGGGGGGMMMMMMMMMllllllllllllllLLLLLLLLKKkkkKJJJJJIiiiiiiiiiiiiIhhhhhhhhG
GGGGGGGGGGGGGG.

Integration with GUI


Each method was tested with the corresponding button on the GUI the output
displayed on the interface was correct and matched the expected outcome (see
the P8 | Alpha Stage Unit Testing for the expected outcomes).
Only one button can be checked at a time. To begin a process, you must have a
method selected, have input text and also click the begin process button.

29
Kalvin Johnston

Validation & Verification


The screenshot to the right
shows that I have
implemented a feature to
ensure that a non-null string
is entered. If a string wasnt
entered and there were no
error message box users
may crash the application
it wouldnt be stable or
have good system integrity.

Customer Acceptance Testing


Below are a few questions that the customer will have to ask themselves:

Do the encryption methods hide input text?


Does the system encrypt long strings quickly?
Is the graphical user interface (GUI) appropriate?
Can you decrypt the encrypted text?
Does the system meet the specified requirements?

After giving the system to the customer they carried out there tested and
believed that two of the encryption methods scrambled the texted. However,
they wanted the reverse encryption method changed to something
stronger/harder to unscramble.
They tested encrypting long strings and came to the conclusion that the
application processed encrypting string with reasonable speeds (practically
instantaneous).
They believed the colour scheme in the application was appropriate and the
layout was also friendly. However, they wanted larger input and output textboxes
as they may be encrypting/decrypting large strings.
Decrypting the encrypted text also worked fine (as tested in Unit Testing).
Overall the system did meet their specified requirements.

User Acceptance Testing


The user tested the encryption methods to determine if they believed the text
was scrambled sufficiently. As stated above in the customer acceptance testing
the encrypt methods did scramble the text enough apart from the reverse
encryption.
The customer and user both suggest changing the reverse encryption method as
it is weak and not sufficient.

D2 | Evaluation & Optimization

30
Kalvin Johnston

Anda mungkin juga menyukai