From 1fdd54e80f1de18247d6fb0b0255d39a4eeb67b4 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 21 Sep 2019 12:46:59 -0700 Subject: [PATCH 1/5] binaries --- 334/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 334/.gitignore diff --git a/334/.gitignore b/334/.gitignore new file mode 100644 index 0000000..ba077a4 --- /dev/null +++ b/334/.gitignore @@ -0,0 +1 @@ +bin From a85dffe4da01edc6398edaa2757bc540de519e97 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 21 Sep 2019 12:58:31 -0700 Subject: [PATCH 2/5] msh in its own long standing directory now --- 334/Makefile | 6 ++++- 334/homework/2/msh.c | 46 ----------------------------------- 334/homework/{3 => msh}/msh.c | 0 3 files changed, 5 insertions(+), 47 deletions(-) delete mode 100644 334/homework/2/msh.c rename 334/homework/{3 => msh}/msh.c (100%) diff --git a/334/Makefile b/334/Makefile index f67c39b..54e2d8c 100644 --- a/334/Makefile +++ b/334/Makefile @@ -1,10 +1,14 @@ # Single make file for everything becauz lazy -object=hw.c +object=homework/msh/msh.c cc=gcc output=bin default: $(cc) $(object) -o $(output) +run: + ./bin + + clean: rm -f $(output) diff --git a/334/homework/2/msh.c b/334/homework/2/msh.c deleted file mode 100644 index 218efb4..0000000 --- a/334/homework/2/msh.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include - -#define PROMPT "msh> " -#define EXIT_CMD "exit" -#define MAX_BUF 121 - -void echo(const char*); -void remove_newline(char*); -void exit_branch(const char*); - -int main(void) { - char buffer[MAX_BUF]; - while(1) { - printf("%s", PROMPT); - fgets(buffer, MAX_BUF, stdin); - if(!strlen(buffer)) { - return 0; - } - // process the input - remove_newline(buffer); - exit_branch(buffer); - echo(buffer); - } - 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)) { - return; - } - exit(0); - return; // just for gcc but exit shouldn't fail -} diff --git a/334/homework/3/msh.c b/334/homework/msh/msh.c similarity index 100% rename from 334/homework/3/msh.c rename to 334/homework/msh/msh.c From c02a7905b263c78edbb84d0f4aecabb4f8512229 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 21 Sep 2019 16:10:09 -0700 Subject: [PATCH 3/5] test 4 working+ test scripts nearly setup for tracking --- 334/.gitignore | 3 +++ 334/Makefile | 2 +- 334/homework/msh/msh.c | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/334/.gitignore b/334/.gitignore index ba077a4..e8fd3f1 100644 --- a/334/.gitignore +++ b/334/.gitignore @@ -1 +1,4 @@ bin +msh +*txt +*sh diff --git a/334/Makefile b/334/Makefile index 54e2d8c..37fdc95 100644 --- a/334/Makefile +++ b/334/Makefile @@ -1,7 +1,7 @@ # Single make file for everything becauz lazy object=homework/msh/msh.c cc=gcc -output=bin +output=msh default: $(cc) $(object) -o $(output) diff --git a/334/homework/msh/msh.c b/334/homework/msh/msh.c index 73e6511..17a9acd 100644 --- a/334/homework/msh/msh.c +++ b/334/homework/msh/msh.c @@ -21,12 +21,22 @@ void remove_newline(char*); void exit_branch(const char*); int builtin_response(char*); - -int main(void) { +int main(int argc, char** argv) { + FILE* file = NULL; + if(argc == 2) { + file = fopen(argv[1], "r"); + } char buffer[MAX_BUF]; while(1) { - printf("%s", PROMPT); - fgets(buffer, MAX_BUF, stdin); + // 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); + } + // Deal with EOF input if(!strlen(buffer)) { exit(0); @@ -109,3 +119,4 @@ int builtin_response(char* buffer) { } } + From 39bfd0e7ff8a62d74494ed74c591503fb58a473e Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 21 Sep 2019 22:02:56 -0700 Subject: [PATCH 4/5] streams are broken but manual input is correct for test4 --- 334/Makefile | 2 ++ 334/homework/msh/msh.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/334/Makefile b/334/Makefile index 37fdc95..3da3348 100644 --- a/334/Makefile +++ b/334/Makefile @@ -2,6 +2,7 @@ object=homework/msh/msh.c cc=gcc output=msh +tmps=*txt default: $(cc) $(object) -o $(output) @@ -12,3 +13,4 @@ run: clean: rm -f $(output) + rm -f $(tmps) diff --git a/334/homework/msh/msh.c b/334/homework/msh/msh.c index 17a9acd..0110465 100644 --- a/334/homework/msh/msh.c +++ b/334/homework/msh/msh.c @@ -15,16 +15,23 @@ #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) { @@ -35,6 +42,7 @@ int main(int argc, char** argv) { } else { fgets(buffer, MAX_BUF, file); + printf("buffer: %s\n", buffer); } // Deal with EOF input @@ -51,6 +59,8 @@ int main(int argc, char** argv) { 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 } @@ -92,6 +102,9 @@ int builtin_response(char* buffer) { 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)) { @@ -102,6 +115,12 @@ int builtin_response(char* buffer) { 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) { @@ -120,3 +139,13 @@ int builtin_response(char* buffer) { } +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; +} From 261701be7e0e3528657475933da07d72eae7b94c Mon Sep 17 00:00:00 2001 From: shockrah Date: Sun, 22 Sep 2019 19:53:50 -0700 Subject: [PATCH 5/5] more qa things for 312 --- 312/hw/2/2.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 312/hw/2/2.md diff --git a/312/hw/2/2.md b/312/hw/2/2.md new file mode 100644 index 0000000..abc340c --- /dev/null +++ b/312/hw/2/2.md @@ -0,0 +1,59 @@ +--- +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 +``` + +