Home > Sample essays > Secure Data with C++ Morse Coding: An Encoding and Decoding Project

Essay: Secure Data with C++ Morse Coding: An Encoding and Decoding Project

Essay details and download:

  • Subject area(s): Sample essays
  • Reading time: 12 minutes
  • Price: Free download
  • Published: 1 June 2019*
  • Last Modified: 23 July 2024
  • File format: Text
  • Words: 3,443 (approx)
  • Number of pages: 14 (approx)

Text preview of this essay:

This page of the essay has 3,443 words.



Abstract

Encoding and decoding data is one of the ways of ensuring data is secure from unauthorized persons. It ensures that any given message is safeguarded from unauthorized persons. This protects the owner, whether an organization or an individual from sabotage arising from data leaks.

This project is an implementation of an encoding and decoding system using a code invented by F. S Morse called Morse Code. It works by encoding data into dots and dashes. The project is inspired by a binary tree data structure where data is stored in interconnected nodes and accessed recursively.

The morse code takes a string of characters and transforms it to a code of dots and dashes using a predefined mapping scheme. The values of each alphabetical character are store in a binary tree at a position equivalent to the codes path. The paths of a binary tree are in the form of right- left or left right where right and left are nodes with each having possible subsequent nodes interconnected to form a tree.

A dash represents a left and dot represents a right thus making it a path representation mechanism.

The morse code is a great way of encoding data as long as no one knows which character is stored in which node. It can be safe as long as data is presented to people who have no idea about dashes and dots.

Project.

A C++ Morse Coding Project.

Introduction

Data transmission is a broad field in networking which has many areas of study. One of those areas is the study of data transmission risks and threats. Under this topic, learners get to understand the risk involving transmission of data as well as the threats a signal faces when being transmitted from one point to another.

In the study, it is discovered that many messages which travel through networks systems are at the risk of being manipulated or accessed by unauthorized people. This can be done through signal hacking or eaves dropping. With any data in the hands of unauthorized persons an organization is always faced with the risk of sabotage from the same people.  

The threats and risks therefore create a need for the transmitters to find ways of ensuring that data transmission is free from external interference. This has resulted to different solutions whereby both the transmitters and the receivers play a role in ensuring the authenticity of the received or transmitted message. This can be done by either having a calculation method to validate the received data on by simply scribbling the data in a manner only the receiver can understand.

The Problem Statement.

When sending data from a given point to another, a person is always faced with the risk of having the data land in to the hands of unauthorized persons and probably using the information to carry out unexpected and unwanted activities, some which may amount to sabotage. For example, a message containing sensitive data like passwords and user names or personal information like phone numbers, addresses and financial records, landing in to the hands or rogue people can be sold to malicious people and used to sabotage the owner. This major risk therefore possess a challenge to transmitters to come up with mechanisms to ensure that, at a bare minimum, no one can understand the data, even when a third party entrusted with transmission decides to use it against their client.

The Project.

One of the solutions to the above problem is data encryption through encoding. The morse code is one of the best algorithms developed to generate codes from a given message. The morse project is developed as a solution to provide a mechanism to hinder people coming across the data either by mistake or knowingly, from understanding the contents of the messages.

The Morse code project is a program which takes a message and transforms it to a code in the form of dots and dashes. This makes it a little hard for anyone to understand what is being transmitted. Although it’s a great way of salvaging data from unwanted access, it’s basically a program to encode data to a string of dots and dashes. There are still various loop holes which malicious people can use to tamper with the data. It is however a milestone in data security and integrity especially for low risk systems.

Project Structure.

The project is designed using the object oriented programming approach on the c++ programming language. It has three classes and several functions which facilitate the encoding and decoding processes. It also includes some header files which contain declarations and function definitions. The main file which acts as a driver program contains code to test and put to use the three Classes.

Project Idea.

The idea of a project is derived from a programming data structure called a Binary tree.  A binary tree is a data structure where data is stored in the form of a tree, with branches and leaves. It is a data structure whereby all the data items in the form of nodes point to a node on the right or left. It is known to be an effective way of data storage and retrieval.

Binary Trees.

A binary search tree is a data structure in computer science which store items in an ordered way in a manner that the data can easily be retrieved.  The structure representation takes the shape of a tree where data is stored either to the right or to the left of the tree depending on the value given. This makes them a better and efficient data structure suitable for data retrieval. They work on the basis of binary search which is a fast search implementation method where by the sorted data set containing a value in question is recursively divided by two and a determination is made on whether the value being sought is in either side. This reduces the number of comparisons involved in searching thus making it a more effective method for searching values in large sets of data.

Binary Tree Structure.

The Binary search tree takes a structure of interconnected tree. The first node also called the root node points to subsequent nodes, one on the right and one on the left. Now each node also points to at most two other nodes. This makes the data structure to resemble an interconnection of nodes often referred to as “tree of trees”

Relevance to the Project.

