Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Curtin University of Technology,

Departments of Computer Science, and Imaging and Applied Physics

Scientific Computing 101


Exercise Cover Sheet

Title:
Encryption/Decryption Theory

Student Name & Id.: Kyle Pellerin 1880 7587


Class (day/time): Thursday 3pm-5pm
Instructor Name: Ketesse Hansen

Notes:
1. Late submissions will be marked normally then mark will be reduced by 10% of total allocated marks per calendar
day late.
2. Marks will be scaled by number of tasks attempted - if you attempt 1/3 of the tasks, you will get 1/3 of the marks.
3. You will get marks even for programs that you can’t get to work, so if you run out of time, submit them anyway.

Assessment Criteria

Criteria Totals
Program coding
Coding style (ie. following “Rules for good programming”)
Implementation of algorithms
Successful completion of programming tasks
Professional presentation of exercises
Cover sheet included
Sufficient text explaining exercise aims and results
Headings where appropriate
Figures labelled
Program testing and sample output
Adequate range of tests carried out
Appropriate presentation of sample output

Total possible mark 10

Marker’s comments:

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics

Encryption.m

Aim:

A program/function with the capacity to encrypt/decrypt any phrase consisting of only letters and
numbers (capitalised and spaces included), with the added functionality of 2 different passwords/keys
and unique representations of letters will be used for increased security. Several checks should also be
in place to ensure code runs smoothly.

The purpose of this program is to be used to send secure messages or sensitive information over a
network that is being monitored. The sender should be able send an encrypted message that cannot be
viewed by an unwanted person. The receiver should be able to decrypt the encryption using the
password related keys and read the message accurately.

Background/Theory:

Encryption is related to the theory of cryptography, which is a systematic approach to protecting


information over computer networks (Dan Boneh and Victor Shoup, 2016). Usually used to ensure two
people can communicate whilst third parties cannot understand the information being received, the
process of converting normal text into secret code is called ciphering (Gary C. Kessler, 2019). Whilst
this sounds simple in theory, the development of software to penetrate and obtain sensitive data has
increased (Alexander W. Dent, 2006). Thus, the necessity for strong encryption methods is required for
data used for banking, storing passwords and other personal information.

Cryptography requires five different aspects to function properly in order for the delivery to execute
well. These five are (Gary C. Kessler, 2019):
1. Privacy: To ensure messages sent are secure and not being read by unwanted recipients.
2. Authenticity: To prove and acknowledge that the sender sent the message.
3. Integrity: Works consistently the same using the same information, however cannot be
misrepresented mid-transmission.
4. Acknowledgement: Receiver is able to prove the message was sent by the intended sender,
additionally with proof.
5. Key transfer: A method of transferring keys used for the encryption.

The encryption process is as follows: Alice (sender) sends normal generic text (plain text) into a
process or program which converts into ciphered text (secret code), thus able to send ciphered text over
a server. An observer (Oscar) without the encryption program cannot read ciphered text, thus the
receiver (Bob) can decipher the text and read it privately.

Alice sends (plain text)  Cipher Process (ciphered text)  Server

Server Oscar receives (ciphered text)

Server Bob (ciphered text)  Cipher Process (plain text)  Bob receives (plain text)

There exists different methods of cryptography each with their own strengths and weaknesses, thus
different methods share different purposes for encryption (Gary C. Kessler, 2019). Symmetric Keys are
used as the name suggests symmetrically, this is done by using the same key for encryption as well as
decryption (Kefa Rabah, 2005). The name ‘private key’ is used as it assumes both the sender and

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
receiver have predetermined the password prior to encryption (Kefa Rabah, 2005). Some initial
problems with this method is the exchange of the private key, the key needs a secure form of
communication in order to exchange information by either through a secure network or in person
(Satish et al., 2012).

An asymmetric key system works differently in that it has a public key attributed with the code to be
ciphered, this system allows communication to occur secretly without the initial secret exchange (Kefa
Rabah, 2005). Two keys are used, the private key and a public key (Satish et al., 2012). Typically users
encrypt using the public key whilst decrypting using the private key, this allows in theory for multiple
users to send and receive messages securely (Satish et al., 2012).

For symmetric key systems, there consists of two different types: stream ciphers and block ciphers.
Stream cipher systems look at each bit of data individually by using a feedback system in which the
key is constantly changing, whilst block cipher systems use the same key to change different ‘blocks’
of data (Satish et al., 2012).

However methods can vary between symmetric key and asymmetric key systems. A symmetric
substitution method for example, takes bits of data from the input and modifies it using an algorithmic
relationship in a way that makes it difficult for someone to view the output and trace it back to the input
(Kefa Rabah, 2005). Contrastingly, the transposition method for asymmetric key systems changes two
bits of information whilst maintaining all other information (Kefa Rabah, 2005).

The encryption program I have designed uses a symmetric substitution method; therefore for security it
is required to use an algorithmic method of converting data. Whilst the idea of using a public key is
enticing, my program will be using a private key system due to the complexity of public key systems.
My method also uses a block cipher method, by this it uses the key to change blocks of data that
represent characters for every bit of data. It therefore handles each character individually and in theory
each character should be represented differently. However vulnerabilities may be present with the
algorithmic method used and therefore should not be used to encrypt sensitive data.

It should be noted that I do use variables labelled ‘Public Key’ as I did intend to use some sort of Public
Key system, however, later I relied more heavily on a private key system due to complexity issues.
Thus, the Public Key used in my program is just an extended private key. Without both keys, the
decryption process cannot be executed.

For storing data, I will be using MatLab’s containers.Map() function.

General (How my function works):

1. All variables are defined:


o Private key
o Public Key
o Phrase
o Whether the user wants to encrypt or decrypt
 Simple integer input function can be used. 1 for Encrypt, 2 for Decrypt
o Set for pre-set data sets per character.
 E.g. Letter_A = ‘woseG’
2. Simple checks are in place to ensure data parameters are met such as:
o Only letters/numbers

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
 Uses a system in which compares string data to a pre-set string variable. If the
inputted string has a character which is not approved, the code will result in a
logical result of False or 0. It will check every letter of the string.
 Using a variable we can check every letter, by using an array of logically defined
information we can see if something is there that shouldn’t be.
 private_key(PrKCheck:PrKCheck) == Sample_withspace;
o Integer within correct range
 Simple OR statement can be used: 1 || 2
3. Change private key into an encrypted language that can be used
o Using the database set for characters, replace every character with its corresponding
encrypted text
 Example: ‘aa’ would be changed into ‘woseGwoseG’
4. Using a substituted cipher method, convert the raw converted password into an easy to handle
compact form.
o A separate function has been designed to handle this for several parts of the function.
Named strhandle(). This function handles a string and transforms it uniquely but also in
a reproducibly way so that it can be replicated reliably.
 It uses a frequency variable in which if the same frequency is used for the same
target letter, the output will always be the same. A target letter is the character to
be transformed or converted; each character has its own pre-set string.
 The process involves moving around the string characters to different positions.
For example:
 ‘12345’  ‘23451’  ‘34512’ …ect
 After a while it reaches a point where all possible combinations are
obtained by moving one letter to the back. Thus moving one letter by two
spaces instead of one is needed: ‘12345’  ‘21345’
 It can now repeat the one step procedure of moving characters to the back
 After those options are exhausted, we can now move the front character
by 3 spaces… ‘12345’  ‘23145’
 Repeating this pattern until all options are exhausted
 Frequency is counted for every change made, if the frequency variable equals the
count… the function stops and the result is produced.
o By using strhandle() we can have a different database for every step we take and
therefore same characters will be represented by different code.
o By using this database (separate from the database for letters) we can change the target
letter. If the target letter is ‘w’, the code looks for the database for ‘w’ and by using
strhandle() it has been set that for string ‘w’ it now changes into ‘I’. However, because
this code handles every character individually, one step will look like this:
‘woseGwoseG’  ‘IoseGwoseG’
 Future steps will be different, so that both ‘w’ characters are not the same.
Example: ‘IoseGwoseG’ could end up being ‘I4gT2pllg9’ where ‘I’ and ‘p’ are
where ‘w’ used to be.
o It does this for the raw encrypted password until it equals a length of 15. It takes the
back letter and changes the first letter, and then it takes the back letter and changes the
second letter, deleting the last letter each time a change is made.
5. Once the password is compact to a length of 15. Each first character of the private key and
public key are compared and converted using the same strhandle() process. Example:
o Compact private key = ‘abcde12345ABCDE’
o Public key = ‘zyxwu09876ZYXWU’

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
 For the first instance ‘a’ is the target letter, using a frequency of 1. ‘z’ is inputted
into the fresh database created by target ‘a’ and frequency ‘1’ which produces
‘P’.
 For the second instance ‘b’ is the target letter, using a frequency of 2. ‘y’ is
inputted into the fresh database created by target ‘b’ and frequency ‘2’ which
produces ‘u’.
 So far producing an end result ‘Pu’…
 Process is repeated for all characters.
6. Once the new password has been created using the private and public key, the phrase must now
be converted into encrypted code. To do this, it will use the letters database.
o The first letter of the new password is compared for every first letter of the database and
then changed using strhandle().
o After the second letter of the new password is compared for every second letter of the
database… and so forth until every letter of every character has been changed
completely.
o Once we have our new formed character database we can now change the first letter of
the phrase into encrypted code. Example:
 If the first letter of the phrase is ‘A’ it may be converted from ‘woseG’ to
‘N5jaP’ so that for this first instance ‘A’ equals ‘N5jaP’ instead of ‘woseG’.
This is repeated for every letter in the phrase.
 We change the whole database instead of just one character so that we remain
consistent and can retrace our steps for decryption. If we only changed one
character for encryption it would become very difficult to separate what
character is meant to be decrypted, thus if all are changed in the same sequence
we only need to keep count of how many time we overall change character code.
7. Contrastingly if we intend to decrypt code, the phrase will be 5 times longer than before. So we
know how many overall characters are present. Thus we can look at each individual character in
sequence and change the database in the same way. If we are able to pair ‘woseG’ to ‘A’ we
then convert accordingly.

Examples:

>> encryption
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>1
Input password: kyle!!!
Please input only letters and numbers
Input password: WineBottleLateNite5
Input phrase: hehehehehe
Type 1 to get new public key
Type 2 to reuse old public key
>1
Your public key is: E1Z2jOYimLJfVHI
New phrase: Ht0dkoBNGJoJM63TCwisLdjGuzLdxMigiN5OLWOooeSBbLZJlD
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
Spaces are permitted in passwords and phrases
>2
Input password: WineBottleLateNite5
Input phrase: Ht0dkoBNGJoJM63TCwisLdjGuzLdxMigiN5OLWOooeSBbLZJlD
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: E1Z2jOYimLJfVHI
New phrase:
'hehehehehe'

Notes: For this example it can be seen that the check works correctly and thus ensures only the correct
letters/numbers are present. The final produced encryption is:
‘Ht0dkoBNGJoJM63TCwisLdjGuzLdxMigiN5OLWOooeSBbLZJlD’. We can break up this code to
see how the program handles different ‘h’ and ‘e’ characters.

Ht0dk oBNGJ oJM63 TCwis LdjGu zLdxM igiN5 OLWOo oeSBb LZJlD
h e h e h e h e h e

This works as intended.

However if we use a password that is similar to the original but is not quite the same, some code may
be decrypted despite not having the complete password. Although as the password length increases and
becomes more complex the security of the encryption increases also. Example:

>> encryption
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: winebottlelatenite5
Input phrase: Ht0dkoBNGJoJM63TCwisLdjGuzLdxMigiN5OLWOooeSBbLZJlD
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: E1Z2jOYimLJfVHI
New phrase:
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: WineBottleLateNite
Input phrase: Ht0dkoBNGJoJM63TCwisLdjGuzLdxMigiN5OLWOooeSBbLZJlD
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: E1Z2jOYimLJfVHI
New phrase:

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: wineBottleLateNite5
Input phrase: Ht0dkoBNGJoJM63TCwisLdjGuzLdxMigiN5OLWOooeSBbLZJlD
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: E1Z2jOYimLJfVHI
New phrase:

Note: In this attempt no result is produced despite being very similar to original password.

For this example the original password used was ‘kylep’ and the original public key was
‘yefgo9KJCEFsdqD’ producing a final encrypted message of
‘VutGz720PxSRBiNOTRnLljwIIF6u67jACeVJaHlEgbWi9SKXBesBeBT’. However the following
variations did not produce any results:
 kyle
 kyleo
 kyle1
 kylee
 kyleP
 Kylep

Example:
>> encryption
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>1
Input password: kylep
Input phrase: Hello world
Type 1 to get new public key
Type 2 to reuse old public key
>1
Your public key is: yefgo9KJCEFsdqD
New phrase: VutGz720PxSRBiNOTRnLljwIIF6u67jACeVJaHlEgbWi9SKXBesBeBT
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: kyle
Input phrase: VutGz720PxSRBiNOTRnLljwIIF6u67jACeVJaHlEgbWi9SKXBesBeBT
Type 1 to get new public key
Type 2 to reuse old public key
>2

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
Please input public key: yefgo9KJCEFsdqD
New phrase:
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: kyleo
Input phrase: VutGz720PxSRBiNOTRnLljwIIF6u67jACeVJaHlEgbWi9SKXBesBeBT
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: yefgo9KJCEFsdqD
New phrase:
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: kyle1
Input phrase: VutGz720PxSRBiNOTRnLljwIIF6u67jACeVJaHlEgbWi9SKXBesBeBT
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: yefgo9KJCEFsdqD
New phrase:
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: kylee
Input phrase: VutGz720PxSRBiNOTRnLljwIIF6u67jACeVJaHlEgbWi9SKXBesBeBT
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: yefgo9KJCEFsdqD
New phrase:
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: kyleP
Input phrase: VutGz720PxSRBiNOTRnLljwIIF6u67jACeVJaHlEgbWi9SKXBesBeBT
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: yefgo9KJCEFsdqD
New phrase:

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: Kylep
Input phrase: VutGz720PxSRBiNOTRnLljwIIF6u67jACeVJaHlEgbWi9SKXBesBeBT
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: yefgo9KJCEFsdqD
New phrase:

Note: This suggests this program is reliable even at shorter passwords.

Example:

>> encryption
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>1
Input password: 4389amsd23
Input phrase: Hello world can you read me
Type 1 to get new public key
Type 2 to reuse old public key
>1
Your public key is: HrR0ULGhK4cyvZp
New phrase:
MpOlZeC9IcXGk2RGl6taGaCLRqCTsGqdQWI1Ldc8Ql44zpJec63QabOSST9Vplp0L79egdJ3zwvOe
k91LdDC31tiCaJ5axabsTqssahr0bqr38qBuxSrDiR7jhKVQO2HrpbeQmt
Type 1 for Encryption
Type 2 for Decryption
Please note, only use letters and numbers
Spaces are permitted in passwords and phrases
>2
Input password: 4389amsd23
Input phrase:
MpOlZeC9IcXGk2RGl6taGaCLRqCTsGqdQWI1Ldc8Ql44zpJec63QabOSST9Vplp0L79egdJ3zwvOe
k91LdDC31tiCaJ5axabsTqssahr0bqr38qBuxSrDiR7jhKVQO2HrpbeQmt
Type 1 to get new public key
Type 2 to reuse old public key
>2
Please input public key: HrR0ULGhK4cyvZp
New phrase:
'Hello world can you read me'

Note: works as intended.

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
Conclusion
Overall the function works great; however a few things can be determined such as how many
characters are originally present. Also it may be possible to work backwards to find the passcode, this
is due to the systematic way this function works. However it may take some serious time to hack, I am
not sure. It is possible to produce a letter or two with the wrong password, although it proved difficult
to replicate, if this is possible, it could be evidence that this encryption method isn’t as secured as
planned. Despite this, it works well.

References:

Boneh, Dan, and Victor Shoup. A Graduate Course in Applied Cryptography. 2016. Accessed May 31,
2019. https://crypto.stanford.edu/~dabo/cryptobook/draft_0_3.pdf.
Dent, Alexander W. "Fundamental Problems in Provable Security and Cryptography." 2006.
https://eprint.iacr.org/2006/278.pdf.
Kessler, Gary C. "An Overview of Cryptography." An Overview of Cryptography. 2019.
https://www.garykessler.net/library/crypto.html.
Rabah, Kefa. 2005. "Theory and Implementation of Data Encryption Standard: A Review. Information
Technology Journal." 10.3923/itj.2005.307.325.
SATISH, GANTI & Raghavendran, Dr. Ch V & T K Mehar, P & P Suresh Varma, Dr. (2012).
SECRET KEY CRYPTOGRAPHIC ALGORITHM. 1. Retrieved from:
https://www.researchgate.net/publication/266389826_SECRET_KEY_CRYPTOGRAPHIC_A
LGORITHM

Appendix:

Encryption.m

function encryption ()

% Kyle Pellerin 22/04/2019

% display 'warning about writing down passwords case sensentive and in a secure
% location.
%
% Input all key variables including encrypt/decrypt, password, public key and
phrase.
%
% after all password variables and default characters are created.
% we now have change the password into encryption. therefore apple becomes a
% length('apple') times 5 string variable. we now have to convert that into a 15
character
% password, this is to shorten and make it more compact.
%
% To do this we take the raw password and compare the first and last letters ('a'
and 'e').
%
%
% 'we now use [code] function to change according to each other.
% Example: 'ap' and 'pl' changes to 'bw' and then 'bw' and 'e' changes to 'bwe'.
% It must always result in the same unique combination.

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
%
% Right here will be the code which uses the variables of whether it's an
% encrypt or decrypt. If encrypt process A will be used, else then process B.
%
% Process A:
%
% This is the same way in which it will now change the phrase.
% 'bwe' changes 'hello' by first focusing on the first letter 'h'. then by the
% same process [code] function 'bwe' will change into 'hfw' which will now focus
% the next letter 'e'. and so forth. This is so that duplicate letters like 'l'
% do not have the same encryption combination.
%
% Process B:
%
% This is the same way in which it will now decode the phrase.
% This is work because we are not changing the core flow of the program, only the
% application. Instead of changing single letters into 5 letters, we're doing the
% opposite - 5 letters into a single letter.
% 'bwe' changes 'hello' by first focusing on the first letter 'h'. then by the
% same process [code] function 'bwe' will change into 'hfw' which will now focus
% the next letter 'e'. and so forth. This is so that duplicate letters like 'l'
% do not have the same encryption combination.
%
% After display new phrase, either decoded or encoded.

Start_Program = 1;
Sample_nospace = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
Sample_withspace = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890
';

while Start_Program == 1

disp('Type 1 for Encryption');


disp('Type 2 for Decryption');
disp('Please note, only use letters and numbers');
disp('Spaces are permitted in passwords and phrases');

%checks Encrypt or Decrypt values


while Start_Program == 1
EncryptOrDecrypt = input('> ');
if EncryptOrDecrypt == 1 || EncryptOrDecrypt == 2
Start_Program = 2;
else
disp('Error, please type either 1 or 2')
end
end
Start_Program = 1;

%checks private key for valid characters

PrKCheck=0;
PrKCheck_loop = 1;
while PrKCheck_loop==1
PrKCheck = PrKCheck +1;
private_key = input ('Input password: ', 's');
while PrKCheck>0
if PrKCheck == 1
PrKvar= private_key(PrKCheck:PrKCheck) == Sample_withspace;
else

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
PrKvar= PrKvar + (private_key(PrKCheck:PrKCheck) ==
Sample_withspace);
end
if PrKCheck == length(private_key)
if length(private_key)<4
disp('Please input a password of length 4 or greater');
private_key= '';
end
if sum(PrKvar) == length(private_key)
PrKCheck_loop = 0;
PrKCheck= -100;
else
PrKCheck = -1;
disp('Please input only letters and numbers');
end

