Posts

Vigenère cipher encryption with C++

Image
Vigenère cipher is a substitution cipher that uses a 26 x 26 alphabetic table to either encrypt or decrypt. For example, say we wanted to encrypt the plaintext: "DAY" Then we would first pick an arbitrary keyword for the letter, let's go with: "SEE" From there on out, we would use the plaintext on the columns and keyword on the rows on the 26 x 26 table and then substitute. Ultimately, we would see that the plaintext combined with the keyword turns into: "VEC" Which will be our final encrypted text. An illustration of this can be seen visually as: Now, let's move over to the C++ program and start with main.cpp. main.cpp #include "Vigenere.h" Vigenere * vigenere = nullptr; int main () { vigenere = new Vigenere(); while (vigenere -> isRunning()) { vigenere -> showMenu(); vigenere -> handleEvents(); } return 0 ; } In this case, we're simply creating a new instance of a Vigenere object that we're g

Using CSS and SVG's to animate for web

Image
In order to do animations we will need something to animate. So let's move into Adobe Illustrator where we can create a basic flat design SVG for which we can use for our animation. In this case, I am going for a simple coffee cup. From there on we will need another SVG image that will get an animated effect. Let's settle with a steam effect for the coffee cup. The image above will be our steam effect (look past the blue background). So now that we have two different pictures, we can start with the animation. But first, we will have to export these two images as .png images, and that without any backgrounds (the blue background). From there on out, let's create a HTML page, a CSS document and import a CSS animation library. Let's call the HTML page index.html and the CSS document for main.css. For our imported CSS animation library, we will use a library called Animate.css (version 3.7.2), which is great for quick animations. Though, I will override some

Minimum Spanning Trees (MST)

Image
Let's imagine an undirected graph with weighted edges. From this graph, the spanning tree wil be a tree that maps all the vertices. In other words, the tree seen above will be G = (V, E) = (4, 5) and the spanning tree must be at least S = (4, 3). Let us visualize us this down below. Here we will have S = (4, 3) marked with green, which will be our spanning tree. As we can see, it covers all the vertices in the tree. However, it doesn't cover all the vertices in regards to the weighted edges. This S tree will have the sum of 4 + 5 + 2 = 11. Now when it comes to minimal spanning trees, we have to care about the weighted edges in the graph. Let's find the minimal spanning tree of the G graph above. Let's call this subgraph for S2 = (4, 3). In this subgraph we will see that the sum will be equal to 4 + 1 +2 = 7 and that it covers all the vertices. Since it has the smallest sum out of all the spanning trees you can make over graph G, it will be the minimal sp

Walkthrough of red-black trees with example

Image
First of all, red-black trees are only a representation of 2-4 trees. The reason for this is because the red-black trees are easier to implement into code. We're not going to look at implementing red-black trees into code in this post, but rather some of the theory behind red-black trees. For red-black trees there's some rules. A node is either red or black A new node is always red Root node or leaves are always black A red node can not have a red parent or a red child Every path from the root to a nullptr node will have the same number of black nodes If the aunt is red, the father is red, and the daughter is red. Then what we must do is a color change. Where the aunt and father shall be black and the grandparent shall be red As an example, we can look at how we will build a red-black tree for the list 1, 2, 3, 4, 5, 6.

Double linked list with C++

Image
The structure of a node in a double linked list is almost identical to that of a single linked list . The only difference is that the node in a double linked list will have an extra pointer. This can visually be seen a:

A simple Android app - "How fast can you click" game

Image
Looking for some fun I created a very basic Android app that checks how fast you can click. The concept is simple, you have 30 seconds to click as fast as possible. The clicks will register and eventually tell you the overall clicks after the 30 seconds have run out. Once it's done you'll also have an option to refresh the game; giving a possibility to try to do better next time. Here's a picture from the Android Studio Phone Emulator.

Single linked list with C++

Image
A linked list can be imagined with a sequence of something. In our case, let's think of it as integers. So, if I for example have a list of 6 integers being 12, 8, 3, 2, 6 and 38 we could represent the linked list as. Where the blue boxes are nodes. These nodes can be represented individually as.

Insertion Sort algorithm in depth with C++

Image
We can visualize an example of the Insertion Sort algorithm with an array of integers that needs to be sorted. In this case we will set the start position as the blue arrow that is located at index 1. Where we will compare 3 < 7 . If this is true, then we will have to swap these with eachother. Now, this is true for 3 < 7 so we will swap

Queue data structure with C++

Image
Contrary to a Stack , the queue data structure uses FIFO (First In, First Out). In order to explain this concept, we can imagine some people standing in a line. Where person A (Blue) is the first one to enter the line. A will then be the last to go out from the line. Person F (Grey) is the last to enter, so the person will therefor be the last to get out from the line. With other words, with FIFO the first element in a sequence will also be the first to go out of the sequence. Creating a queue class with C++ we will need some functions, such as enqueue(), dequeue(), queue_size(), is_empty() and display(). So let's make a class with those.

Simple Arduino PIN lock with LCD Display

Image
I thought it would be fun to build something that looked like a smart lock for a door. With an Arduino Uno, three buttons being 1, 2 and 3 along with a buzzer, some LED diodes and a microservo I was able to make a simple mechanism that can both grant- and deny access. The servo will rotate on a valid PIN and keep an angle for X seconds (See gif underneath). Furthermore, if the PIN code is incorrect the servo won't rotate. Here's a gif of the system in action. Starting out with recreating the project I will be using TinkerCad to illustrate some of the parts. We can start out with the attachment of the three buttons to a breadboard, along with some LED diodes to indicate a button being pressed. From there we can add the buzzer (Piezo speaker in this image) and one more LED diode which will both activate when the PIN code is correct. This is when the system should grant access and the servo rotate. Now we can connect the servo to the breadboard.

Selection Sort algorithm in depth with C++

Image
To represent this sorting algorithm we can visualize an array of unsorted integers. From there we start by marking the first integer and calling it Small . All the other numbers in the array will then be to the right of Small . We will then compare Small with all the other integers to the right. Checking if they are less than Small , and if so, we will be replacing the variable Small with the lowest value found. Let's imagine we have a array of integers 7, 8, 5, 4, 9, 2. In that case Small will be equal to 7 (Being the blue arrow). Now let's compare Small with the numbers to the right (The yellow arrow). Checking if they are in fact less than Small . So with the example above, we will first be checking if 8 < 7 . If that's true, then we will have to switch Small = 7 with Small = 8 . In this case, that simply isn't true. So we will have to move on with comparing Small = 7 with the other integers in the list. For the next step we can see that 5 wil