The objective of the project is to generate a code representing a string of characters which can be securely transmitted through insecure environments without being decoded by unauthorized persons. The node structure with a depth of say 4 nodes can accurately represent the 26 alphabetical character. In this case therefore, the node location or path in relation to the binary tree can be used to represent characters. With a simple dot(.) and dash (-) notation, a string of characters delimited using a special character like a comma or even space can be represented as a path in the form “.__.. .__.” Which makes it hard for anyone to crack.

In this project, the path plays a key role in the coding and decoding, for characters in the alphabet are stored as nodes!

For anyone, who has no idea about the representation, the message will look like a line of dots and dashes, but would prove hard to crack since characters may not be stored in any predefined order.

The Code.

The solution includes five program files and an input definition file containing a predetermined code mappings of the characters and desired paths. The five files include morse.cpp, morse.h, main.cpp, binaryTree.h, binaryTree.h. Each file contains special methods as highlighted below.

Main.cpp

This is the main program file which acts as entry point to the program. It contains only one method named main, which has just a few lines of code to put to test the two other classes. The code lines includes the compiler directives which add system predefined and other classes during runtime and some output statements. It has lines to facilitate initialization of the other classes and implementations of the program, as well as output statements showing operations being carried out.

BinaryTree.h

To ensure program uniformity and minimization of errors in a c++ programming project a generally accepted coding style is adopted. This is the use of header files and implementation files. This style allows a programmer to organize their code in a professional manner.

In this project, the same approach has been applied and so the two class files have a header file each. The BinaryTree.h file is the header file for the binaryTree class. It contains definitions of functions and variables used within the Binary tree class. Since the project is not made to be complex, it only contains two methods with each having two implementations through overloading.

BinaryTree.cpp

This file contains implementations of the binary tree Logic. The code for each method defined in the header file is written in this class. It also houses a struct data type called Node which is used as a variable to hold the values of the key and location within the binary tree. The header file is also imported to the class file using the “include’ compiler directive statements.

Morse.h

Just like with the BinaryTree class, the morse class has an header file too which holds definitions of methods and variable. The se style of header class implementation reduces errors within code and helps in reuse of code, by just importing the header file. The header of the morse class contains definitions of methods to encode and decode data as well as variables used during encoding and decoding. It also contains methods to build the binary tree and a map of characters to help in decoding messages.

Morse.cpp

This is the major file where most of the Logic is carried out. Although some methods are encapsulated in the binary Tree class, they are accessed from this class. A binary tree is build using the binary Tree class and populated with data from a text file. The data from the text file contains a character and its equivalent representation on the binary tree.

Project Implementation.

This section explains the logic behind each part of the solution. It contains a step by step explanation of each piece of code within the system and how it interacts with the other functions to build the solution.

Entry Point

The program’s entry point is the main method in the main.cpp file. The method consists of initialization statements and execution lines.

Initialization.

To start up the system the following line is executed to initialize the binary tree Class in the Binary Tree File. An empty binary tree is created during initialization. This data object will hold data for the morse codes.

morseCodeTree tree;

To build a key / value pair of items to hold each value and key for decoding, a map data type is initialized using this line.

map <char, string> morseMap = populateMap();

PopulateMap() Method is called at this point to initialize the  hardcoded values of code for each character to the map for easy look up.

This method, from the morse class, then populates the created binary tree with data from a text file in system.

buildTree(tree);

After successful creation and update of a binary tree as well as a character map containing the key values which are the alphabetical characters and the code equivalents, the methods to encode and decode several strings of texts and code are called. This is the last part of the program meant to test the accuracy of the functionalities.

The Morse logic is a coding scheme used in telecommunication where by characters are encoded to a certain standard code which can be regenerated. It was invented by F.B Morse the man who invented telegraph. The logic represents text in form of dots and dashes making an encoded message hard to understand.

To implement the Logic, the program first builds a binary tree by reading it from a text file with predefined values for each character. The reason why each character is predefined is to ensure that the receiver of the message knows what each code represents, otherwise, they would never be able to decode it.

The class with the morse code contains several methods which perform various functionalities.

The first method is a void buildTree method which takes an empty build tree as a parameter.  void buildTree( morseCodeTree& tree)

In this method, a file stream object is created from the file containing the codes in the file system and all codes are determined by splitting each line of the ifstream object. In the file, every line contains a character and its morse code equivalent spearated by a space.

Every key and code is saved in a variable of data type node which is inserted to the binary tree using the tree object created and it’s insert method tree.insert(key_code, code_hold);

When a value is inserted the node is cleared and a new value is loaded. This loop is executed until all Characters are added to the Binary Tree.

The File also contains a method called populateMap() which creates a key value map of each character and it’s code value. This is used to hold values so as to make it possible to decode messages. The binary tree is an encoding technique but the map contains values to be used for decoding.

It works using a c++ data structure called a map which holds data in form of key / value pairs.

In this value all alphabetical characters and the equivalent values are added and saved.

To encode messages a method called encodeMessage() which takes two parameters is used. This method takes a character map as a parameter and the message and returns its morse code.

Here is a snippet of the encode method:

string encodeMessage(map <char, string> map, string message){

string tempString; //Holds return string with morse code

char tempChar; //Holds char to be encoded

for (unsigned i = 0; i<message.length(); ++i)

{

tempChar = message.at(i);

tempString += map.find(tempChar)->second + " ";

}

return tempString;

}