end
PrKCheck = PrKCheck +1;
end
end
%checks phrase for valid characters
phraseCheck=0;
phraseCheck_loop = 1;
while phraseCheck_loop==1
phraseCheck = phraseCheck +1;
phrase = input ('Input phrase: ', 's');
while phraseCheck>0
if phraseCheck == 1
phrasevar= phrase(phraseCheck:phraseCheck) == Sample_withspace;
else
phrasevar= phrasevar + (phrase(phraseCheck:phraseCheck) ==
Sample_withspace);
end
if phraseCheck == length(phrase)
if sum(phrasevar) == length(phrase)
phraseCheck_loop = 0;
phraseCheck= -100;
else
phraseCheck = -1;
disp('Please input only letters and numbers');
end
end
phraseCheck = phraseCheck +1;
end
end
Public_Key = randsample(Sample_nospace,15);

PubK_Check=1;
while PubK_Check==1
disp('Type 1 to get new public key');
disp('Type 2 to reuse old public key');
PubK_oldnew = input('> ');
if PubK_oldnew == 1 || 2
PubK_Check=0;

else
disp('Please type either 1 or 2');
end
end

if PubK_oldnew == 1

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
disp(['Your public key is: ', Public_Key]);
elseif PubK_oldnew == 2
while PubK_oldnew == 2
Public_Key = input('Please input public key: ', 's');
if length(Public_Key) == 15
PubK_oldnew = 0;
else
disp('Please input a public key that is 15 in length');
end
end
end

SetLetters = containers.Map('A', 'woseG');


SetLetters('B') = '5Bduf';
SetLetters('C') = 'B3eOL';
SetLetters('D') = 'CqgED';
SetLetters('E') = 'ox9cg';
SetLetters('F') = 'xDzgY';
SetLetters('G') = 'AKG0X';
SetLetters('H') = 'hQtDa';
SetLetters('I') = 'hLprH';
SetLetters('J') = 'L9pcW';
SetLetters('K') = 'adHOk';
SetLetters('L') = 'VQ9zt';
SetLetters('M') = 'aBQTk';
SetLetters('N') = 'CnEdr';
SetLetters('O') = 's9gGU';
SetLetters('P') = 'RcJbg';
SetLetters('Q') = 'OErRp';
SetLetters('R') = 'XpwlA';
SetLetters('S') = 'vCwdT';
SetLetters('T') = '5lLtP';
SetLetters('U') = 'qjahn';
SetLetters('V') = 'lHOrb';
SetLetters('W') = 'z1ZPm';
SetLetters('X') = '7nHdo';
SetLetters('Y') = 'GDZN0';
SetLetters('Z') = 'I9Lr6';
SetLetters('a') = 'pVgYt';
SetLetters('b') = 'tPqWb';
SetLetters('c') = 'UyMaQ';
SetLetters('d') = 'XxuyN';
SetLetters('e') = 'v20fK';
SetLetters('f') = 'Thuzw';
SetLetters('g') = 'DeL1J';
SetLetters('h') = '02l3A';
SetLetters('i') = '1je4t';
SetLetters('j') = '49vot';
SetLetters('k') = 'e21iM';
SetLetters('l') = 'JHMeL';
SetLetters('m') = 'rhHbe';
SetLetters('n') = 'MZjn7';
SetLetters('o') = '62tDj';
SetLetters('p') = 'IBLY7';
SetLetters('q') = 'BVib1';
SetLetters('r') = '0HRhr';
SetLetters('s') = 'DLgWU';
SetLetters('t') = 'uG5ti';
SetLetters('u') = 'DbP4E';
SetLetters('v') = 'UGSc0';
SetLetters('w') = 'Fwn5h';

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
SetLetters('x') = 'lpDAg';
SetLetters('y') = 'YiwDU';
SetLetters('z') = 'De4tx';
SetLetters('1') = 'GnHsI';
SetLetters('2') = 'FO2t9';
SetLetters('3') = 'vMYFW';
SetLetters('4') = 'GSgOw';
SetLetters('5') = 'ralS8';
SetLetters('6') = 'eQLxv';
SetLetters('7') = 'vlTcD';
SetLetters('8') = 'oagsG';
SetLetters('9') = 'PTNMK';
SetLetters('0') = 'Er5Ti';
SetLetters(' ') = 'gVzqS';

%Change password into encrypted code


Increment = 1;
CryptedPassword = SetLetters(private_key(Increment));
while Increment < length(private_key)
Increment = Increment + 1;
CryptedPassword = strcat(CryptedPassword,
(SetLetters(private_key(Increment))));
end

%Setting key
Num=0;
Increment = 1;
while Num>-1
Num=Num+1;
CryptTableSet = strhandle(Num, CryptedPassword(Increment));

SetTable = containers.Map('A', CryptTableSet(1));


SetTable('B') = CryptTableSet(2);
SetTable('C') = CryptTableSet(3);
SetTable('D') = CryptTableSet(4);
SetTable('E') = CryptTableSet(5);
SetTable('F') = CryptTableSet(6);
SetTable('G') = CryptTableSet(7);
SetTable('H') = CryptTableSet(8);
SetTable('I') = CryptTableSet(9);
SetTable('J') = CryptTableSet(10);
SetTable('K') = CryptTableSet(11);
SetTable('L') = CryptTableSet(12);
SetTable('M') = CryptTableSet(13);
SetTable('N') = CryptTableSet(14);
SetTable('O') = CryptTableSet(15);
SetTable('P') = CryptTableSet(16);
SetTable('Q') = CryptTableSet(17);
SetTable('R') = CryptTableSet(18);
SetTable('S') = CryptTableSet(19);
SetTable('T') = CryptTableSet(20);
SetTable('U') = CryptTableSet(21);
SetTable('V') = CryptTableSet(22);
SetTable('W') = CryptTableSet(23);
SetTable('X') = CryptTableSet(24);
SetTable('Y') = CryptTableSet(25);
SetTable('Z') = CryptTableSet(26);
SetTable('a') = CryptTableSet(27);
SetTable('b') = CryptTableSet(28);
SetTable('c') = CryptTableSet(29);
SetTable('d') = CryptTableSet(30);

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
SetTable('e') = CryptTableSet(31);
SetTable('f') = CryptTableSet(32);
SetTable('g') = CryptTableSet(33);
SetTable('h') = CryptTableSet(34);
SetTable('i') = CryptTableSet(35);
SetTable('j') = CryptTableSet(36);
SetTable('k') = CryptTableSet(37);
SetTable('l') = CryptTableSet(38);
SetTable('m') = CryptTableSet(39);
SetTable('n') = CryptTableSet(40);
SetTable('o') = CryptTableSet(41);
SetTable('p') = CryptTableSet(42);
SetTable('q') = CryptTableSet(43);
SetTable('r') = CryptTableSet(44);
SetTable('s') = CryptTableSet(45);
SetTable('t') = CryptTableSet(46);
SetTable('u') = CryptTableSet(47);
SetTable('v') = CryptTableSet(48);
SetTable('w') = CryptTableSet(49);
SetTable('x') = CryptTableSet(50);
SetTable('y') = CryptTableSet(51);
SetTable('z') = CryptTableSet(52);
SetTable('1') = CryptTableSet(53);
SetTable('2') = CryptTableSet(54);
SetTable('3') = CryptTableSet(55);
SetTable('4') = CryptTableSet(56);
SetTable('5') = CryptTableSet(57);
SetTable('6') = CryptTableSet(58);
SetTable('7') = CryptTableSet(59);
SetTable('8') = CryptTableSet(60);
SetTable('9') = CryptTableSet(61);
SetTable('0') = CryptTableSet(62);

