Merge branch 'master' of gitlab.com:shockrah/csnotes
This commit is contained in:
commit
c28b068558
1
312/.gitignore
vendored
Normal file
1
312/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
hw/
|
2
312/hw/.gitignore
vendored
2
312/hw/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
makefile
|
|
||||||
*pdf
|
|
72
312/hw/1.md
72
312/hw/1.md
@ -1,72 +0,0 @@
|
|||||||
---
|
|
||||||
title: Homework 1
|
|
||||||
author:
|
|
||||||
- Alejandro Santillana
|
|
||||||
---
|
|
||||||
## Section 1
|
|
||||||
|
|
||||||
1. What are the differences between message confidentiality and message integrity? Can you have confidentiality without integrity? Can you have integrity without confidentiality? Justify your answer.
|
|
||||||
|
|
||||||
- Confidentiality is the idea that the intended message will not be unexpectedly shared to a third party. Message integrity however means to imply that the structure of the message or messaging system is working as expected. This does mean however that a system which does not guarantee integrity could potentially be unable to guarantee confidentiality.
|
|
||||||
|
|
||||||
|
|
||||||
2. Internet entities (routers, switches, DNS servers, Web servers, user end systems, and so on) often need to communicate securely. Give three specific example pairs of Internet entities that may want secure communication.
|
|
||||||
|
|
||||||
<!--
|
|
||||||
This answer is awful but if I don't word it this way I literally won't get any points.
|
|
||||||
-->
|
|
||||||
3. Name 3 challenges faced in order to provide computer security.
|
|
||||||
|
|
||||||
- Providing confidentiality between parties, ensuring that systems in place maintain integrity against various attacks, as well as maintaining other services so that they can be used by intended parties.
|
|
||||||
|
|
||||||
4. Differentiate between active and passive attacks.
|
|
||||||
|
|
||||||
- Active attacks involving meddling with communications or systems between some target or targets. Passive attacks involve usually listening in some type of manner but without doing anything more.
|
|
||||||
|
|
||||||
5. For each of the following assets, determine if it is a loss of confidentiality, availability, and integrity and also assign a low, moderate or high impact level:
|
|
||||||
|
|
||||||
A. Student grades of the entire class were posted online visible to all.
|
|
||||||
|
|
||||||
- Confidentiality High
|
|
||||||
|
|
||||||
B. Deadlines of your assignments on the schedule were incorrect and incomplete.
|
|
||||||
|
|
||||||
- Integrity : Moderate
|
|
||||||
|
|
||||||
C. iLearn was down during quiz time.
|
|
||||||
|
|
||||||
- Availability : High
|
|
||||||
|
|
||||||
D. I accidentally forwarded a private email from a student to the entire class.
|
|
||||||
|
|
||||||
- Confidentiality : Moderate - High
|
|
||||||
|
|
||||||
## Section 2
|
|
||||||
|
|
||||||
1. Find the gcd(4655, 12075) using Euclidean algorithm.
|
|
||||||
|
|
||||||
```
|
|
||||||
12075 / 4655 = 2 R 2765
|
|
||||||
4655 / 2765 = 1 R 1890
|
|
||||||
2765 / 1890 = 1 R 875
|
|
||||||
1890 / 875 = 2 R 140
|
|
||||||
875 / 140 = 6 R 35
|
|
||||||
140 / 35 = 4 R 0
|
|
||||||
```
|
|
||||||
|
|
||||||
- GCD 35
|
|
||||||
|
|
||||||
2. Is 100 ☰ 50 (mod 5)? Why or why not?
|
|
||||||
|
|
||||||
- Yes because `(100 - 50)` is a multiple of 5.
|
|
||||||
|
|
||||||
3. What is -50 mod 4?
|
|
||||||
|
|
||||||
- 2
|
|
||||||
|
|
||||||
4. What is the quotient and remainder when 17 | -101?
|
|
||||||
|
|
||||||
- Quotient: 0
|
|
||||||
- Remainder: -84
|
|
||||||
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
|||||||
---
|
|
||||||
title: Homework 2
|
|
||||||
author: Alejandro Santillana
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
# Section 1 - Symmetric Key Cryptography
|
|
||||||
|
|
||||||
1. The two approaches to attacking a given cipher are using _brute force_ or _cryptanalysis_. Brute force methods are a simpler method of attack because they naively try all possible inputs for a given output. Cryptanalysis is the process of using the particular characteristics of a cipher to de-cipher the original message.
|
|
||||||
|
|
||||||
2. Chosen plain text attacks involve using a given plain text to determine a cipher text. The attacker themselves choose the plain text and have some kind of cipher text available to them. The algorithm on the other hand is not known to the attacker when performing cryptanalysis. In this way a black box approach to reversing the cipher is taken.
|
|
||||||
|
|
||||||
3. Cryptography is the study and practice of creating hidden messages from plain messages. Cryptanalysis is the practice of analyzing hidden messages to determine a plain message.
|
|
||||||
|
|
||||||
4. Unconditionally secure ciphers are ciphers which are considered secure regardless of how many resources or time are given to reversing the cipher, sometimes due to not having enough information to determine anything useful. Computationally secure ciphers exist on the premise that it is impractical to attempt to break the cipher given a limited amount of compute power.
|
|
||||||
|
|
||||||
5. Key distribution is the first major hurdle to ensure that the one time pad is used effectively. Without properly secure channels to share the key the scheme of a one time pad can not be trusted. The other issue is that the key must be longer than the message itself in order to ensure that parts of it are never reused.
|
|
||||||
|
|
||||||
# Section 2
|
|
||||||
|
|
||||||
1. Encode: _This is an easy problem_. \
|
|
||||||
Decode: _rmij'u uamu xyj_. \
|
|
||||||
Plaintext letter: a b c d e f g h i j k l m n o p q r s t u v w x y z \
|
|
||||||
Ciphertext letter: m n b v c x z a s d f g h j k l p o i u y t r e w q \
|
|
||||||
```
|
|
||||||
Encode portion: uasi si mncmiw lokngch
|
|
||||||
Decode portion: wasn't that fun
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
2. Plain Text: _Must see you over Cadogan West. Coming at once._ \
|
|
||||||
Key: _largest_
|
|
||||||
```
|
|
||||||
Part A:
|
|
||||||
|
|
||||||
L A R G E
|
|
||||||
S T B C D
|
|
||||||
F H I K M
|
|
||||||
N O P Q U
|
|
||||||
V W X Y Z
|
|
||||||
Encoded: UZTB DLG ZPN NWLG TGTUERO VLDB DUHFPE RH WQSRZ
|
|
||||||
|
|
||||||
Part B:
|
|
||||||
Encoded: UZTB DLG ZPN NWLG TGTUERO VLDB DUHFPE RH WQSRZ
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Message: "_Let's skip class and go to the beach_" \
|
|
||||||
Depth = 4 \
|
|
||||||
```
|
|
||||||
L S C S G T E
|
|
||||||
E K L A O H A
|
|
||||||
T I A N T E C
|
|
||||||
S P S D O B H
|
|
||||||
Message: LSCSGTEEKLAOHATIANTECSPSDOBH
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
1
334/.gitignore
vendored
1
334/.gitignore
vendored
@ -2,3 +2,4 @@ bin
|
|||||||
msh
|
msh
|
||||||
*txt
|
*txt
|
||||||
*sh
|
*sh
|
||||||
|
homework/
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
// max length input string
|
|
||||||
#define MAXSTR 25
|
|
||||||
|
|
||||||
// convert input binary string to a number
|
|
||||||
int bindec(char*, size_t);
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
// user input string
|
|
||||||
char s[MAXSTR+3];
|
|
||||||
|
|
||||||
// prompt for input
|
|
||||||
printf("> ");
|
|
||||||
|
|
||||||
// read input string; at most MAXSTR+1 chars accepted
|
|
||||||
// Note: this is tricky. If we accept only MAXSTR chars,
|
|
||||||
// we can't see if user entered more chars and they are
|
|
||||||
// being dropped by fgets.
|
|
||||||
fgets(s, MAXSTR+3, stdin);
|
|
||||||
|
|
||||||
// check input length; n does not include final carriage return
|
|
||||||
int n = strlen(s)-1;
|
|
||||||
if (n > MAXSTR) {
|
|
||||||
printf("input cannot be more than %d characters\n", MAXSTR);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(size_t i = 0; i < n; i++) {
|
|
||||||
if(s[i] == '0' || s[i] == '1') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("input must contain only zeros and ones\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!n) {
|
|
||||||
printf("No input given only hit enter\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int output = bindec(s, MAXSTR);
|
|
||||||
printf("%d\n", output);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bindec(char* buf, size_t len) {
|
|
||||||
int ret = 0;
|
|
||||||
for(size_t i = 0; i < len; i++) {
|
|
||||||
if(buf[i] == '1') {
|
|
||||||
ret <<= 1;
|
|
||||||
ret++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ret <<= 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
|
|
||||||
# Problem lines begin with #@.
|
|
||||||
# For each problem, put your answer on
|
|
||||||
# the line following the problem line.
|
|
||||||
# Do not modify this file in any way
|
|
||||||
# except to insert your answers.
|
|
||||||
|
|
||||||
#@ 1 -- enter a number
|
|
||||||
22
|
|
||||||
#@ 2 -- enter a number
|
|
||||||
7
|
|
||||||
#@ 3 -- enter a number
|
|
||||||
3
|
|
||||||
#@ 4 -- enter a number
|
|
||||||
25
|
|
||||||
#@ 5 -- enter a number
|
|
||||||
255
|
|
||||||
#@ 6 -- enter a binary number
|
|
||||||
1101
|
|
||||||
#@ 7 -- enter a binary number
|
|
||||||
10101
|
|
||||||
#@ 8 -- enter a binary number
|
|
||||||
10000
|
|
||||||
#@ 9 -- enter a binary number
|
|
||||||
110111
|
|
||||||
#@ 10 -- enter a binary number
|
|
||||||
1010000
|
|
||||||
#@ 11 -- enter a number
|
|
||||||
44
|
|
||||||
#@ 12 -- enter a number
|
|
||||||
18
|
|
||||||
#@ 13 -- enter a number
|
|
||||||
471
|
|
||||||
#@ 14 -- enter a number
|
|
||||||
255
|
|
||||||
#@ 15 -- enter a number
|
|
||||||
123
|
|
||||||
#@ 16 -- enter a hex number (beginning with 0x)
|
|
||||||
0x12
|
|
||||||
#@ 17 -- enter a hex number
|
|
||||||
0x05
|
|
||||||
#@ 18 -- enter a hex number
|
|
||||||
0x58
|
|
||||||
#@ 19 -- enter a hex number
|
|
||||||
0x7b
|
|
||||||
#@ 20 -- enter a hex number
|
|
||||||
0x64
|
|
@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
# Homework 1 answer sheet.
|
|
||||||
#
|
|
||||||
# Problem lines begin with #@.
|
|
||||||
# For each problem, put your answer on
|
|
||||||
# the line following the problem line.
|
|
||||||
# Do not modify this file in any way
|
|
||||||
# except to insert your answers.
|
|
||||||
|
|
||||||
#@ 1 -- enter 'a', 'b', or 'c' (don't use quotes in any answer)
|
|
||||||
a
|
|
||||||
#@ 2 -- enter 'a', 'b', or 'c'
|
|
||||||
b
|
|
||||||
#@ 3 -- enter one or more letters, separated by commas
|
|
||||||
b
|
|
||||||
#@ 4 -- enter 'a' or 'b'
|
|
||||||
a
|
|
||||||
#@ 5 -- enter 'a', 'b', or 'c'
|
|
||||||
b
|
|
@ -1,22 +0,0 @@
|
|||||||
# Instructions: edit this file to provide your homework answers.
|
|
||||||
#
|
|
||||||
# Problem numbers are shown on lines that begin with #@.
|
|
||||||
# Please put your solution to a problem on the line *after* the
|
|
||||||
# line with the problem number.
|
|
||||||
#
|
|
||||||
# Do not modify this file *except* to add lines as needed after each problem.
|
|
||||||
# Blank lines are ignored. You don't need to put your name in the file.
|
|
||||||
#
|
|
||||||
# No points will be awarded to incorrectly-formatted files.
|
|
||||||
#
|
|
||||||
|
|
||||||
#@ 1 -- enter 'a', 'b', or 'c' (don't use quotes in any answer)
|
|
||||||
b
|
|
||||||
#@ 2 -- enter 'a', 'b', or 'c'
|
|
||||||
c
|
|
||||||
#@ 3 -- enter 'a' or 'b'
|
|
||||||
b
|
|
||||||
#@ 4 -- enter 'a' or 'b'
|
|
||||||
b
|
|
||||||
#@ 5 -- enter 'a', 'b', or 'c'
|
|
||||||
c
|
|
@ -1,32 +0,0 @@
|
|||||||
# Instructions: edit this file to provide your homework answers.
|
|
||||||
#
|
|
||||||
# Problem numbers are shown on lines that begin with #@.
|
|
||||||
# Please put your solution to a problem on the line *after* the
|
|
||||||
# line with the problem number.
|
|
||||||
#
|
|
||||||
# Do not modify this file *except* to add lines as needed after each problem.
|
|
||||||
# Blank lines are ignored. You don't need to put your name in the file.
|
|
||||||
#
|
|
||||||
# No points will be awarded to incorrectly-formatted files.
|
|
||||||
#
|
|
||||||
|
|
||||||
#@ 1 -- enter a single number
|
|
||||||
1
|
|
||||||
#@ 2 -- enter 'Y' or 'N'
|
|
||||||
2
|
|
||||||
#@ 3 -- enter 'Y' or 'N'
|
|
||||||
Y
|
|
||||||
#@ 4 -- enter 'Y' or 'N'
|
|
||||||
N
|
|
||||||
#@ 5 -- enter text on a single line
|
|
||||||
some stuff
|
|
||||||
#@ 6 -- enter 'Y' or 'N'
|
|
||||||
Y
|
|
||||||
#@ 7 -- enter text on a single line
|
|
||||||
stuff
|
|
||||||
#@ 8 -- enter 'Y' or 'N'
|
|
||||||
N
|
|
||||||
#@ 9 -- enter text on a single line
|
|
||||||
some stuff
|
|
||||||
#@ 10 -- enter 'Y' or 'N'
|
|
||||||
Y
|
|
@ -1,14 +0,0 @@
|
|||||||
#
|
|
||||||
# Problem lines begin with "#@".
|
|
||||||
# For each problem line, enter your answer on the following line.
|
|
||||||
# Do not modify this file in any way except to enter your answers.
|
|
||||||
#
|
|
||||||
|
|
||||||
#@ 1 -- enter 'a', 'b', or 'c' (don't use quotes in any answer)
|
|
||||||
b
|
|
||||||
#@ 2 -- enter 'a', 'b', or 'c'
|
|
||||||
a
|
|
||||||
#@ 3 -- enter 'a', 'b', or 'c'
|
|
||||||
b
|
|
||||||
#@ 4 -- enter 'a', 'b', or 'c'
|
|
||||||
a
|
|
@ -1,14 +0,0 @@
|
|||||||
#
|
|
||||||
# Problem lines begin with "#@".
|
|
||||||
# For each problem line, enter your answer on the following line.
|
|
||||||
# Do not modify this file in any way except to enter your answers.
|
|
||||||
#
|
|
||||||
|
|
||||||
#@ 1 -- enter 'a' or 'b' (don't use quotes in any answer)
|
|
||||||
b
|
|
||||||
#@ 2 -- enter 'a', 'b', or 'c'
|
|
||||||
a
|
|
||||||
#@ 3 -- enter 'T' or 'F'
|
|
||||||
F
|
|
||||||
#@ 4 -- enter 'T' or 'F'
|
|
||||||
F
|
|
@ -1,151 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#define PROMPT "msh> "
|
|
||||||
#define EXIT_CMD "exit"
|
|
||||||
#define MAX_BUF 121
|
|
||||||
|
|
||||||
// Statuses from builtin responses
|
|
||||||
#define RESP_HELP 1
|
|
||||||
#define RESP_DATE 2
|
|
||||||
#define RESP_ECHO 3
|
|
||||||
#define RESP_SHELL 4
|
|
||||||
#define RESP_CD_FAIL -1
|
|
||||||
#define RESP_CD_SUCCESS 6
|
|
||||||
|
|
||||||
// Sub statuses that are generally nice to have
|
|
||||||
#define CD_NOP 0x1
|
|
||||||
|
|
||||||
void echo(const char*);
|
|
||||||
void remove_newline(char*);
|
|
||||||
void exit_branch(const char*);
|
|
||||||
int builtin_response(char*);
|
|
||||||
int cd_handler(char**, const int);
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
FILE* file = NULL;
|
|
||||||
if(argc == 2) {
|
|
||||||
file = fopen(argv[1], "r");
|
|
||||||
if(!file) { return 1; }
|
|
||||||
}
|
|
||||||
char buffer[MAX_BUF];
|
|
||||||
while(1) {
|
|
||||||
// determine if we're reading from stdin or a stream of some sort
|
|
||||||
if(file == NULL && isatty(STDIN_FILENO)) {
|
|
||||||
printf("%s", PROMPT);
|
|
||||||
fgets(buffer, MAX_BUF, stdin);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fgets(buffer, MAX_BUF, file);
|
|
||||||
printf("buffer: %s\n", buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deal with EOF input
|
|
||||||
if(!strlen(buffer)) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
exit_branch(buffer);
|
|
||||||
|
|
||||||
remove_newline(buffer);
|
|
||||||
int status = builtin_response(buffer);
|
|
||||||
// the switch in case we need to add more response flags later
|
|
||||||
switch(status) {
|
|
||||||
case RESP_ECHO:
|
|
||||||
echo(buffer);
|
|
||||||
case RESP_SHELL: // shell command handler was used
|
|
||||||
continue;
|
|
||||||
case RESP_CD_FAIL:
|
|
||||||
printf("msh: cd: No such file or directory\n");
|
|
||||||
}
|
|
||||||
memset(buffer, 0x00, MAX_BUF); // reset buffer after each usage
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void echo(const char* buf) {
|
|
||||||
printf("%s\n", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void remove_newline(char* buf) {
|
|
||||||
char* c = buf;
|
|
||||||
while(*c != '\n') { c++; }
|
|
||||||
*c='\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
void exit_branch(const char* buf) {
|
|
||||||
if(!strcmp(buf, EXIT_CMD)) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int builtin_response(char* buffer) {
|
|
||||||
#define STRING_DELIMITER " "
|
|
||||||
#define TIME_FMT "%D"
|
|
||||||
exit_branch(buffer); // exit is builtin so here we are
|
|
||||||
if(!strcmp(buffer, "help")) {
|
|
||||||
echo("enter Linux commands, or ‘exit’ to exit");
|
|
||||||
return RESP_HELP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Printout the date today
|
|
||||||
if(!strcmp(buffer, "date")) {
|
|
||||||
static char date[64];
|
|
||||||
time_t now = time(0);
|
|
||||||
strftime(date, sizeof(date), TIME_FMT, localtime(&now));
|
|
||||||
echo(date);
|
|
||||||
return RESP_DATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Populate tokens
|
|
||||||
char *tokens[64];
|
|
||||||
int idx = 0;
|
|
||||||
for(char* cur = strtok(buffer, STRING_DELIMITER); cur != NULL; cur=strtok(NULL, STRING_DELIMITER)) {
|
|
||||||
#ifdef DBG_LINE
|
|
||||||
printf("%s ", cur);
|
|
||||||
#endif
|
|
||||||
tokens[idx] = cur;
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handling director changes
|
|
||||||
int cd_result = cd_handler(tokens, idx);
|
|
||||||
if(cd_result != CD_NOP) {
|
|
||||||
return cd_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute child process
|
|
||||||
pid_t child = fork();
|
|
||||||
if(child != 0) {
|
|
||||||
int status_child = wait(NULL);
|
|
||||||
if(status_child == 127) {
|
|
||||||
printf("msh: %s: %d", tokens[0], status_child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
execvp(tokens[0], tokens);
|
|
||||||
}
|
|
||||||
// Cleanup pointers
|
|
||||||
for(int i = 0; i< 64; i++) {
|
|
||||||
tokens[i] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int cd_handler(char** tokens, const int t_count) {
|
|
||||||
if(!strcmp(tokens[0], "cd")) {
|
|
||||||
if(t_count < 2) {
|
|
||||||
int ret = chdir(getenv("HOME"));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return chdir(tokens[1]);
|
|
||||||
}
|
|
||||||
return CD_NOP;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user