The logic implemented here involves splitting the message to an array of characters and looking up for the value of each in the map while building a new array of character codes which are later concatenated to form a final string, the coded message.

To decode messages, the code is passed to a method called decodeMessage() which takes a binary tree with the codes and the encoded message. The encoded message is then split in to an array of strings which are morse codes. The value of each morse code is then determined by moving through the binary tree recursively comparing the keys and values. When a value is found, then the key is appended to a temporary message variable used to hold output before display!

A snippet of the decode method:

string decodeMessage(morseCodeTree tree, string encoded) {

vector <char> lettersToDecode;

string message;

char decoded;

for (unsigned i = 0; i < encoded.size() + 1; i++) {

if ((encoded[i] == ' ') || (i == encoded.size())) {

decoded = tree.search(lettersToDecode)->key;

lettersToDecode.clear();

message += decoded;

if (encoded[i] == ' ') i++;

}

lettersToDecode.push_back(encoded[i]);

}

return message;

}

The morse idea is represented in just two characters a dot and a dash because they only represent a direction.

The dot may be used to mean a move to the right while a dash means a move to the left. During the tree traversal, a person will check the code and move according to the character codes. If say a code is .__. Then at the root node, one will move to the left node then move to a right node and again to its right node, stopping at the left node. This makes it easy to follow and find the key value of the node stored at the new location. This action is not carried out in the method, but only called as it is a member method of the tree object.

The morse class is however not independent as it depends directly on the binary Tree class.

Binary Tree Class.

The need to come up with a unique code of characters led to the invention of morse code using a binary tree. The binary tree as a data structure holds data in form of nodes ad leaves. A node can point to more nodes but with a maximum of only two, one to its right and another to the left. The child nodes can also pint to more nodes thus forming a structure like a tree.

The Node data structure.

The node data structure holds several values which include, the key which is the alphabetical character, a representation of the character in the morse code and a pointer to the left and to the right. Here is the struct code:

struct node

{

public:

char key; //Hold a Character

vector<char> code; //Holds the code Equivalent

struct node *left;

struct node *right;

std:: string toString(){

}

};

The methods.

To implement the binary tree there are a number of methods required. These methods include, insert(), search(), delete(), inorder(), preorder among others. For the sake of this project, only two methods are implemented.

First a Node data structure is created which acts as a container holding data members for every code. Its class skeleton has the variables:

These are:

1. Insert.

The insert method is used to insert a node in to the tree. It has two variations whereby one takes two variables while the other takes one.

This is made possible by the programming feature called method overloading!

The method with one parameter value is used for accessing the overloaded method. This is because a variable for the node cannot be accessed outside the Binary tree class. Inserting a value in to the tree involves traversing through the available nodes to find an empty one. When an empty slot is found, a new node is added to the tree.

The overloaded method takes two parameters, whereby one is the root node which can only be declared within the Binary tree class and a node value holding the data to be inserted. The root node issued as a starting point also known as an entry point for the Node. The Morse code which is the value in the Node is stored on a slot which is equivalent to the path of the node on the Binary Tree.

Although the two methods do similar work, one is accessed from the other because to facilitate easy traversal when the node is set to root.

2. Search

The search method is the most important method in the code for a binary tree in relation to the morse code. It is where the mapping of a code for any given key is carried out. When a Character is supplied, the whole tree is traversed recursively trying to establish the value of the supplied key in the morse code. Searching in Binary trees is done by recursively comparing the values of a given node to determine if its key is the value in question. When the key is found, then the value within the node is returned.

As the insert method is overloaded, the search method is also overloaded to facilitate searching from a certain entry point. Sometimes a user may know the range of some given data and may want to search for a value at a given area. This is made possible by the overloaded version of search which takes an entry point as a parameter of type node and a parameter with the search term.

Conclusion

Day by day hackers and malicious intentioned people are working to find loopholes in every piece of software. The morse code is a good implementation of code to code messages while transmitting them through a network. With more people examining the implementation of the code, reverse mechanisms can be designed to try and mimic the operations of the system thus making it a vulnerable to security breaches.

The main advantage of the morse code system is that it is easy to implement and use. Accessing items in a Binary Tree takes really short time and is easy to implement. As much as programmers can still find a way access the coded message, morse code proofs to be too hard to crack.

Because each character is stored independent form each other, it is hard to search and find the morse equivalent.

The program is limited in that if anyone knows the values of keys, it is easy to decode the messages being transmitted even without an electronic device. On a different note however, may not have a code for the dots and dashes.

About this essay:

If you use part of this page in your own work, you need to provide a citation, as follows:

Essay Sauce, Secure Data with C++ Morse Coding: An Encoding and Decoding Project. Available from:<https://www.essaysauce.com/sample-essays/2018-12-20-1545340868-2/> [Accessed 16-04-26].

These Sample essays have been submitted to us by students in order to help you with your studies.

* This essay may have been previously published on EssaySauce.com and/or Essay.uk.com at an earlier date than indicated.