feat(resources): split up topics and languages

This commit is contained in:
Jean-Philippe Sirois
2020-05-27 02:42:39 -04:00
parent 8fba0edc4f
commit 135452bd4b
35 changed files with 86 additions and 55 deletions
@@ -0,0 +1,240 @@
---
authors:
- "Chill#4048"
created_at: "2020/04/22"
title: "Deploying discord bots written in Kotlin to Heroku"
external_resources:
- text: Getting Started on Heroku with Java
href: "https://devcenter.heroku.com/articles/getting-started-with-java#introduction"
- text: Java Sample (on GitHub)
href: "https://github.com/heroku/java-sample"
---
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.
## 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!
> 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.
## 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.
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.
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.
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`.
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:
1. Initialise the codebase as a Git repository
2. Create a Heroku application for the bot
3. Create a `Procfile` to supply instructions for Heroku to run the bot
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.
## 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)
If you wish to follow along, you can get the repository via
```bash
$ 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.
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
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).
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
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.
```bash
$ git init
```
## Create a new Heroku application
Then, we want to create a Heroku application.
```bash
$ 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.
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.
```bash
$ git remote -v
heroku https://git.heroku.com/chill-ping-bot.git (fetch)
heroku https://git.heroku.com/chill-ping-bot.git (push)
```
With the Heroku application created, we can begin configuring our repository to deploy to Heroku.
## 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.
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.
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.
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.
We will add our bot's token as an environment variable and use `System.getenv()` method to retrieve this value.
```bash
$ heroku config:set BOT_TOKEN=<bot token>
```
Inside the `Bot.kt` file, you will find the following lines in the `main()` function.
```kotlin
val token = System.getenv("BOT_TOKEN")
?: throw Exception("Must include bot token in environment variable for bot to run")
```
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.
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.
## Launching the bot
After configuring everything, commit all the changes to your project, and push it to the `heroku` remote.
```bash
$ git add .
$ 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.
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.
```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!`.
## 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.
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.
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.
## 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)
@@ -0,0 +1,10 @@
---
authors:
- "Chill#4048"
created_at: 2020/04/20
title: Bot Development
---
###### About
In TPH, we employ the use of various Discord bots to help with a myriad of tasks such as moderation and managing embeds.
@@ -0,0 +1,149 @@
---
authors:
- "Hayden#5036"
created_at: "2019/09/06"
title: Getting Started with KUtils
---
## What is KUtils?
According to the [GitLab repo](https://gitlab.com/aberrantfox/kutils), KUtils is "A comprehensive wrapper over the discord API using JDA in Kotlin". Which is completely believable, because not only does it provide a command handler, but it also provides things like argument handling, services, embed menus, and much, much more.
When it comes to making your first KUtils-powered bot, the task can seem fairly daunting. But make no mistake, it's definitely easier than it looks.
## Installation
### Setting up our IDE
So, for this guide, I'll assume that you're using IntelliJ IDEA. It comes with Kotlin bundled, after all! Open it up, smash that 'New Project...' button, and click on the Maven category. Use the Kotlin archetype and hit next. Give your project a `groupId` and `artifactId`, but version isn't really necessary to edit.
### Setting up Maven.
You're not _quite_ off to the races though, only some minor paint splashes yet. You've gotta actually _add_ KUtils as a Maven dependency. So open up the file in your project's root called `pom.xml`, and find the `properties` tag. Inside, you want to add this line of code:
```xml
<kutils.version>0.11.2</kutils.version>
```
This will be used in a minute or two. Next, we need to tell Maven where to find KUtils. It's on the JitPack repository, so put this code in below it.
```xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```
Let's break that down. `repositories` is a collection of `repository` tags. `repository` tags tell Maven where to look to find packages. By default, it'll look in "Maven Central", which is like the official NPM registry or Docker Hub. But we're configuring it to look in the JitPack repository. So we give it an ID to remember the repository by, in our case we just named it `jitpack.io`, and then we tell Maven what URL to look up to find the packages. In this case, that's [https://jitpack.io](https://jitpack.io).
Alright, so now we know what _that_ did, let's move on to finally including KUtils.
Head down to the `dependencies` section. In here, we're going to set up our reference to KUtils, so that Maven knows to download it when we build the bot into its final form. Pop this little tidbit of code in:
```xml
<dependency>
<groupId>com.gitlab.aberrantfox</groupId>
<artifactId>Kutils</artifactId>
<version>${kutils.version}</version>
</dependency>
```
So here, we're declaring that Maven needs to grab the `dependency` with the `groupId` of `com.gitlab.aberrantfox`, and the `artifactId` of `Kutils`. But wait a second, what's that? That looks like some weird JavaScript string literal! Well, it's similar. You remember when we put `<kutils.version>` in our `properties` tag? Well, putting text in between `${` and `}` makes Maven get the property you set matching that text. So in our case, it'll swap `${kutils.version}` for `0.11.2`.
That should be all, you should now have a blank Maven-enabled, Kotlin-powered, KUtils-backed canvas to spray your art at like some deranged lunatic with a complex or two.
## Setting up the bot
### The main() function
In Kotlin, we define where our app will start from by using the `main` function. In your codebase, there should be a file called `App.kt` or something similar. It should just be a file on its own with the `.kt` extension. If you open that, you'll see this code:
```kotlin
fun main(args: String[]) {
println("Hello, world!")
}
```
If you hit run (the little green play icon) in the top right-hand corner (for IntelliJ users), after a little while of it building, a window will pop up at the bottom of the screen and in it, the text `Hello, world!` will come out. If you think that's awesome, then great! Maybe the [Kotlin documentation](https://kotlinlang.org) would be a cool place to have a look around before following this guide further.
If, however, you're kind of bored, and wish I'd get on with the damned tutorial---
Then I've got news for you.
Because that's what we're doing.
### Goodbye, println, hello KUtils!
So, let's swap out that measly little `Hello, world!` for a KUtils login, shall we?
So, gut the contents of `main`, and replace them with this:
```kotlin
startBot("your-bot-token-goes-here") {
configure {
prefix = "!"
reactToCommands = true
deleteMode = PrefixDeleteMode.None
}
}
```
Now, don't worry, if IntelliJ complains that it can't find any of the things there, click on where it goes red, and hit <kbd>alt+enter</kbd> until there are none left. Now let me break this down.
- `startBot` calls KUtils' start function, using the string we're passing it there (which you need to replace with a Discord bot token. If you don't know what that is or how to get it, use some Google-fu.)
- `configure` is a KConfiguration safe type constructor, which we use to configure the bot's features.
- `reactToCommands` tells the bot to give us a little set of emoji eyes whenever we use a command to tell us it's recognised it.
- `deleteMode` isn't important, and the reasoning for it being there isn't either.
So, is that it? Well, yeah. It is. If you hit run again, you should be greeted with a set of warnings and messages in the output window again. However, if you invite the bot to a server, you'll see that it's now online! Awesome!
Go into that server and type `!help`, and you should be greeted with a cute little embed telling you how the help command works!
## Commands
### Oi! Don't be so bossy with those command words!
So, if you've followed the guides thus far, you might be shouting, "Oi! Hayden! Get off your lazy bum and tell me how to make my own commands!"
Alright, alright, simmer down. We'll do that now.
So, to get started, find the folder your bot's main `.kt` file is in, and right click, go to 'New', then 'Package'. Type 'commands' in the box and smash that enter key like your finger is a missile. (although... not if you're on a laptop... that... that could end badly.)
Make a new Kotlin Script in that folder called `UtilityCommands`. We're gonna first off declare that we're making a set of commands.
```kotlin
@CommandSet("Utility")
```
This creates a new CommandSet called "Utility". Although you may notice it's got a red line under it. That's just IntelliJ screaming at you because you don't have a function containing all the sweet, sweet commands it has to run. So let's give it one.
```kotlin
@CommandSet("Utility")
fun utilityCommands() = commands {
}
```
Note how this has a weird ending. It doesn't go straight into a function, this goes into a `commands` block. Huh. Well, believe me, it makes it very simple. Because now all you need to do is add this:
```kotlin
@CommandSet("Utility")
fun utilityCommands() = commands {
command("Ping") {
description = "Pong!"
execute {
it.respond("Pong!")
}
}
}
```
...which creates a command called "Ping", with the description of "Pong!", and which, when it runs, will respond by saying "Pong!". Try it! Restart the bot and run `!ping`.
That's all she wrote, folks. That's how you make commands and groups of them in KUtils.
So thus far, you can basically make a basic (ah? ah? basically basic? ah? no? nevermind) Discord bot. And (minus reading time (**_hopefully if you actually read this_**, looking at you, skim-reders)) it only took about 5-10 minutes to set up! That's cool, isn't it?
Well, stay tuned, because coming up are some tutorials about setting up arguments, services, preconditions and more!
@@ -0,0 +1,84 @@
---
authors:
- "cros#0001"
created_at: "2020/04/23"
title: The Past, Present, and the Future
---
## Introduction
For eons, the bravest kings, noblest queens, mightiest commanders, and fearsome scouts have all relied on effective communication to win wars, stop rebellions, command armies, and safeguard against betrayal. Yet, they all understood if their communication was intercepted, and should this information fall into enemy hands, it might lead to demise, and ultimately death. To prevent interception of vital communication through betrayal or usage of force, they encouraged scholars to come up with what's now known as ciphers, which are techniques for disguising information.
The desire for secrecy means, that someone is out there to get that information. This has resulted in two different factions, the codemakers and the codebreakers. From the beginning of time, there has been this eternal war between both factions. The codemakers strive to make better and better codes, the codebreakers have come with stronger and powerful methods for attacking these codes. In fact, this war between the codemakers and the codebreakers has been responsible for many breakthrough in mathematics and the sciences including the most important one, computers.
This document will constantly evolve to document this everlasting war. We don't really talk about how the techniques work in this document. For those head over to different sections where we discuss those in detail. For those who are new to cryptography, however, it is essential, in my opinion, to understand the history of cryptography and how the events from past resulted in present, and how they will affect the future.
## 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.
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.
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.
### What really is cryptography and steganography?
The technique of hiding the existence of messages is called steganography. The word was derived from two, you guessed it, greek words steganos, meaning covered, and graphein meaning to write. Other examples of this technique being used include the ancient Chinese silk ball, where a message was written, which was then covered in wax and swallowed by the messenger. The usage of invisible ink, which disappears until heated is also considered steganography. The "milk" of tithymalus plant was originally first used as ink. As the ink is transparent after drying, gentle heating will char the ink to visible brown. In fact, many organic fluids work similarly, and who knows for how many modern spies have improvised by using their own urine.
While steganography is certainly useful, and still used quite extensively, it suffers from a fundamental weakness that if the message is discovered, then the content of the message is revealed right away. There will be events where someday the message is discovered. Scraping wax tablets, heating paper, shaving heads, while unlikely might happen some day. Thus in parallel, we started the evolution of cryptography. Cryptography originates from two, you guessed it (it's always either latin or greek), greek words crypto which means "hidden" and graphein which means "to write". The aim is to make the message unintelligible. The protocol is discussed beforehand, and thus only those who are privy to the details are able to reverse it. Without the protocol, it is quite difficult to scramble the message, although when the message is of utmost importance, history has told us that codebreakers have always been successful. Poor Mary learnt it the hard way.
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.
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.
### 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.
In fact Caesar was one of the firmest believer of cryptography. In fact, he used cryptography so much that Valerius Probus wrote an entire treaty on his ciphers, which unfortunately didn't survive time. The only Cipher of his, that we have a detailed description of, is called the Caesar Shift Cipher, which works by shifting the position of every character by some number.
### Arabic Golden Age
In 750AD, the start of the Abbasid dynasty healded the golden age of Islam. The arts and the sciences flourished. The legacy of Islamic scientists from that era is still felt to this day evident from arabic words such as algebra, that are found all around the sciences. This richness was largely due to rich and peaceful society. There was not much interest in conquest, and wanted to establish an affluent society. Lower taxes encouraged greater economy, and all of this centred around effective administration, which relied on secure communication achieved through encryption. Officials protected sensitive information and tax records through cryptography. They usually used a monoalphabetic substitution cipher, where letters could be replaced by different letters. Though these ciphers aren't much of a big deal, arabs alongside being able to use ciphers, were also able to destroy them. They invented cryptanalysis, which is the science to unscramble encryption without knowing it's key. While cryptographers develop new methods of encrypting data, cryptanalysts are the ones responsible for breaking these. Arabic scientists were able to find a way to break the monoalphabetic substitution cipher, which had been invulnerable for centuries.
Cryptanalysis could not be invented yet because it requires study of mathematics, statistics and linguistics. Since Islam pursued knowledge above all, the scientists were equipped with the tools to dabble in it. The economic success also meant that the scholars could focus on research instead of worrying about survival. The art was able to be distributed as they had acquired the knowledge to make paper from the Chinese.
The arabic scholars analyzed individual letters, and not just words. They later realized that certain words, especially a and i, are very common in arabic. This small discovery is actually a giant breakthrough that later evolved to form frequency analysis. Instead of scrambling billions of characters, frequency of characters could easily reveal the contents of the message. While highly effective, this is not a silver bullet. Short texts deviate greatly from the averages, for example. Similarly for longer content, it's not necessary for it to follow that certain frequency.
### The Dark Ages
While the Arab scholars were having a good time, europe was struck in Dark Ages. Arabs had already pioneered cryptanalysis, while Europe was still struggling with the basics. The study of cryptography was mostly done by monks studying bible, in search of hidden meaning, much like a bible study group. These monks were fascinated by the fact that the old testament included many example of cryptography. For example, atbash cipher appears quite often in the bible. Thanks to this fascination, the usage of cryptography got more and more popular in Europe.
Centuries later, cryptography became a norm in Europe, with alchemists and scientists using it to encrypt their discoveries. Soon, politics came into play, and interest in cryptography reached unprecedented heights for secret communications.
### The Cipher of Mary, Queen of Scots
Mary Stuart was born to King James V, and was his only legitimate surviving child. The distraught Scottish King had suffered a complete mental and physical breakdown, after a crushing battle with Henry VIII. Just a week later after Mary was born, as if he was waiting for the news of an heir, died. The untimely death of her father meant that Mary inherited the throne as an infant. At the age of nine, she was officially crowned as the queen of Scots. Her young age prevented Henry VIII from attacking Scotland, as he would receive backlash for invading a country whose king recently died. Henry VIII decided to strike a deal by offering his son and Mary to be tied in a sacred bond of marriage. His idea, that this way his line could peacefully gain the crown of Scotland. The Scots, however, instead struck a deal with the French, that Mary and Francis, the dauphin of France, would marry when they were of age, and would unite France and Scotland. As France was a Catholic nation, Scotland themselves would prefer to ally with a catholic country. In the meantime, France would deter England from attacking Scotland.
Soon Mary at the age of six, set sail to France. Mary's first few years in French Court were the definition of luxury. She was protected from harm, lived in a grand castle, and fell in love with her future husband. At the age of sixteen they married, and Mary became the Queen of France. Soon, however, Francis succumbed to an ear infection, and Mary was widowed. From this point onwards, her life became full of tragedy.
When she returned back to Scotland, the nation was completely different. Scotland had moved mostly towards the Protestant church. At first, Mary was able to keep her subjects in check. However, her second marriage to her cousin Darnley, led to decline in her popularity. Darnley was a vicious man, whose greed for power resulted in Mary losing faith of Scottish nobles. Following year, Darnley viciously murdered Mary's secretary in front of her. It was clear that Darnley was not a sane man, and he had a lot of power that an insane man should not. Soon, his house blew up, and when he attempted to escape was strangled. Her son was the only good thing to come out of the marriage.
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.
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.
This document is a work in progress, and will be constantly updated.
@@ -0,0 +1,21 @@
---
authors:
- "cros#0001"
created_at: 2020/04/23
title: Introduction to Cryptography
---
###### Popular Science Books
- [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/)
- [Serious Cryptography](https://nostarch.com/seriouscrypto)
- [Cryptograpy Engineering](https://www.schneier.com/books/cryptography_engineering/)
###### Video
- [Coursera](https://www.coursera.org/learn/crypto)
@@ -0,0 +1,58 @@
---
authors:
- "YourDailyLlama#1127"
created_at: "2020/05/24"
title: "Deploying a site with Netlify and adding HTTPS"
external_resources:
- text: Freenom
href: "https://freenom.com"
- text: Netlify
href: "https://netlify.com"
---
Netlify is an awesome service for all kind of web apps and wesbites! Here you will learn how to deploy a site and add HTTPS security to it for free!
## Getting started
First you will have to navigate to https://netlify.com then login with your prefered service.
Now, there are two ways to deploy a site.
1. From a Github repository
2. Just drag and drop the files
So if you got your site files or Github repository ready, let's get started!
## 1. Deploying site from a Github repository
Go ahead and click the big button saying "New site from Git".
Choose Github, then search for the repository holding your site's files, then click next and one more next in the "Build and deploy options"
(If you know what you are doing, then change stuff in there if required)
Now, if everything was done successful, your site should be up and running under a random generated Netlify name.
## 2. Deploying site with drag and drop
First you will have to navigate to https://netlify.com then login with your prefered service.
Now, almost at the bottom of the page there is a file drop section, now open your File Explorer and drag and drop the site files inside there, the site should be running under a random generated Netlify name.
## Changing domain
### This is not sponsored, but https://freenom.com can provide you free fast domains if you don't have one already
Now if you have your site running on Netlify, it's good also changing it's domain.
Go to Settings > Domain management and there should be an option add domain (I dont really remember what it says)
After adding your custom domain, you will have to setup the Netlify DNS on your site.
The process is very simple, just follow the instructions given by Netlify.
## Adding HTTPS
Now, who does not like secure websites.
In Settings > Domain management at the bottom of the page there is the "HTTPS" section.
If you have have done the process of setting up the Netlify DNS, then just click on "Verify DNS configuration"
and your site should have a HTTPS connection now.
## Congrats!
If you done all the steps and everything is working, congrats!
Netlify got so much more to offer tho.
They have a custom form system, custom login system and many more for free!
Hope you liked this tutorial, and have a great day!
@@ -0,0 +1,15 @@
---
authors:
- "veksen#1565"
created_at: 2019/12/15
title: Python
---
###### Get started
- [Freecodecamp Beginner Roadmap](https://www.freecodecamp.org/news/beginners-roadmap-web-development/)
- [MDN Get Started](https://developer.mozilla.org/en-US/docs/Learn)
###### Extra
- [Google developer best practices](https://web.dev/learn/)