CryptedLetter = SetTable(CryptedPassword(length(CryptedPassword))); %Makes


a copy of the letter to be replacing.
CryptedPassword = CryptedPassword(1:end-1); %deletes last letter
FollowingLetters = CryptedPassword(Increment+1:length(CryptedPassword));
%Makes a copy of the ending letters
BeforeLetters = CryptedPassword(1:Increment-1);%Makes a copy of the letters
occuring before the swapped letter
CryptedPassword = strcat(BeforeLetters, CryptedLetter, FollowingLetters);
%Creates new string
Increment = Increment + 1;
try
CryptedPassword(16);
catch
Num=-2;
end

if Increment == 16
Increment = 1;
end
end
%Using the public key to convert the private key into a unique key.

Num=0;
while Num< 15
Num=Num+1;
CryptTableSet = strhandle(Num, Public_Key(Num));
SetTable = containers.Map('A', CryptTableSet(1));
SetTable('B') = CryptTableSet(2);

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
SetTable('C') = CryptTableSet(3);
SetTable('D') = CryptTableSet(4);
SetTable('E') = CryptTableSet(5);
SetTable('F') = CryptTableSet(6);
SetTable('G') = CryptTableSet(7);
SetTable('H') = CryptTableSet(8);
SetTable('I') = CryptTableSet(9);
SetTable('J') = CryptTableSet(10);
SetTable('K') = CryptTableSet(11);
SetTable('L') = CryptTableSet(12);
SetTable('M') = CryptTableSet(13);
SetTable('N') = CryptTableSet(14);
SetTable('O') = CryptTableSet(15);
SetTable('P') = CryptTableSet(16);
SetTable('Q') = CryptTableSet(17);
SetTable('R') = CryptTableSet(18);
SetTable('S') = CryptTableSet(19);
SetTable('T') = CryptTableSet(20);
SetTable('U') = CryptTableSet(21);
SetTable('V') = CryptTableSet(22);
SetTable('W') = CryptTableSet(23);
SetTable('X') = CryptTableSet(24);
SetTable('Y') = CryptTableSet(25);
SetTable('Z') = CryptTableSet(26);
SetTable('a') = CryptTableSet(27);
SetTable('b') = CryptTableSet(28);
SetTable('c') = CryptTableSet(29);
SetTable('d') = CryptTableSet(30);
SetTable('e') = CryptTableSet(31);
SetTable('f') = CryptTableSet(32);
SetTable('g') = CryptTableSet(33);
SetTable('h') = CryptTableSet(34);
SetTable('i') = CryptTableSet(35);
SetTable('j') = CryptTableSet(36);
SetTable('k') = CryptTableSet(37);
SetTable('l') = CryptTableSet(38);
SetTable('m') = CryptTableSet(39);
SetTable('n') = CryptTableSet(40);
SetTable('o') = CryptTableSet(41);
SetTable('p') = CryptTableSet(42);
SetTable('q') = CryptTableSet(43);
SetTable('r') = CryptTableSet(44);
SetTable('s') = CryptTableSet(45);
SetTable('t') = CryptTableSet(46);
SetTable('u') = CryptTableSet(47);
SetTable('v') = CryptTableSet(48);
SetTable('w') = CryptTableSet(49);
SetTable('x') = CryptTableSet(50);
SetTable('y') = CryptTableSet(51);
SetTable('z') = CryptTableSet(52);
SetTable('1') = CryptTableSet(53);
SetTable('2') = CryptTableSet(54);
SetTable('3') = CryptTableSet(55);
SetTable('4') = CryptTableSet(56);
SetTable('5') = CryptTableSet(57);
SetTable('6') = CryptTableSet(58);
SetTable('7') = CryptTableSet(59);
SetTable('8') = CryptTableSet(60);
SetTable('9') = CryptTableSet(61);
SetTable('0') = CryptTableSet(62);

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
CryptedLetter = SetTable(CryptedPassword(Num)); %Makes a copy of the letter
to be replacing.
FollowingLetters = CryptedPassword(Num+1:length(CryptedPassword)); %Makes a
copy of the ending letters
BeforeLetters = CryptedPassword(1:Num-1);%Makes a copy of the letters
occuring before the swapped letter
CryptedPassword = strcat(BeforeLetters, CryptedLetter, FollowingLetters);
%Creates new string
end

%Changing phrase into encrypted or decrypting phrase.


NumTotal = 0;
newphrase = '';
NumPass = 1;
while NumTotal>-1
NumTotal = NumTotal + 1;
IncrementSpacing=0;
while IncrementSpacing<5
IncrementSpacing=IncrementSpacing+1;

CryptTableSet = strhandle(NumTotal, CryptedPassword(NumPass));


