Merge pull request #248 from the-programmers-hangout/content-clean-up-markdown

content(resources): clean up markdown files, headings & codeblocks
This commit is contained in:
Jean-Philippe Sirois
2020-05-13 07:52:41 -04:00
committed by GitHub
10 changed files with 110 additions and 117 deletions
@@ -11,50 +11,50 @@ external_resources:
---
Over my time in TPH, I have noticed that a common woe aspiring bot developers have is that they are unable to host
their Discord bot online as they may not have access to a credit card.
their Discord bot online as they may not have access to a credit card.
## Introducing Heroku!
While the official Discord bots used in TPH - like HotBot - is hosted via paid platforms, there are free alternatives
to deploying your bot online. This is where Heroku comes into the picture!
to deploying your bot online. This is where Heroku comes into the picture!
> Heroku is a cloud platform that lets companies build, deliver, monitor and scale apps — we're the fastest way to
> go from idea to URL, bypassing all those infrastructure headaches.
Heroku's free tier does not require any credit card information and has sufficient uptime for your basic bot
development needs and it is a great starting place to understand hosting.
development needs and it is a great starting place to understand hosting.
## How does Heroku work?
Before diving into setting up a Discord bot on Heroku, it is best to explain how Heroku is used. Heroku relies on the
Git version control system (VCS) to manage an application. This means that it integrates well with any existing projects
that already use Git. Do not fret, even if your application does not use Git, the configuration and setup for Heroku is
still simple.
Git version control system (VCS) to manage an application. This means that it integrates well with any existing projects
that already use Git. Do not fret, even if your application does not use Git, the configuration and setup for Heroku is
still simple.
By using Git, Heroku receives the project files directly and it is responsible for building the project. This is unlike
other hosting platforms where you would often only supply the final executable - a `.jar` file in our case - to the
hosting platform to run.
other hosting platforms where you would often only supply the final executable - a `.jar` file in our case - to the
hosting platform to run.
In order for Heroku to understand how it will build and deploy your application, you must provide a `Procfile`.
In order for Heroku to understand how it will build and deploy your application, you must provide a `Procfile`.
The `Procfile` is comprised of two key components - the dyno to run the application on and the commands to run your
application.
The `Procfile` is comprised of two key components - the dyno to run the application on and the commands to run your
application.
According to the [Heroku documentation on dynos](https://www.heroku.com/dynos), dynos are containers that are used to
run and scale all Heroku applications. Rather than worrying about configuring your build environment or OS, you can
focus on building your applications and allowing Heroku to take over the build and deployment process. For all
Discord bots, we will use a **worker** dyno.
According to the [Heroku documentation on dynos](https://www.heroku.com/dynos), dynos are containers that are used to
run and scale all Heroku applications. Rather than worrying about configuring your build environment or OS, you can
focus on building your applications and allowing Heroku to take over the build and deployment process. For all
Discord bots, we will use a **worker** dyno.
The build commands we supply correspond to the build commands we use to run our bots locally.
As Heroku uses the project files to determine the type of tools we are using, we do not need to specify the
instructions to create the executable. In our case, since we are using Maven, it can intelligently detect the
`pom.xml` file and create the `.jar` accordingly. This leaves us with only the run commands to include in our `Procfile`.
As Heroku uses the project files to determine the type of tools we are using, we do not need to specify the
instructions to create the executable. In our case, since we are using Maven, it can intelligently detect the
`pom.xml` file and create the `.jar` accordingly. This leaves us with only the run commands to include in our `Procfile`.
Finally, to tighten security, we will store all bot tokens in Heroku's
[config vars.](https://devcenter.heroku.com/articles/config-vars) From a code perspective, these config vars are simply
environment variables available to our applications. This allows us to load our bot token during runtime and prevent
the bot token from being leaked.
Finally, to tighten security, we will store all bot tokens in Heroku's
[config vars.](https://devcenter.heroku.com/articles/config-vars) From a code perspective, these config vars are simply
environment variables available to our applications. This allows us to load our bot token during runtime and prevent
the bot token from being leaked.
Thus, we can define our deployment plan as such:
@@ -64,13 +64,13 @@ Thus, we can define our deployment plan as such:
4. Store the bot token as a config var to be used by your bot
What I have just presented is a general overview of Heroku as a hosting platform. I will be diving into the implementation
in the following sections.
in the following sections.
## Getting started
For this article, I will be using a very simple Discord bot written in Kotlin. I have chosen to use JDA as the focus of
this guide is to understand Heroku. The code repository can be found
[here.](https://github.com/woojiahao/discord-heroku-deployment-demo)
For this article, I will be using a very simple Discord bot written in Kotlin. I have chosen to use JDA as the focus of
this guide is to understand Heroku. The code repository can be found
[here.](https://github.com/woojiahao/discord-heroku-deployment-demo)
If you wish to follow along, you can get the repository via
@@ -78,40 +78,40 @@ If you wish to follow along, you can get the repository via
$ git clone https://github.com/woojiahao/discord-heroku-deployment-demo ping-bot
$ cd ping-bot/
```
Aside from that, basic understanding of the following is good to have to understand the technical details of this guide.
Aside from that, basic understanding of the following is good to have to understand the technical details of this guide.
1. [Git](https://git-scm.com/book/en/v2) - version control system that integrates with Heroku to enable easy deployments
2. [Maven](http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html) - build tool for Kotlin to
manage application dependencies
manage application dependencies
In Kotlin/Java, we are looking to create a `.jar` file. This `.jar` file can be thought of like a `.exe` file.
Essentially, it bundles the application and allows us to run our bot without having to fire up an IDE.
To create this `.jar` file, we will use Maven. For more information about using Maven to create `.jar` files, refer to
[this](http://tutorials.jenkov.com/maven/maven-build-fat-jar.html) guide.
In Kotlin/Java, we are looking to create a `.jar` file. This `.jar` file can be thought of like a `.exe` file.
Essentially, it bundles the application and allows us to run our bot without having to fire up an IDE.
To create this `.jar` file, we will use Maven. For more information about using Maven to create `.jar` files, refer to
[this](http://tutorials.jenkov.com/maven/maven-build-fat-jar.html) guide.
With the formalities out of the way, let's get down to deploying our bot.
## Installing Heroku
You will have to install Heroku onto your machine to execute the following commands in the command line. You can find
the installation instructions for Heroku [here](https://devcenter.heroku.com/articles/heroku-cli).
the installation instructions for Heroku [here](https://devcenter.heroku.com/articles/heroku-cli).
To ensure that you have installed Heroku successfully, run `heroku --version`. My version of Heroku is
`heroku/7.39.2 linux-x64 node-v13.12.0`
To ensure that you have installed Heroku successfully, run `heroku --version`. My version of Heroku is
`heroku/7.39.2 linux-x64 node-v13.12.0`
## Setup a Git repository
As mentioned earlier, we need to ensure that our application is a Git repository for Heroku to work.
While it is recommended to [publish your repository to GitHub](https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line) (or any other version control website), it is not necessary
While it is recommended to [publish your repository to GitHub](https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line) (or any other version control website), it is not necessary
for deploying your applicaiton to Heroku.
If you are using the sample bot, it is already a Git repository.
If you are deploying your own bot, initialise a repository by using the following command inside the root folder of your
codebase.
codebase.
```bash
$ git init
@@ -125,14 +125,14 @@ Then, we want to create a Heroku application.
$ heroku create [project name]
```
The project name is optional and will be automatically generated if not provided. It is recommended that you give a name
to be organised.
The project name is optional and will be automatically generated if not provided. It is recommended that you give a name
to be organised.
To ensure that the Heroku application has been created, run the `git remote -v` command to list the remotes of your
repository. Should your application have been created successfully, you will see a new remote added linking to a Heroku
Git remote.
repository. Should your application have been created successfully, you will see a new remote added linking to a Heroku
Git remote.
```
```bash
$ git remote -v
heroku https://git.heroku.com/chill-ping-bot.git (fetch)
heroku https://git.heroku.com/chill-ping-bot.git (push)
@@ -143,32 +143,32 @@ With the Heroku application created, we can begin configuring our repository to
## Creating a Procfile
As explained earlier, the `Procfile` acts as a build instruction manual for our application. It instructs Heroku how we
want to run our application. Heroku takes over the rest and helps with managing our build environment.
want to run our application. Heroku takes over the rest and helps with managing our build environment.
For my sample bot, the `Procfile` looks like this:
```
```yaml
worker: java -jar target/Bot.jar
```
Let's breakdown this file. We first declare the dyno type as `worker`. Then, we specify the command to run our `.jar`
file.
Let's breakdown this file. We first declare the dyno type as `worker`. Then, we specify the command to run our `.jar`
file.
Heroku is able to intelligently detect that our Kotlin application uses Maven as a build tool and runs the
`mvn clean install` command to create our `Bot.jar` file. Then, it will use the commands in the `Procfile` to run the
application.
Heroku is able to intelligently detect that our Kotlin application uses Maven as a build tool and runs the
`mvn clean install` command to create our `Bot.jar` file. Then, it will use the commands in the `Procfile` to run the
application.
## Securing Discord bot tokens
A Discord bot requires a token to run.
You can obtain this bot token when you make a new Discord bot from the Discord
[developer dashboard](https://discordpy.readthedocs.io/en/latest/discord.html).
However, you do not want to expose this token in your repository as this would mean that others could launch and
access your bot.
[developer dashboard](https://discordpy.readthedocs.io/en/latest/discord.html).
However, you do not want to expose this token in your repository as this would mean that others could launch and
access your bot.
As mentioned earlier, we will make use of Heroku's [config vars](https://devcenter.heroku.com/articles/config-vars) to
safely store and access this token.
safely store and access this token.
We will add our bot's token as an environment variable and use `System.getenv()` method to retrieve this value.
@@ -176,7 +176,7 @@ We will add our bot's token as an environment variable and use `System.getenv()`
$ heroku config:set BOT_TOKEN=<bot token>
```
Inside the `Bot.kt` file, you will find the following lines in the `main()` function.
Inside the `Bot.kt` file, you will find the following lines in the `main()` function.
```kotlin
val token = System.getenv("BOT_TOKEN")
@@ -184,15 +184,15 @@ val token = System.getenv("BOT_TOKEN")
```
This will retrieve the corresponding environment variable that we have stored in Heroku. If there is no environment
variable present, we will stop the bot from launching and display an error.
variable present, we will stop the bot from launching and display an error.
An additional benefit of storing our bot tokens as an environment variable is that we are able to store the bot token
locally as an environment variable which streamlines our development process as we could have a separate token used
for a development/testing bot.
locally as an environment variable which streamlines our development process as we could have a separate token used
for a development/testing bot.
## Launching the bot
After configuring everything, commit all the changes to your project, and push it to the `heroku` remote.
After configuring everything, commit all the changes to your project, and push it to the `heroku` remote.
```bash
$ git add .
@@ -200,41 +200,41 @@ $ git commit -am "Setup Heroku"
$ git push heroku master
```
If you encounter a problem with pushing to the `heroku` remote, use the command `heroku logs --tail` and find the
latest error messages to debug any errors.
If you encounter a problem with pushing to the `heroku` remote, use the command `heroku logs --tail` and find the
latest error messages to debug any errors.
After pushing the changes, Heroku will build your application. However, it is not online yet as you have to scale
your application. This tells Heroku how many instances of your application you wish to run. For our case, we can go
with one worker dyno.
your application. This tells Heroku how many instances of your application you wish to run. For our case, we can go
with one worker dyno.
```bash
$ heroku ps:scale worker=1
```
You can now invite your bot to a server and test it out. If you're using the sample PingBot, you can use `!ping` and
expect the bot to respond with `Pong!`.
expect the bot to respond with `Pong!`.
## Now what?
Congratulations! You have just deployed a Discord bot onto Heroku! When you make changes to the bot, you are free to
commit and push those changes to the `heroku` remote to update the bot that is online.
commit and push those changes to the `heroku` remote to update the bot that is online.
Here are some tips for developing with Heroku.
1. While working on your development copy of the bot, it is recommended that you obtain a seprate bot token and
attach it as an environment variable to your local development environment. Doing so allows you to maintain your
bot's uptime while making changes.
1. While working on your development copy of the bot, it is recommended that you obtain a seprate bot token and
attach it as an environment variable to your local development environment. Doing so allows you to maintain your
bot's uptime while making changes.
2. If you encounter any errors or your bot is not responding, use the `heroku logs --tail` command to view the logs
of your application. Doing so allows you to check if there were any errors while running your project.
3. If you require persistent storage, Heroku comes with a free tier plugin for
[PostgreSQL.](https://www.heroku.com/postgres) Heroku - by default - has ephemeral storage, meaning it does not
maintain new files after each build.
of your application. Doing so allows you to check if there were any errors while running your project.
3. If you require persistent storage, Heroku comes with a free tier plugin for
[PostgreSQL.](https://www.heroku.com/postgres) Heroku - by default - has ephemeral storage, meaning it does not
maintain new files after each build.
## Conclusion
Heroku offers a free alternative to many hosting platforms and is a perfect platform for aspiring bot developers to begin.
More resources on hosting JVM-based applications on Heroku:
- [Getting Started on Heroku with Java](https://devcenter.heroku.com/articles/getting-started-with-java#introduction)
- [Java Sample (on GitHub)](https://github.com/heroku/java-sample)
@@ -24,7 +24,7 @@ And we can keep going on and on, creating more arrays inside the arrays.
To create multidimensional array, you do it like a regular array but with a extra `[]` at the end.
##### Method 1:
#### Method 1:
Use
@@ -48,7 +48,7 @@ This will make a empty 2x3 matrix that looks like:
So there are 2 arrays with 3 elements each within the array `arr`.
##### Method 2:
#### Method 2:
Use:
@@ -70,7 +70,7 @@ This will make a 2x3 matrix with preset values instead of all 0's so it'll look
{{1,2,3},{4,5,6}}
```
##### Method 3:
#### Method 3:
Combine both:
@@ -92,7 +92,7 @@ This will make a 2x3 matrix that looks like:
{{1,2,3},{4,5,6}}
```
##### Note:
#### Note:
It is possible to go ever further, and so a declaration like `data_type array_name[A][B][C]` is possible and would add more layers to your array. So after going through one layer, you have to input the location of the next layer, and so on and so forth until you reach the deepest layer of the `{}` where you'll find the object.
@@ -108,9 +108,9 @@ This will make an 2x3x4 matrix that looks like:
{{{0,0,0,0},{0,0,0,0},{0,0,0,0}},{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}
```
### What can you do with it?
## What can you do with it?
##### Calling objects
#### Calling objects
To get the object inside, you can call for the object inside a multidimensional array by putting a integer inside the `[]`.
@@ -126,7 +126,7 @@ This would output `2` because using array indicies, `2` is the object in positio
You must put an integer in both `[]`, or else you will get an error.
There is no syntax to instantly view the whole array, but an easy way is to loop through the whole array and outputting it.
##### Reassigning objects
#### Reassigning objects
Like with a regular array, you can also reassign what object is being held inside a exact position using `=`
So let's take for example the array made in example 2 above, which looks like:
@@ -142,7 +142,7 @@ This would cause the array to change to looking like:
{{1,2,3},{4,1337,6}}
```
### Restrictions
## Restrictions
1. The size is locked upon initialization. Once you make the array, its size is locked. For example, if you make a 2x3 array, and realize you need another column or row, you have to either make a new one, or change the size where you initialize it. If you want a dynamic size array, a array which you can change the size of, consider using `std::vector` instead.
2. There is no way to search except by iterating through each object in the entire array. For example, if you need to find the number `2` in:
+12 -12
View File
@@ -1,6 +1,6 @@
---
authors:
- "cros#0001"
- "cros#0001"
created_at: "2020/04/23"
title: The Past, Present, and the Future
---
@@ -16,13 +16,14 @@ This document will constantly evolve to document this everlasting war. We don't
## The Past
### The War of Xerxes & Greeks
Some of the earliest accounts of hiding secrets date back to Herodotus, a legendary figure known as "the father of history". Herodotus in one of his accounts, chronicles the conflict of Persia and Xerxes, the despotic king of Persians. It was art of hiding secrets that saved Persia from falling into slavery.
Greek and Persia are both known for their well running feud. This feud reached a never before seen crisis after Xerxes started construction of the new capital of his great kingdom. Gifts and tributes arrived from kings, merchants, and the likes with the sole exception of Athens and Sparta. Xerxes was extremely proud and this insolence has reached his bottom line. Xerxes started mobilizing a force and declared that he will conquer the world and Persia's boundary would be the heavens itself. He actually assembled the greatest fighting force in the history of mankind, and that too in secrecy, and was ready to launch an attack.
Greek and Persia are both known for their well running feud. This feud reached a never before seen crisis after Xerxes started construction of the new capital of his great kingdom. Gifts and tributes arrived from kings, merchants, and the likes with the sole exception of Athens and Sparta. Xerxes was extremely proud and this insolence has reached his bottom line. Xerxes started mobilizing a force and declared that he will conquer the world and Persia's boundary would be the heavens itself. He actually assembled the greatest fighting force in the history of mankind, and that too in secrecy, and was ready to launch an attack.
This buildup, however, was witnessed by Demaratus. Demaratus was a greek who was exiled from his homeland, and lived in a Persian city. Yet, he still felt some loyalty towards his home, so he decided to warn them about the incoming disaster. The question was, how would I do that without getting caught by the Persian Guards. Unlike fantasy novels, no pigeons were willing to come to take his letter to the Greek commanders. He decided to scrape wax from the wooden folding tablets, write the message, and then cover it with wax again. This way, it appears blank to the guards, and when the message reaches the destination, the wax can be scraped off, and the message could be received.
This buildup, however, was witnessed by Demaratus. Demaratus was a greek who was exiled from his homeland, and lived in a Persian city. Yet, he still felt some loyalty towards his home, so he decided to warn them about the incoming disaster. The question was, how would I do that without getting caught by the Persian Guards. Unlike fantasy novels, no pigeons were willing to come to take his letter to the Greek commanders. He decided to scrape wax from the wooden folding tablets, write the message, and then cover it with wax again. This way, it appears blank to the guards, and when the message reaches the destination, the wax can be scraped off, and the message could be received.
Thanks to this message the defenseless Greeks began to arm themselves. They were able to create two hundred warships that could be used to fight off the invasion. Xerxes has lost the element of surprise, and the Greeks were ready, waiting for the ambush. As the Greeks were prepared, they were able to bait the Persian warships to fight in the confines of the bay. Soon panic took hold of the Persian forces. Princess Artemisia was surrounded by three sides, and scared for her life decided to head back to the sea, only to ram her ship to another ship. Soon, chaos took over, and Greeks launched a bloody assault on the Persian forces. The mightiest army assembled had been outmaneuvered.
Thanks to this message the defenseless Greeks began to arm themselves. They were able to create two hundred warships that could be used to fight off the invasion. Xerxes has lost the element of surprise, and the Greeks were ready, waiting for the ambush. As the Greeks were prepared, they were able to bait the Persian warships to fight in the confines of the bay. Soon panic took hold of the Persian forces. Princess Artemisia was surrounded by three sides, and scared for her life decided to head back to the sea, only to ram her ship to another ship. Soon, chaos took over, and Greeks launched a bloody assault on the Persian forces. The mightiest army assembled had been outmaneuvered.
This simple strategy by Demaratus revolved around hiding the message. In fact, this is not the first time a simple concealment of a message has worked. Herodotus' account also tells of another extremely funny tale. Histiaeus wanted to encourage Aristagoras to revolt against the persian king. To convey this message without being intercepted, he shaved the head of one of his messengers, and wrote the message on his scalp, and then waited until his hair had grown back. Since the messenger seemingly carried nothing with him, the king's guards didn't give him a hard time. When the messenger finally reached the recipient of the message, he shaved off his head and pointed it at the intended recipient.
@@ -34,12 +35,12 @@ While steganography is certainly useful, and still used quite extensively, it su
Both can be combined for maximum security. During World War II, microdot was a form of steganography that Germans extensively used. They'd shrink a page full of text down to less than 1 millimeter, then hide it on top of a letter. A tip from an anonymous source to the FBI, who told them to look out for a shiny gleam was the first time Americans had caught this. Therefore, Americans were able to read the contents of the page, only that the Germans were extra careful and had scrambled the text and then reduced it. This combines cryptography and steganography for maximum security. Cryptography is considered to be the more powerful of the two branches, because cryptography is the only technique that prevents messages from being processed by the enemy.
Ancient cryptography can be thought off with two branches. Transposition and Substitution Ciphers.
Ancient cryptography can be thought off with two branches. Transposition and Substitution Ciphers.
In the former, we rearrange the letters. While this is insecure for smaller messages, for bigger numbers it's extremely difficult to bruteforce. For example, in a short email of 40 characters, there are 40 to the power of 26 variations. A thousand lifetimes is not enough to decode this one by one. In fact, the sun would have probably swallowed us whole long ago before we finish. While this might be super secure, if we randomly jumble these letters without reason, then the intended recipient would also have to spend a thousand lifetimes before getting the message. It's a little too late by then. Which means, it has to be fairly straightforward to be understood by the recipient, that has been previously agreed.
In the former, we rearrange the letters. While this is insecure for smaller messages, for bigger numbers it's extremely difficult to bruteforce. For example, in a short email of 40 characters, there are 40 to the power of 26 variations. A thousand lifetimes is not enough to decode this one by one. In fact, the sun would have probably swallowed us whole long ago before we finish. While this might be super secure, if we randomly jumble these letters without reason, then the intended recipient would also have to spend a thousand lifetimes before getting the message. It's a little too late by then. Which means, it has to be fairly straightforward to be understood by the recipient, that has been previously agreed.
The later, called substitution revolves around substituting something for another. One of the earliest descriptions of this appears in Kama Sutra, a text written in the fourth century about 64-arts women should study to be a good wife. One of those arts is the art of cryptography. One of the techniques recommended is to pair one set of letters with another.
The later, called substitution revolves around substituting something for another. One of the earliest descriptions of this appears in Kama Sutra, a text written in the fourth century about 64-arts women should study to be a good wife. One of those arts is the art of cryptography. One of the techniques recommended is to pair one set of letters with another.
### Caesar and his ciphers
One of the first documented uses of a substitution cipher is documented in Julius Caesar's Gallic Wars. Caesar describes how he sent a message to Cicero, who was on the verge of surrendering that his army is on his way to reinforce them. Caesar instructed his messenger, who was ahead of the army rushing towards Cicero, that if he couldn't approach the tower to give the news to Cicero, fasten the letter to the spear, and hurl it towards the tower. The letter substituted Roman Letters with Greek Letters effectively making it incomprehensible to the enemy soldiers. The messenger, fearing for his life, hurled his spear towards the tower, and by sheer luck it struck one of the tower's walls. After two days, the letter was sighted by one of Cicero's soldiers, and was brought to him. Cicero was extremely happy, and recited the letter to his parade of soldiers, thus increasing their morale to maximum.
@@ -70,15 +71,14 @@ When she returned back to Scotland, the nation was completely different. Scotlan
Her next marriage was hardly more successful. James Hepburn, was publically considered the murderer of Mary's husband. Further events occurred, and the protestant nobles rebelled against Mary. Mary was imprisoned. However, next year she escaped from her prison, and fled for her life to England through a fishing boat. She had hoped that Elizabeth, her cousin, would provide her refuge. This was a big mistake, as English Catholics considered Mary, a catholic, to be the true queen of England. Thus Elizabeth imprisioned Mary, on paper the reason was her connection with hthe murder of Darnley fearing her rise.
Mary was imprisoned for 18 years. Her sole crime was her existence. This had pushed her to limit. Some of her catholics supporters who were increasingly being harassed and disposed by the protestants, hatched a plan to rescue her. Mary, then masterminded a plan to assassinate Elizabeth. As she is next in line for the throne, she would effectively be able to escape imprisonment. Mary designed a cipher to communicate with her correspondents, consisting of cipher alphabets and code words. Her plans were going well, and she would have succeeded, but her courier was actually double agent to Walsingham, principal secretary to the Queen. While Mary used a fairly complicated cipher, her correspondents only sent an extremely simple cipher when replying to her. Walsingham was a firm believer in cryptography. He has learnt his lessons and understood the power of cryptography after he was able to deter an invasion of England thanks to it. So he was very ready to fight off this threat. He laid down waiting for the right moment to strike.
Mary was imprisoned for 18 years. Her sole crime was her existence. This had pushed her to limit. Some of her catholics supporters who were increasingly being harassed and disposed by the protestants, hatched a plan to rescue her. Mary, then masterminded a plan to assassinate Elizabeth. As she is next in line for the throne, she would effectively be able to escape imprisonment. Mary designed a cipher to communicate with her correspondents, consisting of cipher alphabets and code words. Her plans were going well, and she would have succeeded, but her courier was actually double agent to Walsingham, principal secretary to the Queen. While Mary used a fairly complicated cipher, her correspondents only sent an extremely simple cipher when replying to her. Walsingham was a firm believer in cryptography. He has learnt his lessons and understood the power of cryptography after he was able to deter an invasion of England thanks to it. So he was very ready to fight off this threat. He laid down waiting for the right moment to strike.
Walsingham had to convince Queen Elizabeth of Mary's guilt. While Queen Elizabeth despised Mary, she was a Scottish Queen and there would be a giant controversy if a head of a state could execute a foreign head of state. Elizabeth wasn't willing to try this gamble as this would set an interesting precedent, which means that rebels wouldn't have much reservations about killing another Queen. Her name? Elizabeth. Then they were related by blood, and it's not exactly a great feeling to execute your own family, especially someone who's life was such a tragedy. The essence of this assasination was the exact opposite of what caused her abdication from the throne. In this case, some catholic noblemen wanted to replace Elizabeth,a protestant with a catholic queen, and Mary perfectly fit the bill. It was clear that Mary was involved in the incident, but they were not sure if Mary was a figurehead, or if she was the mastermind herself. Thus, Walsingham's challenge was to find definitive proof that could link Mary as the mastermind behind plotting the assasination of the Queen of England.
Walsingham had to convince Queen Elizabeth of Mary's guilt. While Queen Elizabeth despised Mary, she was a Scottish Queen and there would be a giant controversy if a head of a state could execute a foreign head of state. Elizabeth wasn't willing to try this gamble as this would set an interesting precedent, which means that rebels wouldn't have much reservations about killing another Queen. Her name? Elizabeth. Then they were related by blood, and it's not exactly a great feeling to execute your own family, especially someone who's life was such a tragedy. The essence of this assasination was the exact opposite of what caused her abdication from the throne. In this case, some catholic noblemen wanted to replace Elizabeth,a protestant with a catholic queen, and Mary perfectly fit the bill. It was clear that Mary was involved in the incident, but they were not sure if Mary was a figurehead, or if she was the mastermind herself. Thus, Walsingham's challenge was to find definitive proof that could link Mary as the mastermind behind plotting the assasination of the Queen of England.
Mary was a careful woman. She had ensured that all her communication with other conspirators had been written in the cipher she designed. This cipher turned this wonderful content about murdering a head of state into meaningless symbols that made absolutely no sense. Mary was sure that even if Walsingham intercepted one of her letters, the contents were a complete mystery. Just like how in the modern world, encrypted data cannot be used as evidence by law enforcement agencies, similarly it could not be used in the English Court as well.
Unfortunately for her, Walsingham had another designation. He was England's spymaster. He exactly knew who might be capable of deciphering these meaningless symbols. Thomas Phellippes, while little is known about him, he's a legendary fellow, who was known for deciphering similar cipher messages by those who plotted against Queen Elizabeth, and thus responsible for providing evidence to punish them. Once again, it was the battle of wits against a code maker, and the codebreaker. If Mary's cipher is strong enough, there is a good chance she will survive. Once again, Mary's life hangs on a paper thin margin. However, Phellippes was a genius. He would devour any message he received, and have solutions in matter of time. He was the master of frequency analysis, and with how many times each character repeated, he was able to easily decode majority of the content. As for codewords? That could be easily understood from the context of rest of the decoded message. This is a good example of how sometimes bad cipher is worse than no cipher. If they were meeting in public, they would have acted far more discreetly, but in this case believing their communication to be secure, they threw caution to the wind. Lessons to be learnt here. The correspondents were caught and suffered the most humiliating and horrid execution. In the words of the Elizabethan historian William Camden, “they were all cut down, their privities were cut off, bowelled alive and seeing, and quartered.”
Mary was soon caught, and was sent to trial. Although, they used a cipher, there belonged to an era where ciphers were constantly being weakened by advances in cryptanalysis. It stood no chance against Phellippes. There was sufficient proof, and death penalty was recommended. Elizabeth signed her death warrant. With her family motto in mind, "In my end is my beginning", she approached the block. The executioners requested her forgiveness, and she was finally released from her misery.
Mary was soon caught, and was sent to trial. Although, they used a cipher, there belonged to an era where ciphers were constantly being weakened by advances in cryptanalysis. It stood no chance against Phellippes. There was sufficient proof, and death penalty was recommended. Elizabeth signed her death warrant. With her family motto in mind, "In my end is my beginning", she approached the block. The executioners requested her forgiveness, and she was finally released from her misery.
This document is a work in progress, and will be constantly updated.
@@ -10,7 +10,6 @@ title: Introduction to Cryptography
- [The Codebreakers](https://www.amazon.com/Codebreakers-Comprehensive-History-Communication-Internet/dp/0684831309)
- [Seizing the Enigma: The Race to Break the German U-Boats Codes](https://www.amazon.com/Seizing-Enigma-German-U-Boats-1939-1943/dp/0395427398)
## Books
- [Handbook of Applied Cryptography - Free](http://cacr.uwaterloo.ca/hac/)
+3 -3
View File
@@ -1,11 +1,11 @@
---
authors:
- "AstronautEVA#0331"
title: "What is a class?"
title: "Classes"
created_at: 2019/10/20
---
# What is a class?
## What is a class?
Oftentimes in programs, it is necessary to represent objects from the real world as computer data.
For example, if someone is writing a program that simulates a zoo, they will need to create some animals.
@@ -56,7 +56,7 @@ public class Animal {
}
```
### Class vs Object
## Class vs Object
Remember this is only the description of what an animal is, not a specific animal. A specific animal such as Max is one instance of a class and is called an object. It has values assigned to its attributes like the name is Max and the age is 5. You can call methods on the object such as move or sleep. And there can be an infinite number of objects constructed from a class. To create objects from your class, you need something called a constructor.
+4 -4
View File
@@ -1,13 +1,13 @@
---
authors:
- "AstronautEVA#0331"
title: "What is Inheritance?"
title: "Inheritance"
created_at: 2019/10/24
recommended_reading:
- java/class
---
# What is Inheritance?
## What is Inheritance?
Inheritance is the idea that when two classes have similar implementations, rather than duplicating code for each class one can obtain it from the other. Much like a human child will inherit traits from their parents, a child class will inherit data from
its parent class.
@@ -123,7 +123,7 @@ public class Animal {
It can be used in our subclass.
```
```java
Animal myAnimal = new Animal();
myAnimal.sleep(); // returns "The animal sleeps."
@@ -145,7 +145,7 @@ public class Bird extends Animal {
It cannot be used in our superclass.
```
```java
Animal myAnimal = new Animal();
myAnimal.chirp(); // error, the method does not exist
+2 -4
View File
@@ -8,8 +8,6 @@ external_resources:
href: https://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/
---
## An introduction to Streams
Basically everyone, who spent a few hours coding some Java came across a situation like this:
```java
@@ -30,7 +28,7 @@ Arrays.stream(intArray).forEach(n -> System.out.println(n));
You just made one line out of three. But how does this work? `int[] intArray = {1,2,3,4,5};` does just declare and initialize a new array of integers. This stays the same as before, because you can use the `Arrays.stream()` method for every Array, [as it works with generic Arrays](https://www.mkyong.com/java8/java-how-to-convert-array-to-stream/). This method creates a [Stream Object](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html), that has several methods to perform operations on an array.
### Sorting
## Sorting
Now maybe you have a list instead of an array and you also want the list to get sorted before you print it. Without Streams you would first have to sort the list and then iterate through it. Way too many lines! Using Streams you can simply do:
@@ -46,7 +44,7 @@ intList.stream().sorted().forEach(n -> System.out.print(n + ", "));
At the end, you have again only one line, for sorting and printing every element in a list. Due to the fact that Streams mostly use Method Chaining, you could perform a bunch of operations.
### Filtering
## Filtering
Now you are able to print out every element of an array, a list, a stack, etc. sorted as well as unsorted. The last essential operation is, how to filter your array/list. One often has to only get specific elements of an array. Using Streams you could do it like this:
@@ -16,7 +16,7 @@ completed at a later time. Much like in real life, when you create a promise, yo
to fulfill that promise. However, sometimes things go wrong where you can no longer fulfill
a promise you made. This is essentially the main idea behind how promises work in javascript.
### Basics
## Basics
When you create a Promise or call a function that returns a Promise in Javascript, you're left
with an object that can either resolve into the actual value that you were promised, or it
@@ -24,7 +24,7 @@ can reject and leave you with an error for why that promise failed.
We can access these values using the `.then` and `.catch` methods on the `Promise` object respectively.
### A Simple Example
## A Simple Example
First, let's explore a bit of a made-up example. Imagine we have a promise-returning function
called `getMembers` that retrieves all the members in a discord server. When we execute this
@@ -50,7 +50,7 @@ getMembers("The Programmers Hangout").then(members => {
This way we are able to make sure that we only try to `console.log` when the `getMembers` function has resolved and ready to be used.
### Beginner Mistakes
## Beginner Mistakes
Promises are possibly the #1 most common source of confusion for beginners. In order
to avoid falling in pitfalls yourself, you have to remember 2 things about Javascript when
@@ -85,7 +85,7 @@ getWeather("Los Angeles").then(weather => {
});
```
### Real World Example
## Real World Example
Here is a real function that gets character information from the Rick and Morty API.
You can try it in your browser if you want to test it out.
@@ -12,8 +12,6 @@ external_resources:
href: "https://www.freecodecamp.org/news/spread-operator-and-rest-parameter-in-javascript-es6-4416a9f47e5e/"
---
# An overview of the spread operator
Spread operator (or spread syntax) is a powerful feature in Javascript which allows you to do such things as merging or copying objects, expanding an array into function arguments and a lot more. In this post, we are going to cover most of its use-cases.
## Copying an object
@@ -5,8 +5,6 @@ created_at: "2019/10/06"
title: Variables
---
## Variables
A `variable` in Javascript is a "named container" that can hold data. Variables are declared by giving them a name and a value - the `name` allows you to reference the variable throughout your program, and the `value` is the current value the variable represents.
Variables can be defined in the following ways:
@@ -117,15 +115,15 @@ console.log(myVar); // 'test'
This is fixed using `let`
```js
for(let i = 0; i < 5; i++) {
for (let i = 0; i < 5; i++) {
console.log(i);
}
console.log(i); // Error: i is undefined
if (true) {
let myVar = 'test';
let myVar = "test";
}
console.log(myVar) // Error: myVar is undefined
console.log(myVar); // Error: myVar is undefined
```
However, if the above code was in a function, this would not be the case. In the case of a function, the variable will be scoped to the given function, and not accessible outside it. Eg: