# Essay on M150 TMA5 JAVA PROGRAMING

Submitted By dusancermak
Words: 870
Pages: 4

Tutor marked assignment 5 (M150)
By Dusan Cermak (dc8352)
Question 1

1. Decoding simple substitution ciphers using frequency analysis is based on the fact, that some letters, letter pairs and repeat letters are more frequent then others and some are rare, this pattern is translated to the cipher. Letters E, T, A and O are the most common in English text as well as pairs TH, ER, ON, and AN and doubles SS, EE , TT , and FF. If the text is long enough this information can be used to assign letters of alphabet to the letters of code, according to there fervency, repeating and length of words.

2. The code for the first word “eve” is “Bsjs”, where “B” is signal character. The second word ”ever” is coded “Crire” and “eavesdrop” is coded “Dqmhqepdabe”. The coded text will be “BsjsCrireDqmhqepdabe”

3. Decoded message is “ALBERTI THWARTS EVE” .

Structured English:
Initialise new Array with as many elements as original array. No values are assigned.
For every element in the original array
If position in array is 0 first element of the new array is the last element of the original array.
Else the shifted element is assigned a value of cipher element on (position -1)
Assign shifted alphabet to cipher alphabet
Return new array.

Function code: function right(letterArray)
{
// Initialise new Array with as many elements as original array. No values are assigned var shiftedArray = new Array(letterArray.length);
// for every element in the original array for (var x=0; x<letterArray.length; x=x+1) { if (x==0) // If position in array is 0 first element of the new array is the last element of the original array. shiftedArray[x] = cipherArray[letterArray.length-1]; else //Else the shifted element is assigned a value of cipher element on position (position -1) shiftedArray[x] = cipherArray[x-1]; } for (var y=0; y< letterArray.length; y=y+1) cipherArray[y] = shiftedArray[y]; // assign shifted alphabet to cipher alphabet return cipherArray; // return new array.

}

{
}

Structured English:
Declare signal character position index
For every element in cipher Alphabet
If signal character is equal to plain alphabet assign position to index.
Repeat as long as cipher alphabet element is different from index character
Use function right shift elements one position to the right
Returns aligned cipher alphabet

Function : function rotateToPosition(signalCharacter, indexCharacter, plainAlphabet, cipherAlphabet)
{
// declare signal character position index var index;
//repeat for every element in cipher alphabet for (var x=0; x<cipherAlphabet.length; x=x+1)
{
if (plainArray[x] == signalCharacter) // if signal character is equal to plain alphabet assign position to index. index = x;
}
while (cipherArray[index] != indexCharacter) // repeat as long as cipher alphabet element is different from index character right(cipherArray); // Use function right shift elements one position to the right return cipherArray; // returns aligned cipher alphabet
}

{