SetTable = containers.Map('A', CryptTableSet(1));
SetTable('B') = CryptTableSet(2);
SetTable('C') = CryptTableSet(3);
SetTable('D') = CryptTableSet(4);
SetTable('E') = CryptTableSet(5);
SetTable('F') = CryptTableSet(6);
SetTable('G') = CryptTableSet(7);
SetTable('H') = CryptTableSet(8);
SetTable('I') = CryptTableSet(9);
SetTable('J') = CryptTableSet(10);
SetTable('K') = CryptTableSet(11);
SetTable('L') = CryptTableSet(12);
SetTable('M') = CryptTableSet(13);
SetTable('N') = CryptTableSet(14);
SetTable('O') = CryptTableSet(15);
SetTable('P') = CryptTableSet(16);
SetTable('Q') = CryptTableSet(17);
SetTable('R') = CryptTableSet(18);
SetTable('S') = CryptTableSet(19);
SetTable('T') = CryptTableSet(20);
SetTable('U') = CryptTableSet(21);
SetTable('V') = CryptTableSet(22);
SetTable('W') = CryptTableSet(23);
SetTable('X') = CryptTableSet(24);
SetTable('Y') = CryptTableSet(25);
SetTable('Z') = CryptTableSet(26);
SetTable('a') = CryptTableSet(27);
SetTable('b') = CryptTableSet(28);
SetTable('c') = CryptTableSet(29);
SetTable('d') = CryptTableSet(30);
SetTable('e') = CryptTableSet(31);
SetTable('f') = CryptTableSet(32);
SetTable('g') = CryptTableSet(33);
SetTable('h') = CryptTableSet(34);
SetTable('i') = CryptTableSet(35);
SetTable('j') = CryptTableSet(36);
SetTable('k') = CryptTableSet(37);
SetTable('l') = CryptTableSet(38);
SetTable('m') = CryptTableSet(39);

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
SetTable('n') = CryptTableSet(40);
SetTable('o') = CryptTableSet(41);
SetTable('p') = CryptTableSet(42);
SetTable('q') = CryptTableSet(43);
SetTable('r') = CryptTableSet(44);
SetTable('s') = CryptTableSet(45);
SetTable('t') = CryptTableSet(46);
SetTable('u') = CryptTableSet(47);
SetTable('v') = CryptTableSet(48);
SetTable('w') = CryptTableSet(49);
SetTable('x') = CryptTableSet(50);
SetTable('y') = CryptTableSet(51);
SetTable('z') = CryptTableSet(52);
SetTable('1') = CryptTableSet(53);
SetTable('2') = CryptTableSet(54);
SetTable('3') = CryptTableSet(55);
SetTable('4') = CryptTableSet(56);
SetTable('5') = CryptTableSet(57);
SetTable('6') = CryptTableSet(58);
SetTable('7') = CryptTableSet(59);
SetTable('8') = CryptTableSet(60);
SetTable('9') = CryptTableSet(61);
SetTable('0') = CryptTableSet(62);
NumPass = NumPass +1;
IncrementLetters=1;
while IncrementLetters<64
NewLetter = SetLetters(Sample_withspace(IncrementLetters));
CryptedLetter = SetTable(NewLetter(IncrementSpacing)); %Makes a
copy of the letter to be replacing.
FollowingLetters = NewLetter(IncrementSpacing+1:length(NewLetter));
%Makes a copy of the ending letters
BeforeLetters = NewLetter(1:IncrementSpacing-1);%Makes a copy of
the letters occuring before the swapped letter
NewLetter = strcat(BeforeLetters, CryptedLetter, FollowingLetters);
SetLetters(Sample_withspace(IncrementLetters)) = NewLetter;
IncrementLetters=IncrementLetters+1;
end
end

if EncryptOrDecrypt == 1
Selected = phrase(NumTotal);
elseif EncryptOrDecrypt == 2
Constant= (NumTotal*4)-4;
try
Selected = phrase(NumTotal+Constant:NumTotal+Constant+4);
catch
NumTotal = -1;
disp('New phrase: ');
disp(newphrase);
end
end

if EncryptOrDecrypt == 1
newphrase = strcat(newphrase,SetLetters(Selected));

elseif EncryptOrDecrypt == 2
Increment=1;
while Increment<64
if SetLetters(Sample_withspace(Increment))== Selected
newphrase = strcat(newphrase, {Sample_withspace(Increment)});
end

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
Increment = Increment + 1;
end
end

if NumPass == 16
NumPass=1;
end

if NumTotal == length(phrase)
NumTotal = -1;
disp(['New phrase: ', newphrase]);
end
end
end
end

Strhandle.m

function Result = strhandle(freq, TargetLetter)

% Kyle Pellerin 23/05/19


% This function is designed to handle a string
% and transform it uniquely but also in a reproducable fashion.
% This is so it can be replicated reliably. Variable 'freq' is used
% to determine how many times the function will handle the string.
% Therefore x is used it will produce the same resulting string everytime.

% However through testing, this function does not perfectly produce every
% combination for the string.

%String to be transformed.

if TargetLetter == 'A'
CryptTable = 'Ew8dre6LosiTc19bC5hjHKvMYBpFWqSP07OlAINX2fGJUDngaQzxtuykRmZ34V';
elseif TargetLetter == 'B'
CryptTable = 'IAPtZnfrS7MGJExwasyjD39YzikKQHWu2bCXpVh86cUBglON1TvFoL4qdm5Re0';
elseif TargetLetter == 'C'
CryptTable = '2HFvaWjq6KM1YGtDSZPA5kRidX7hLzmryoClNwsugVn0TEBf3c4p8eJ9xIbOUQ';
elseif TargetLetter == 'D'
CryptTable = '7hbpJFqCu1M83ZK9zSTclevxRO6WgXVEmHijfNDkrLQ2wn5sPdIy40aoGUBYAt';
elseif TargetLetter == 'E'
CryptTable = 'pvOJLP7obVUqn8ziCuBXWTSt0MDya4NZlGsRrKAjHxfdIkY1w92e6m3cEQF5hg';
elseif TargetLetter == 'F'
CryptTable = 'btrofLMXhzU2HNpqewgnJYyIkvjmAiGW1KEu8cx40s9Q6Dd7Pa53lZFOBVCRTS';
elseif TargetLetter == 'G'
CryptTable = 'V5xvtDpr3TfhukN2wq1o8aA4mFLZ7REgWzBQMiYJb6HOyXdj9lS0KCUnGcesPI';
elseif TargetLetter == 'H'
CryptTable = 'QPSnIi7yWNHvhmALRf9KtDeqVl8aYXzCBj3MJpG41rO5u0xZsEUgTkc62odbwF';
elseif TargetLetter == 'I'
CryptTable = '5cTfNXvJqyMYWQxtK1DaSwFegpOB3UEoR76zr9bZHhd4LnC8VIusm0AlGiP2kj';
elseif TargetLetter == 'J'
CryptTable = 'P6WEQrNI2R09BCM5aGXfikF3psgSjqo4bVLemdOYnTl8vHxwzuKZDJhcyUAt71';
elseif TargetLetter == 'K'
CryptTable = 'HbNUiCrO4oE8c1e9WKxZmMugnBVD7qz0Xkty6a2SIhJAQsjvRPFTfdwLY5G3lp';
elseif TargetLetter == 'L'
CryptTable = 'dwOyuXaI5SqlKBR3g8rFnNxtJU1eAsV0jLG9okHhfWEviCTpmbYD476c2QPZMz';
elseif TargetLetter == 'M'
CryptTable = 'C3Qwq5ioXN1BYUEFTekbH4gLf926WltR0a7cOGZnupPdxhzm8MIyVDJsSAjKrv';
elseif TargetLetter == 'N'
CryptTable = 'zfLyEWYi9vxKcwoHS7lV5GJjag6dCpr12ebkQNnZ840sXFIuOqThtBDR3UAPmM';
elseif TargetLetter == 'O'

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
CryptTable = 'WgkmF9b1QKOVNj0ISLnCdf45xM2zTE8iZaR7wh3DqetuyYHPsB6roAGlXUvJpc';
elseif TargetLetter == 'P'
CryptTable = 'dfSvL8OU4FzghyQRHWujK9lqZMkPimnA7YJ1wVBoeXxTC50sp2N3btar6EcGID';
elseif TargetLetter == 'Q'
CryptTable = 'gAuzZHF1oy9UERJYdnla3tjw84BcWqNCSXxKG05rkpVOe7fTviL62MhQPbmDsI';
elseif TargetLetter == 'R'
CryptTable = 'AiMTGP6VIhSUZsOBtWEojLlf4Ja5yR1w2YcN8DndC9bQvHg73u0kKreqpXxmFz';
elseif TargetLetter == 'S'
CryptTable = 'TkR3i2hcQUmyHMjA1wLGbDstFqN9OavWJXpSngIVlEx674uP0oZY5rKBdCzf8e';
elseif TargetLetter == 'T'
CryptTable = 'Cphj2Yu56ImZgeNlSH4POFMkbA3v8fGEXTxcnJKqRUidLr7wVaWsoQB9zy1tD0';
elseif TargetLetter == 'U'
CryptTable = 'tc2WsI4nCX61HEb5dZLqBlAJGONDmFTKzj8p7UeiwuYVyvMgrh3Roa9SPQ0kxf';
elseif TargetLetter == 'V'
CryptTable = 'GVEfp4oYRuKC57NFzni8dO0h3SgyTtrke9LvQMJ6UWbqxHPcZAmlj1IsDXw2Ba';
elseif TargetLetter == 'W'
CryptTable = 'hDczMwoivFuRLN26WUgCtAnIplH0ByadQ4Z8s5q9eOrE1xSfJKj7G3XPYVbTkm';
elseif TargetLetter == 'X'
CryptTable = 'x3QyBl6jz19Rw7I8G0feYZaMEUkNtcs4hCOH2FpmX5bqnAiKJuVvPrDgoWSTdL';
elseif TargetLetter == 'Y'
CryptTable = 'exaL6orhMONImvWK2yVYzQtB0Z3gUp75jnw81kiXDEbufSsqF4GCJA9dTlHPRc';
elseif TargetLetter == 'Z'
CryptTable = 'dQCh2RVYfK9wGHDkpoe4q7WPMTNjFl0XBESJgca53rimOLt8zInAxsv1u6ZbUy';
elseif TargetLetter == 'a'
CryptTable = 'mckXR4GfMsj6IiQYqPD3nCOLw2W7Tad51xV9egZSFAHtlyrzBUpNJuhKvb0E8o';
elseif TargetLetter == 'b'
CryptTable = '3VUR5gAmC1MIsWKPYJ4HkDLnxcyhdev6GraZ9bjFSpTqQE7iz0NwXuol8t2OfB';
elseif TargetLetter == 'c'
CryptTable = 'CUt2SORM87PHJh4Ek31F5wXfasnDo9IWAvKuec0zyQTmbYlrBdi6gxZpqNGVjL';
elseif TargetLetter == 'd'
CryptTable = 'aekOY4AgGXySP95EJ1qFoIsxrMmnLU6bHZWV2pcR7NhitBdufQjDTCl83zKw0v';
elseif TargetLetter == 'e'
CryptTable = 'pgMdYJI4nSl2zfRwVvxoQD5TPEA3bNC19ujhUemWaLqFZstB6X70kiHKO8Gcry';
elseif TargetLetter == 'f'
CryptTable = 'mhs6BT1vWPxCFbDGE3w8HYK5M4JROSL9oVi7zegyulZQpadAnkqNtrjUfX0Ic2';
elseif TargetLetter == 'g'
CryptTable = 'n9oRgmBQLKlYwGX57prDcMTi4VUHWFhvkC1dbjs86Pu2eOEJxqIzNSyfZa3At0';
elseif TargetLetter == 'h'
CryptTable = 'jrETZ1mdUFzHWunPXcgA5KR2sVwICYeQ8xlft3NJL4vy0iSBqbaDM7phk6GO9o';
elseif TargetLetter == 'i'
CryptTable = 'e21Zk0chbFOaAtDpQWzrN5UX84PRCnKigvGY6TwLj9JSImyB3qfoVd7MsEuHlx';
elseif TargetLetter == 'j'
CryptTable = '9sncVjBw8IFOhCEYfRSZA6aDm2uXUrL0N45pliGg37dvK1zWbHxTqoPQeJytkM';
elseif TargetLetter == 'k'
CryptTable = 'ktbKu45WPInchXrN2pQ6JoYdO3zfSLABx1Gj7Ui90CqMZlygeTRvw8aVFHDEsm';
elseif TargetLetter == 'l'
CryptTable = 'Wr2wlRsnmVGJUiT3aEgvNS6uyYtHDhL18ZQ7oCezAjpfIxkB9qKXMP5FO0d4cb';
elseif TargetLetter == 'm'
CryptTable = 'dAeKM0b5cNRLyDZEo2WtQSUg84au6CwJH9Gf3hPXOqFpns1VjvrlTiYBzmxI7k';
elseif TargetLetter == 'n'
CryptTable = 'Qae7Cb2GfB1AEKDuZ3dyXcz4FLqJMgkoOIU5sRwrPxTvi8jhSYVt0p9lNnWm6H';
elseif TargetLetter == 'o'
CryptTable = 'uitIcMemJZAlL4yvfQU0Xz2j3OYFVWwokK58CabsnqhGd19RgxTNPrpHESD76B';
elseif TargetLetter == 'p'
CryptTable = 'PIGbDnsViHm0qC8MFagjYQwhoT7x1rc2RlkvE49OZBS6Jeu5KLUdpXtyNz3fAW';
elseif TargetLetter == 'q'
CryptTable = 'f2I4wCvAdqymp9hrNHxtcKT5Enae6S3VuF8DlRLikGsWYQjUgPJ7ZBbM0zo1XO';
elseif TargetLetter == 'r'
CryptTable = 'PskGQi6I0Zo32XyErdc5DWHvROjB1hnF8mLewpfKqlAuYxgJNTt4CzMbU7SaV9';
elseif TargetLetter == 's'
CryptTable = 'lfaDJH1x2YQVb963jnroet4ZhRBTGmI5EuCL0wOsFNcMkWzqU87AySKdgiXpPv';

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
elseif TargetLetter == 't'
CryptTable = 'uza6m8XAplrNPI1dc4E9yCieUbHGQYSxjgM2W3Ot0q5DBFsVnJvhKRfZTLo7kw';
elseif TargetLetter == 'u'
CryptTable = 'QexKRmL5nX9gqwr8EoHhC3kMzpfAlY7aByic4tbvFOPN1djU2SDJZITsWGu6V0';
elseif TargetLetter == 'v'
CryptTable = 'gPi0qwtark8bIjJpXofWUz4NH576vZlR9FShxE3VnOYCeAdLB2sTmD1yMGKuQc';
elseif TargetLetter == 'w'
CryptTable = 'JT4Bx0cUiIXhOpMyKQurERLaVPm1gAe8of9jlq6wsNd53kWD7C2SvzYnGZFbHt';
elseif TargetLetter == 'x'
CryptTable = 'KgB2Nz3pXVGhfAnoEs8P6Dk5uCYRa0TFqZvUiSWJ9j4lMxet7Qrbm1LHIydwcO';
elseif TargetLetter == 'y'
CryptTable = 'T7fjwcb4dDeM6kVFXruHlE8qAWRp3a2vUIGCYPxZ0tJhsiLy15BzmSN9KQngOo';
elseif TargetLetter == 'z'
CryptTable = 'qHSmUcOI10YezhignvLauVQkA4NTxMEprJyZKDlC9fdGs5wR8XBto7b2WP6Fj3';
elseif TargetLetter == '1'
CryptTable = 'CcM7Z9wxmlXLAjnDuP2FRdz4TJiBt8kgaQGs1YpHNVOKUe350yvorSbfIWqEh6';
elseif TargetLetter == '2'
CryptTable = 'hqWwl7BpQvZmLr6H8obRF1O2fiXM4eKyjzsCD9NGkanTI0xEJY5UuVPdct3ASg';
elseif TargetLetter == '3'
CryptTable = 'K9SBZ1F8dx34CyjgceNoUwtvME70YHpDukOshzRJmXlPLIbn6W5TqQGVfi2rAa';
elseif TargetLetter == '4'
CryptTable = 'Qs0CykhfKMOrPc6dW7V9oNpBFTzYxSUHGn5IJEa2qej1Z4vAbLDg8l3RmtiXwu';
elseif TargetLetter == '5'
CryptTable = 'DLuYd3mTwMCZfcoil1JNrvpa9FG0t5BHyKIj7znPXhbEUQWkOVR4SA826sqegx';
elseif TargetLetter == '6'
CryptTable = 'fNDcLwPCg6QmpZxkHedKbrTXvEoMs7RI1YF3A0US8iOWat5JyquVjh9lBGz2n4';
elseif TargetLetter == '7'
CryptTable = 'zkNxhnBEitVGawFL4cTXrCIpQDofKyRO58HM3lqdJ9Zems1U0YjuW72gvS6bPA';
elseif TargetLetter == '8'
CryptTable = 'BsfvG5Nwg2IeOMJ4CuzLbahYHWQmTEDqxod0AUXRk7nK3j1Ppl6rFZycS8iV9t';
elseif TargetLetter == '9'
CryptTable = '24DJoLOT0EzlwsSZ5aY89kKGHPmQ3gvUBrNnhIWRfM7uc6etVFxbpdyCqXA1ji';
elseif TargetLetter == '0'
CryptTable = 'udA6Qwc2hJgP8aqWCyj0zXMeVGLnkDUOftTRm35HsIFSip9l7NBYob1Krvx4EZ';
end

%All variables used are set to zero before loop. This is so function works
%the first time as well as the later instances.
RotationCount = 0;
Increment = 0;
CryptTableCopy = CryptTable;
TransferCount = 0;
TransferCountTotal = 0;
ExceptionRule=0;
TransferCount2 = 0;
ResultCount = 0;

StartProgram=1;
while StartProgram==1

%Rotating end data


Increment = Increment +1; %Increment now equals 1 but will also work for later
generations
FirstLetter = CryptTable(1:1); %Makes a copy of the first letter
CryptTable = erase(CryptTable, CryptTable(1:1)); %Erased first letter of
CryptTable
CryptTable = strcat(CryptTable, FirstLetter); %Joins the ex first letter to the
back of the new string.
%Effectively moving the
%entire string to the
%left.

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics

ResultCount = ResultCount+1; %Since new string has formed. Counts by 1


generation
if ResultCount == freq %If RotationCount equals freq, result can be produced
Result = CryptTable;
StartProgram = 0; %Breaks loop
end

%Counts by 1
RotationCount = RotationCount+1;

% If the ResultCount equals the length, all possible combinations for moving
one letter
%left has been achieved. Therefore we now must move a letter by two
%steps or more. Once we transform it by two or more steps. we then can
%transform that by length(str) amount again resulting in new combos.
if RotationCount == length(CryptTable)

%Incremental counters.
TransferCount = TransferCount +1;
TransferCountTotal = TransferCountTotal + 1;

%On first occurence only. CryptTableCopy is used to 'save' the


%previous string.
if TransferCount == 1
CryptTableCopy = CryptTable;
end

%Loads previous state.


CryptTable=CryptTableCopy;

FirstLetter = CryptTable(1:1); %Makes a copy of the first letter


FollowingLetters = CryptTable(TransferCount+2:length(CryptTable)); %Makes a
copy of the ending letters
CryptTable=erase(CryptTable, CryptTable(1:1)); %Erases first letter
BeforeLetters = CryptTable(1:TransferCount);%Makes a copy of the letters
occuring before the swapped letter
CryptTable = strcat(BeforeLetters, FirstLetter, FollowingLetters); %Creates
new string

ResultCount = ResultCount+1; %Since new string has formed. Counts by 1


generation
if ResultCount == freq %If RotationCount equals freq, result can be
produced
Result = CryptTable;
StartProgram = 0; %Breaks loop
end

RotationCount=0; %Resets the rotation count so all possible occurences can


occur.

if TransferCountTotal==1 %First time creates containers map, all others add


to set.
SetOrgs = containers.Map(TransferCountTotal, CryptTable);
else
SetOrgs(TransferCountTotal)= CryptTable;
end

if TransferCount == length(CryptTable)-2 %This is the amount of occurences


a letter can move between letters besides the first and last
TransferCount = 0; %Resets Variable

Scientific Computing 101. Final A. Duncan, 31/05/2019


Curtin University of Technology,
Departments of Computer Science, and Imaging and Applied Physics
TransferCount2 = 1; %Sets variable
end

if TransferCount2 == 1

%Once exception rule does all formations for the string. It


%will reset TransferCount2
ExceptionRule = ExceptionRule + 1;
if rem(ExceptionRule,(length(CryptTable)-2)) == 0
TransferCount2 = 0;
end

%Adds further transformations into set


CryptTable=SetOrgs(ExceptionRule);
CryptTableCopy= CryptTable;

FirstLetter = CryptTable(1:1); %Makes a copy of the first letter


FollowingLetters = CryptTable(TransferCount2+2:length(CryptTable));
%Makes a copy of the ending letters
CryptTable=erase(CryptTable, CryptTable(1:1)); %Erases first letter
BeforeLetters = CryptTable(1:TransferCount2);%Makes a copy of the
letters occuring before the swapped letter
CryptTable = strcat(BeforeLetters, FirstLetter, FollowingLetters);
%Creates new string

ResultCount = ResultCount+1; %Since new string has formed. Counts by 1


generation
if ResultCount == freq %If RotationCount equals freq, result can be
produced
Result = CryptTable;
StartProgram = 0; %Breaks loop
end
end
end
end
end

Scientific Computing 101. Final A. Duncan, 31/05/2019

You might also like