├── README.md ├── bashbunny ├── README.md └── bunny-script.md ├── cryptography ├── LICENSE ├── README.md ├── images │ ├── asymmetric.png │ ├── base64.png │ └── symmetric.png ├── module00 │ └── README.md ├── module01 │ └── README.md ├── module02 │ └── README.md ├── module03 │ └── README.md └── module04 │ └── README.md ├── python3 ├── LICENSE ├── README.md ├── module00 │ └── README.md ├── module01 │ ├── README.md │ └── m1-practice │ │ └── survey.py ├── module02 │ ├── README.md │ └── m2-practice │ │ └── animal-trivia.py ├── module03 │ ├── README.md │ └── m3-practice │ │ └── multiplication-tables.py ├── module04 │ ├── README.md │ └── m4-practice │ │ └── dog-name-generator.py ├── module05 │ ├── README.md │ └── m5-practice │ │ └── data-comparison.py ├── module06 │ ├── README.md │ └── m6-practice │ │ └── password-generator.py ├── module07 │ ├── README.md │ └── m7-practice │ │ └── encoder.py ├── module08 │ ├── README.md │ └── m8-practice │ │ ├── account-manager.py │ │ └── accounts.txt ├── module09 │ ├── README.md │ └── m9-practice │ │ └── rock-paper-scissors.py ├── module10 │ ├── README.md │ └── m10-practice │ │ └── calculator.py └── module11 │ ├── README.md │ └── m11-practice │ ├── Contact.py │ ├── __pycache__ │ └── Contact.cpython-39.pyc │ ├── contacts.txt │ └── main.py ├── usb-rubberducky ├── README.md └── ducky-syntax.md └── wifi-pineapple └── README.md /README.md: -------------------------------------------------------------------------------- 1 | # OpenCourse 2 | an open source repository of courses for people to freely learn cybersecurity and computer science topics. The free and open-sourceness of this repository ensure a privacy respecting learning experience that anyone can contribute too. enjoy 3 | - [Online Courses](https://cosmodiumcs.com/courses) 4 | 5 | happy hacking - CosmodiumCS Education Team 6 | -------------------------------------------------------------------------------- /bashbunny/README.md: -------------------------------------------------------------------------------- 1 | # Bash Bunny Book Notes 2 | > Blue Cosmo | 07/21/21 3 | --- 4 | 5 | ## Resources: 6 | notes drawn from: 7 | ``` 8 | Bash Bunny, 'A GUIDE TO HOT PLUG ATTACKS' 9 | By: Darren Kitchen, Hak5 10 | ``` 11 | 12 | ## Module 1 - The Bash Bunny 13 | - advanced USB attack platform 14 | - emulates trusted devices 15 | - gigabit ethernet 16 | - serial 17 | - flash storage 18 | - keyboards 19 | --- 20 | Switch Positions 21 | ```markdown 22 | | Postition | Mode | Location | 23 | |-----------|----------------|------------------| 24 | | 1 | Custom Payload | Closest to LED | 25 | | 2 | Custom Payload | Center | 26 | | 3 | Arming Mode | Closest to USB-A | 27 | ``` 28 | Directories 29 | - /docs - documentation 30 | - /languages - HID keyboard layouts 31 | - /loot - where payload output is stored 32 | - /tools - install additional tools 33 | - /payloads - store payloads for the respective switches 34 | - /switch1 - store custom payload for switch one 35 | - /switch2 - store custom payload for switch two 36 | - /library - payload library 37 | - /extensions - bunny script extensions 38 | 39 | Config.txt 40 | - a file where you can enable certain configurations for the bash bunny 41 | 42 | Defaults 43 | - username - *root* 44 | - password - *hak5bunny* 45 | - ip address - *172.16.64.1* 46 | 47 | LED Staus 48 | ```markdown 49 | | Led | Status | 50 | |------------------------|-------------------| 51 | | Green [blinking] | Booting | 52 | | Red [solid] | Error | 53 | | Blue [blinking] | Arming Mode | 54 | | Red/Blue [alternating] | Flashing Firmware | 55 | ``` 56 | 57 | ## Module 2 - Getting Connected: 58 | - the bash bunny has a serial console to access a linux shell 59 | - it also has ssh enabled for other remote connectivity 60 | --- 61 | Serial Settings 62 | - Baud Rate - 115200 63 | - Data Bits - 8 64 | - Parity Bit - No 65 | - Stop Bit - 1 66 | --- 67 | - Full connectivity instructions in book 68 | 69 | ## Module 3 - Bunny Script: 70 | - full syntax list in *bunny-script.md* 71 | 72 | ## Module 4 - Updates & Recovery: 73 | Updating and Recovery Methods: 74 | - BashBunny Updater [Windows, MacOS, and Linux] 75 | - BashBunny Firmware Recovery 76 | - Manual Firmware Updates 77 | 78 | ## Module 5 - Sample Payload: 79 | SMB Exfiltration - 'https://github.com/hak5/bashbunny-payloads/tree/master/payloads/library/exfiltration/smb_exfiltrator' 80 | 81 | ## Bash Bunny Mark II: 82 | - although the BashBunny MkII has most of the same features as the MkI, there are a few key differences we should notate. 83 | 84 | - payloads are ran from the bunny's internals storage [not the SD card] 85 | - -------------------------------------------------------------------------------- /bashbunny/bunny-script.md: -------------------------------------------------------------------------------- 1 | # Bunny Script 2 | > Blue Cosmo 3 | --- 4 | 5 | ## Extraneous: 6 | - the bash bunny does use *DuckyScript* [a language originally designed for the USB Rubber Ducky] as well as a other language called *BunnyScript* 7 | - communtiy payloads - 'https://github.com/hak5/bashbunny-payloads' 8 | - coupled with BASH 9 | - payloads are saved to a `payload.txt` file 10 | --- 11 | payload header 12 | ``` 13 | # Title: XXX 14 | # Description: XXX 15 | # Author: XXX 16 | # Category: XXX 17 | # Target: XXX 18 | # Attackmodes: XXX 19 | ``` 20 | 21 | ## ATTACKMODE 22 | - select emulation type 23 | 24 | ### Modes: 25 | SERIAL 26 | - enables serial console 27 | 28 | ECM_ETHERNET 29 | - enables ethernet control model [ecm] for linux, mac and android 30 | 31 | RNDIS_ETHERNET 32 | - enables remote network driver interface specification [rndis] for windows 33 | 34 | STORAGE 35 | - enables mass storage 36 | 37 | RO_STORAGE 38 | - enables read only [om] storage 39 | 40 | HID 41 | - enables keyboard mode for keystroke injection 42 | 43 | OFF 44 | - turns off emulation 45 | 46 | ### Arguments: 47 | SN_XX 48 | - set serial number to *XX* 49 | 50 | MAN_XX 51 | - set device manufacturer to *XX* 52 | 53 | VID_XX 54 | - spoof vendor ID as *XX* 55 | 56 | PID_XX 57 | - spoof product ID as *XX* 58 | 59 | ## LED 60 | change LED color 61 | 62 | ### Colors: 63 | ```markdown 64 | | COMMAND | DESCRIPTION | 65 | |---------|-------------| 66 | | R | Red | 67 | | G | Green | 68 | | B | Blue | 69 | | Y | Yellow | 70 | | C | Cyan | 71 | | M | Magenta | 72 | | W | White | 73 | ``` 74 | 75 | ### Paterns: 76 | ```markdown 77 | | PATTERN | DESCRIPTION | 78 | |----------|------------------------| 79 | | SOLID | LED turns on | 80 | | SLOW | 1000ms on/off | 81 | | FAST | 100ms on/off | 82 | | VERYFAST | 10ms on/off | 83 | | SINGLE | 1 100ms on, 1000ms off | 84 | | DOUBLE | 2 100ms on, 1000ms off | 85 | | TRIPLE | 3 100ms on, 1000ms off | 86 | | QUAD | 4 100ms on, 1000ms off | 87 | | QUIN | 5 100ms on, 1000ms off | 88 | | SUCCESS | 1000ms VERYFAST, SOLID | 89 | ``` 90 | 91 | ### LED State: 92 | ```markdown 93 | | STATE | DESCRIPTION | 94 | |------------|-----------------------------------------| 95 | | SETUP | Magenta [solid] | 96 | | FAIL[1-5] | Red [slow blink - very fast blink] | 97 | | ATTACK | Yellow [single blink] | 98 | | STAGE[1-5] | Yellow [single blink - quintuple blink] | 99 | | CLEANUP | White [fast blink] | 100 | | FINISH | Green [1000ms VERYFAST, SOLID] | 101 | ``` 102 | 103 | ## QUACK | Q 104 | run duckysrcript file or command 105 | ``` 106 | QUACK GUI r 107 | ``` 108 | 109 | ## DUCKY_LANG 110 | set keyboard language 111 | ``` 112 | DUCKY_LANG us 113 | ``` 114 | 115 | ## RUN 116 | a cross platform keystroke injection shortcut 117 | ``` 118 | RUN WIN Notepad.exe 119 | ``` 120 | 121 | ## GET 122 | obtain system variables 123 | ``` 124 | GET SWITCH_POSITION 125 | ``` 126 | - this gets the current switch position of the onboard switch of the bash bunny 127 | 128 | ## REQUIRETOOL 129 | terminates payload if tool is not found in `/tools` 130 | ``` 131 | REQUIRETOOL impacket 132 | ``` 133 | 134 | ## WAIT_FOR_PRESENT [MkII] 135 | pauses payload until a a bluetooth id is detected 136 | ``` 137 | WAIT_FOR_PRESENT XXX 138 | ``` 139 | 140 | ## WAIT_FOR_NOT_PRESENT [MkII] 141 | pauses payload until a a bluetooth id is NOT detected 142 | ``` 143 | WAIT_FOR_NOT_PRESENT XXX 144 | ``` -------------------------------------------------------------------------------- /cryptography/LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License [MODIFIED] 2 | 3 | Copyright (c) 2020, Cosmodium CyberSecurity 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | The above copyright notice and this permission notice shall be included in all 32 | copies or substantial portions of the Software. -------------------------------------------------------------------------------- /cryptography/README.md: -------------------------------------------------------------------------------- 1 | # Introduction To Cryptography 2 | 3 | ## Course Overview 4 | This course is an introductory level course that will introduce the topic of cryptography. We will go over concepts like hashing, symmetric encryption, asymmetric encryption, the caesar cipher, the vigenere cipher, and much more. This course can be officially taken at 'http://www.cosmodiumcs.com/courses/'. Officially enrolling in this course will allow you to get a certificate. You can also get quizzed on your knowledge and have easy access to this course overview. 5 | 6 | 7 | ## Module 0.0.0 - What is Cryptography? 8 | ### 0.0.1 - Course Requirements 9 | ### 0.0.2 - Bits & Bytes 10 | ### 0.0.3 - Defining Cryptography 11 | ### 0.0.4 - Cryptographic Resources 12 | ### 0.0.5 - Homework 13 | 14 | ## Module 0.1.0 - Password Hashing 15 | ### 0.1.1 - Understanding Hashes 16 | ### 0.1.2 - Storing Plaintext 17 | ### 0.1.3 - Storing Ciphertext 18 | ### 0.1.4 - Storing Hashes 19 | ### 0.1.5 - Salts 20 | ### 0.1.6 - Homework 21 | 22 | ## Module 0.2.0 - Symmetric Encryption 23 | ### 0.2.1 - Defining Symmetric Encryption 24 | ### 0.2.2 - Understanding The Caesar Cipher 25 | ### 0.2.3 - Encrypting The Caesar Cipher 26 | ### 0.2.4 - Decrypting The Caesar Cipher 27 | ### 0.2.5 - Bruteforcing The Caesar Cipher 28 | ### 0.2.6 - Advanced Encryption Standard [AES or Rijndael] 29 | ### 0.2.7 - Padding 30 | ### 0.2.8 - Homework 31 | 32 | ## Module 0.3.0 - Asymmetric Encryption 33 | ### 0.3.1 - Defining Asymmetric Encryption 34 | ### 0.3.2 - Authentication & Encryption 35 | ### 0.3.3 - Diffie-Hellman Key Exchange 36 | 37 | ## Module 0.4.0 - Other Ciphers 38 | ### 0.4.1 - Understanding The Vigenere Cipher 39 | ### 0.4.2 - Encrypting The Vigenere Cipher 40 | ### 0.4.3 - Decrypting The Vigenere Cipher 41 | ### 0.4.4 - Base64 42 | -------------------------------------------------------------------------------- /cryptography/images/asymmetric.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CosmodiumCS/OpenCourse/01a97b365a14be60b4e1e976d04169b0ff05e897/cryptography/images/asymmetric.png -------------------------------------------------------------------------------- /cryptography/images/base64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CosmodiumCS/OpenCourse/01a97b365a14be60b4e1e976d04169b0ff05e897/cryptography/images/base64.png -------------------------------------------------------------------------------- /cryptography/images/symmetric.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CosmodiumCS/OpenCourse/01a97b365a14be60b4e1e976d04169b0ff05e897/cryptography/images/symmetric.png -------------------------------------------------------------------------------- /cryptography/module00/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.0.0 - What is Cryptography? 2 | 3 | ## 0.0.1 - Course Requirements 4 | - because this course is designed for beginners, I will do my personal best to make everything clear as possible 5 | --- 6 | - Security Linux [Parrot or Kali] 7 | - Python3 Programming Language 8 | - an understanding of computer systems 9 | - Linux and BASH 10 | - algebra and high school level mathematics 11 | 12 | ## 0.0.2 - Bits & Bytes 13 | - you are already familiar with the Decimal Numeric System 14 | - a based 10 numeric system 15 | - numbers composed of 10 digits, ranging from 0-9 16 | - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 17 | - but there are other numeric systems 18 | --- 19 | - binary, a based-two, alpha-numeric system 20 | - composed of two digits: 21 | - 1, on or true 22 | - 0, off or false 23 | - a binary number is one byte, composed of 8 bits 24 | ``` 25 | Decimal : 28 26 | Binary : 00011100 27 | ``` 28 | --- 29 | Decimal --> Binary 30 | - each bit in a binary number represents a value form 0-7, being squared by two 31 | ``` 32 | /----------------------------------------\ 33 | |Decimal | 28| | | 12| 4 | 0 | | | 34 | |--------+---+---+---+---+---+---+---+---| 35 | |Binary | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 36 | |--------+---+---+---+---+---+---+---+---| 37 | |Exponet |2^7|2^6|2^5|2^4|2^3|2^2|2^1|2^0| 38 | |--------+---+---+---+---+---+---+---+---| 39 | |Value |128| 64| 32| 16| 8 | 4 | 2 | 1 | 40 | \----------------------------------------/ 41 | ``` 42 | - find the first value that can go into your decimal [from the left to your right] 43 | - place a "1" in the binary section if the value can go into the decimal 44 | - list the decimal subtracted by the value, set this as your new decimal value 45 | - rinse and repeat using your new decimal 46 | --- 47 | Binary --> Decimal 48 | - we are given this binary number `01011010` 49 | - add the values under each "1" to get the decimal form 50 | ``` 51 | /----------------------------------------\ 52 | |Decimal | | 64| | 16| 8 | | 2 | | 53 | |--------+---+---+---+---+---+---+---+---| 54 | |Binary | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 55 | |--------+---+---+---+---+---+---+---+---| 56 | |Exponet |2^7|2^6|2^5|2^4|2^3|2^2|2^1|2^0| 57 | |--------+---+---+---+---+---+---+---+---| 58 | |Value |128| 64| 32| 16| 8 | 4 | 2 | 1 | 59 | \----------------------------------------/ 60 | ``` 61 | - 64 + 16 + 8 + 2 = 90 62 | --- 63 | - bytes don't always represent numbers, they can also represent letters and symbols 64 | - some ciphers that we will learn about will encrypt data in sets of bits 65 | 66 | ## 0.0.3 - Defining Cryptography 67 | - cryptography [also reffered to as 'cryptology] is the study and practice of secure communications. 68 | - encryption is the process of turning readable information [plaintext] into unreadalbe information [ciphertext] 69 | - decryption is the process of turning ciphertext into plaintext 70 | - a cipher is the algorithm that encrypts plaintext or decrypts ciphertext using a key 71 | - a key is a secretive set of characters used for the ciphering process 72 | - block cipher, a cipher that encrypts/decrypts in blocks [or rounds] of bits 73 | - encoding is a ciphering process that doesn't use a key 74 | 75 | ## 0.0.4 - Cryptographic Resources 76 | - Course Home - 'https://www.cosmodiumcs.com/introduction-to-cryptography' 77 | - Course Overview - 'https://github.com/CosmodiumCS/Introduction-to-Cryptography' 78 | - Third Party Resources 79 | - Wikipedia - 'https://en.wikipedia.org/wiki/Cryptography' 80 | - Have Questions? 81 | - Ask at our Discord - 'https://discord.gg/E5YBNpv8hS' 82 | - Ask on our Website - 'https://www.cosmodiumcs.com/contact-information' 83 | 84 | ## 0.0.5 - Homework 85 | read this article - 'https://www.cosmodiumcs.com/post/the-story-of-rockyou' 86 | - it will be helpful for the next module 87 | -------------------------------------------------------------------------------- /cryptography/module01/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.1.0 - Password Hashing 2 | 3 | ## 0.1.1 - Understanding Hashes 4 | - when you make an account for a service, they store your passwords in one of three main ways: 5 | 1. plaintext 6 | 2. ciphertext 7 | 3. hashing 8 | 9 | ## 0.1.2 - Storing Plaintext 10 | - if you did your homework, you would understand why storing passwords in plaintext can be so dangerous. 11 | - if you didn't do the homework, the rockyou.txt file is a file holding the most common passwords on the internet, all in plaintext 12 | - in our security linux operating system, we actually have acces to the 'rockyou.txt' file 13 | - let's explore it 14 | --- 15 | run the following in your terminal: 16 | ``` 17 | cd /usr/share/wordlists/ 18 | ls 19 | ``` 20 | if you see a `rockyou.txt.gz` instead of `rockyou.txt`, run: 21 | ``` 22 | sudo gzip -d rockyou.txt.gz 23 | ``` 24 | - we can now iterate through the rockyou.txt 25 | - let's look for all the passwords containing 'tree' 26 | ``` 27 | cat rockyou.txt | grep tree 28 | ``` 29 | - you can replace 'tree' to look for any password you wish, you can even try some of your passwords to see if they are in there 30 | 31 | ## 0.1.3 - Storing Ciphertext 32 | - some services may store passwords, but encrypt/encode them before storing them 33 | - there are many methods of encryption, a lot of which we will cover next module 34 | - now encrypting passwords may seem smart, but may not be as smart as you think 35 | - this is because, if we can encrypt a password, we can decrypt a password 36 | --- 37 | - let's say we are a hacker, and we uncovered this password from a database 38 | ``` 39 | c3Vic2NyaWJl== 40 | ``` 41 | - because of the padding at the end '\=\=' we know it's [probably] a base64 encoding 42 | - we will dive into paddings and block ciphers later in the course 43 | - let's use our terminal to decrypt it 44 | ``` 45 | echo "c3Vic2NyaWJl" | base64 -d 46 | ``` 47 | 48 | ## 0.1.4 - Storing Hashes 49 | - so if plaintext is to dangerous and ciphertext can be to dangerous, how do we stroe passwords? 50 | - actually, most [secure] services don't store the passwords at all, they store hashes 51 | - hashing, the process of generating ciphertext from plaintext, using some sort of mathematical function 52 | - hashes can not be decrypted 53 | - so if services store your passwords in hashes, but you can't decrypt them, how do services know if your password is correct? 54 | - simple, when an user enters their password, it is hashed. 55 | - the hashed version of the password they entered is compared to the password stored in the database 56 | - but if we can't decrypt a hash, how do hackers figure out your password? 57 | --- 58 | - let's say we are a hacker, and we found the following hash in a database 59 | ``` 60 | f40fd562f63078722310bf105375576916ef81609331c36aa36015b4f56f9082 61 | ``` 62 | - we can obtain the plaintext password by bruteforcing using some sort of rainbow table 63 | - bruteforcing [dictionary attacks] is a password attack where an attacker iterates through a list of possible passwords, trying each one until one works 64 | - this process would obviously be automated by some sort of script or program 65 | - a rainbow table, is a bruteforce attack but each password is hashed and compared to the hashed password we obtained 66 | - now we could create our own rainbow tables or we can use rainbow tables where somebody took a every word in the english dictionary and every password in rockyou, hashed them, and stored them in a database 67 | - websites like 'https://crackstation.net/' will search it's database to see if it has a hash that matches your hash, if it finds one, it will display the plaintext it has stored with the hash 68 | - go ahead and try to see if you can figure out the plaintext version of the hash 69 | 70 | ## 0.1.5 - Salts 71 | - so if hackers found a way to break through hashes, how do websites stay protected against bruteforce attacks 72 | - introducing salts, a random string of text added to the end of a hash 73 | - it will protect against bruteforce attacks but hackers can still easily identify salts 74 | - this is the reason why it is so important to use complex passwords 75 | - the more complex the password is, the less likely it will be in a database of 'likely' passwords 76 | 77 | ## 0.1.6 - Homework 78 | - in your terminal, clone this repository to your course directory 79 | ``` 80 | git clone https://github.com/CosmodiumCS/python-caesar-cipher.git 81 | ``` 82 | - if you want to see the GitHub page for this repository, i'll have it linked here - 'https://github.com/CosmodiumCS/python-caesar-cipher.git' 83 | - we will need this code for our next module -------------------------------------------------------------------------------- /cryptography/module02/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.2.0 - Symmetric Encryption 2 | ![Symmetric Encryption](https://github.com/CosmodiumCS/Introduction-to-Cryptography/blob/main/images/symmetric.png?raw=true) 3 | 4 | ## 0.2.1 - Defining Symmetric Encryption 5 | - a ciphering algorithm that uses the same key to encrypt and decrypt plaintext 6 | - faster than asymmetric encryption 7 | - more on 'asymmetric encryption' in module 3 8 | 9 | ## 0.2.2 - Understanding The Caesar Cipher 10 | - a symmetric encryption ciphering process, that works by moving [shifitng] letters down the alphabet by a certain number [index] 11 | - it was named after Julius Caesar, who used it as a way to send messages amoungst his army 12 | - Cryptography With Java | Caesar Cipher livestream - 'https://www.youtube.com/watch?v=VLOzGG7u4x4' 13 | --- 14 | Example [shift of 1] 15 | ``` 16 | Plaintext Indexing: 17 | /-----------\ 18 | | A | B | C | 19 | |---+---+---| 20 | | 1 | 2 | 3 | 21 | \-----------/ 22 | 23 | Ciphertext Indexing: 24 | /-----------\ 25 | | B | C | D | 26 | |---+---+---| 27 | | 1 | 2 | 3 | 28 | \-----------/ 29 | 30 | plaintext = "Hello" 31 | ciphertext = "Ifmmp" 32 | 33 | Note: each character shifted over by one, that 'shift' is our encryption key 34 | ``` 35 | --- 36 | Algorithms 37 | ``` 38 | Encryption: 39 | C = (X + N) % 26 40 | 41 | Decryption: 42 | C = (X - N) % 26 43 | 44 | C = character 45 | X = index 46 | N = number of indexes we shift down [key] 47 | ``` 48 | 49 | ## 0.2.3 - Encrypting The Caesar Cipher 50 | - if you did your homework, you should have cloned the 'python-caesar-cipher' repository to your course directory 51 | - let's use this script to explore symmetric encryption concepts 52 | - in your terminal, run: 53 | ``` 54 | cd python-caesar-cipher/ 55 | echo "Hello, World!" > file.txt 56 | python3 caesar-cipher.py 57 | ``` 58 | we are now prompted to enter a file name, let's enter the 'file.txt' we created 59 | ``` 60 | Enter File Name : file.txt 61 | Choose an Option : 62 | 1) Encrypt 63 | 2) Decrypt 64 | 3) Bruteforce 65 | 4) Exit 66 | ``` 67 | - let's choose option '1' to encrypt 68 | - we are now prompted to choose an encryption key, we'll choose a key of 5 [remember that] 69 | ``` 70 | 1 71 | Shift of : 5 72 | Translating... 73 | Success! Output Written to encrypted-caesar.txt 74 | ``` 75 | let's see the contents of the encrypted text 76 | ``` 77 | cat encrypted-caesar.txt 78 | Mjqqt, Btwqi! 79 | ``` 80 | 81 | ## 0.2.4 - Decrypting The Caesar Cipher 82 | - let's decrypt our ciphertext 83 | ``` 84 | python3 caesar-cipher.py 85 | Enter File Name : encrypted-caesar.txt 86 | Choose an Option : 87 | 1) Encrypt 88 | 2) Decrypt 89 | 3) Bruteforce 90 | 4) Exit 91 | 2 92 | 93 | Shift of : 94 | ``` 95 | now because this is a symmetric encryption, it can only be decrypted with the same key used to encrypt it [in this case, the number 5] 96 | ``` 97 | Shift of : 5 98 | Translating... 99 | Success! Output Written to decrypted-caesar.txt 100 | ``` 101 | let's view the contents of our decrypted text 102 | ``` 103 | cat decrypted-caesar.txt 104 | Hello, World! 105 | ``` 106 | 107 | ## 0.2.5 - Bruteforcing The Caesar Cipher 108 | - symmetric encryption methods don't tend to be the most secure, mainly because the keys for both parties are the same 109 | - there is a special case for the Caesar Cipher that makes it especially insecure, it only has 26 possible keys 110 | - How is that possible? ['A' has an index of 1 & 'Z' has an index of 26] Because 'Z' is the last letter, there is no index higher than 26. So once 'Z' receives a shifted index of 1, it can have to recycle back to 26 because there are no other indexes. Therefore, if the shift key is 36 then the shift key is also equal to 10. 111 | - we can exploit this unuiqe feature by trying to decrypt text 26 times, using 26 different keys [each key ranging from 1 to 26] 112 | - luckily, our script will save us hours of time, and automate this process for us 113 | - to do so, we will choose option '3' 114 | ``` 115 | python3 caesar-cipher.py 116 | Enter File Name : encrypted-caesar.txt 117 | Choose an Option : 118 | 1) Encrypt 119 | 2) Decrypt 120 | 3) Bruteforce 121 | 4) Exit 122 | 3 123 | 124 | Choose an Option : 125 | 1) Bruteforce All shift Keys 126 | 2) Choose Range 127 | ``` 128 | - we are prompted to do two options 129 | - the first will bruteforce using all 26 keys 130 | - the second will brute force keys between a range you can choose [in case if the encrypted text is really large and you know that the key is between a certain range] 131 | - we will choose the first 132 | ``` 133 | 1 134 | Bruteforcing... 135 | Success! Output Written to bruteforce-all-keys.txt 136 | ``` 137 | let's read those file contents 138 | ``` 139 | ... 140 | Shift Key: 4 141 | Ifmmp, Xpsme! 142 | 143 | Shift Key: 5 144 | Hello, World! 145 | 146 | Shift Key: 6 147 | Gdkkn, Vnqkc! 148 | ... 149 | ``` 150 | - we can see that our script tried 26 different keys, and the fifth one showed us the plaintext contents 151 | --- 152 | Fun fact, ROT13 [ROTation 13] is a cipher the exact same as the caesar cipher, but the key is always 13 153 | 154 | ## 0.2.6 - Advanced Encryption Standard [AES or Rijndael] 155 | - a symmetric block cipher that encrypts/decrypts blocks of 128 bits using keys sized at 128, 192, or 256 156 | - this encryption method is [currently] the only publically available encryption method used by the U.S Government 157 | - it is allowed for the use of encrypting classified data 158 | - one of the most memory effecient ciphers [on a hardware and software level] 159 | - the encryption rounds of the AES block cipher will vary depending on it's key bit size 160 | ``` 161 | 128 bit keys --> 10 rounds 162 | 192 bit keys --> 12 rounds 163 | 256 bit keys --> 14 rounds 164 | ``` 165 | - this will be about as far as we dive into AES, but here is a link to learn more about this topic - 'https://en.wikipedia.org/wiki/Advanced_Encryption_Standard' 166 | - we can use this website to encrypt data using AES-256 167 | - 'https://encode-decode.com/aes256-encrypt-online/' 168 | - try different passwords [keys] to makeyour ciphertext stronger 169 | 170 | ## 0.2.7 - Padding 171 | - because the encryption works in blocks of 128 bits, the ciphertext will often end with a '\=\=' padding 172 | - Why? let's say our plaintext is 150 bits. after we encrypt our first block of 128 bits, there are only 22 bits left. We need another 106 bits of data in order to meet the quota of 128 bits. Once fulfilled, the cipher can finish properly. This data added to the end is the padding. 173 | 174 | ## 0.2.8 - Homework 175 | read this article on RSA, a type of asymmetric encryption 176 | - 'https://hackernoon.com/how-does-rsa-work-f44918df914b' 177 | -------------------------------------------------------------------------------- /cryptography/module03/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.3.0 - Asymmetric Encryption 2 | ![Asymmetric Encryption](https://github.com/CosmodiumCS/Introduction-to-Cryptography/blob/main/images/asymmetric.png?raw=true) 3 | 4 | ## 0.3.1 - Defining Asymmetric Encryption 5 | - a ciphering algorithm that uses a key for encryption [public key] and a key for decryption [private key] 6 | - asymmetric encryption is often reffered to as public key encryption 7 | - it is more secure than symmetric encryption 8 | - more on 'symmetric encryption' in module 2 9 | - private keys are only available to the owner, while public keys are "publicly available" 10 | - as in available to whoever the owner shares them to 11 | 12 | ## 0.3.2 - Authentication & Encryption 13 | - similar to symmetric encryption, asymmetric encryption allows for end to end encryption 14 | - however, it also allows for authentication 15 | - the cipher's public key can assure that a user with the private key sent the encrypted message or file 16 | 17 | ## 0.3.3 - Diffie-Hellman Key Exchange 18 | - created by Dr. Whitfield Diffie and Dr. Martin Hellman 19 | - allows for the generation and exhange of asymmetric keys 20 | --- 21 | How It Works 22 | 1. John and Jane both pick two whole numbers 23 | - both must be larger than one, Jane's must be larger than John's 24 | - the larger the number, the more secure [but more processing memory] 25 | ``` 26 | 1 < JohnsInteger < JanesInteger 27 | ``` 28 | 2. John and Jane run both pick two random numbers and run it through the following equation 29 | - '\*\*' = to the power of 30 | - '%' = the remainder of 31 | ``` 32 | JohnsResult = JohnsInteger ** JohnsRandomInt % JanesInteger 33 | JanesResult = JohnsInteger ** JanesRadnomInt % JanesInteger 34 | ``` 35 | 3. John and Jane send their respective results to each other. with these results, they will generate their keys 36 | ``` 37 | JohnsKey = JanesResult ** JohnsRandomInt % JanesInteger 38 | JanesKey = JohnsResult ** JanesRandomInt % JanesInteger 39 | ``` 40 | -------------------------------------------------------------------------------- /cryptography/module04/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.4.0 - Other Ciphers 2 | 3 | ## 0.4.1 - Understanding The Vigenere Cipher 4 | - invented by Giovan Battista Bellaso in 1553 5 | - a more advance version was published by Blaise de Vigenere 6 | - also called the 'Polyalphabetic cipher' 7 | - let's learn how it works 8 | --- 9 | we start with our indexing chart, a little different than the one for the caesar cipher 10 | ``` 11 | Indexing: 12 | /---------------------------------------------------\ 13 | | A | B | C | D | E | F | G | H | I | J | K | L | M | 14 | |---+---+---+---+---+---+---+---+---+---+---+---+---| 15 | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 16 | |---+---+---+---+---+---+---+---+---+---+---+---+---| 17 | | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | 18 | |---+---+---+---+---+---+---+---+---+---+---+---+---| 19 | | 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 20 | \---------------------------------------------------/ 21 | ``` 22 | for this example, we will be using "KEY" as our key 23 | - our key has the following indexes [these will be important] 24 | ``` 25 | /-----------\ 26 | | K | E | Y | 27 | |---+---+---| 28 | | 10| 4 | 24| 29 | \-----------/ 30 | ``` 31 | 32 | ## 0.4.2 - Encrypting The Vigenere Cipher 33 | - now we can start to encrypt some plaintext, we will choose the text "ENCRYPT" 34 | - we must first find the indexes of the plaintext's characters 35 | ``` 36 | /---------------------------\ 37 | | E | N | C | R | Y | P | T | 38 | |---+---+---+---+---+---+---| 39 | | 4 | 13| 2 | 17| 24| 15| 19| 40 | \---------------------------/ 41 | ``` 42 | we can now comibne them to the respective index's of our key 43 | ``` 44 | /---------------------------\ 45 | | E | N | C | R | Y | P | T | <-- PLAINTEXT 46 | |---+---+---+---+---+---+---| 47 | | 4 | 13| 2 | 17| 24| 15| 19| <-- PLAINTEXT INDEXES 48 | |---+---+---+---+---+---+---| 49 | |+10| +4|+24|+10| +4|+24|+10| <-- KEY 50 | |---+---+---+---+---+---+---| 51 | | 14| 17| 0 | 1 | 2 | 13| 3 | <-- CIPHERTEXT INDEXES 52 | |---+---+---+---+---+---+---| 53 | | O | R | A | B | C | N | D | <-- CIPHERTEXT 54 | \---------------------------/ 55 | ``` 56 | 57 | ## 0.4.3 - Decrypting The Vigenere Cipher 58 | now we can just reverse the process by subtracting the key values from the plaintext 59 | ``` 60 | /---------------------------\ 61 | | O | R | A | B | C | N | D | <-- CIPHERTEXT 62 | |---+---+---+---+---+---+---| 63 | | 14| 17| 0 | 1 | 2 | 13| 3 | <-- CIPHERTEXT INDEXES 64 | |---+---+---+---+---+---+---| 65 | |-10| -4|-24|-10| -4|-24|-10| <-- KEY 66 | |---+---+---+---+---+---+---| 67 | | 4 | 13| 2 | 17| 24| 15| 19| <-- PLAINTEXT INDEXES 68 | |---+---+---+---+---+---+---| 69 | | E | N | C | R | Y | P | T | <-- PLAINTEXT 70 | \---------------------------/ 71 | ``` 72 | 73 | ## 0.4.4 - Base64 74 | - a ciphering process that uses binary data to encode text 75 | - each digit is composed of 6 bits [rather than the 8 bit binary digits] 76 | - this means that four Base64 digits is equal to three binary numbers 77 | - because of this, we may need a padding at the end of our Base64 string 78 | --- 79 | ![Base64 Table](https://github.com/CosmodiumCS/Introduction-to-Cryptography/blob/main/images/base64.png?raw=true) 80 | - full credit to Wikipedia - 'https://en.wikipedia.org/wiki/Base64' for the table 81 | --- 82 | - you can see how each respective number [binary or decimal] represents the index of an uppercase letter, then a lowercase letter, then a number, and finally a symbol 83 | - this order of characters is part of ASCII [American Standard Code for Information Interchange] 84 | - it is the national standard that all encoding process's follow in America 85 | -------------------------------------------------------------------------------- /python3/LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License [MODIFIED] 2 | 3 | Copyright (c) 2020, Cosmodium CyberSecurity 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | The above copyright notice and this permission notice shall be included in all 32 | copies or substantial portions of the Software. -------------------------------------------------------------------------------- /python3/README.md: -------------------------------------------------------------------------------- 1 | # Introduction to Python3 Course [IP3] 2 | > A Course by Chris Taylor [BLUE C0SM0], powered by CosmodiumCS 3 | 4 | ## Course Overview 5 | This course will take you from knowing nothing to knowing Python at an intermediate level. The course can be taken at 'https://www.cosmodiumcs.com/courses/' . Officially enrolling in this course will allow you to get a certificate. You can also get quizzed on your knowledge and have easy access to this cousse overview. 6 | 7 | ## Module 0.0.0 - Installation & Setup 8 | ### 0.0.1 - Online Option 9 | ### 0.0.2 - Installing Python3 on Windows 10 & MacOS 10 | ### 0.0.3 - Installing Python3 on Linux 11 | ### 0.0.4 - Writing Python3 Code 12 | ### 0.0.5 - Running Python 13 | ### 0.0.6 - Python3 Resources 14 | 15 | ## Module 0.1.0 - Fundamentals 16 | ### 0.1.1 - Datatypes 17 | ### 0.1.2 - Comments 18 | ### 0.1.3 - Errors 19 | ### 0.1.4 - Strings & Output 20 | ### 0.1.5 - Operators 21 | ### 0.1.6 - Operations with Strings 22 | ### 0.1.7 - Converting Datatypes 23 | ### 0.1.8 - Variables 24 | ### 0.1.9 - Variable Operations 25 | ### 0.1.10 - Input 26 | ### 0.1.11 - String Formatting 27 | 28 | ## Module 0.2.0 - Booleans & Conditionals 29 | ### 0.2.1 - Boolean Values 30 | ### 0.2.2 - Boolean Operators 31 | ### 0.2.3 - If Statement 32 | ### 0.2.4 - Else Statement 33 | ### 0.2.5 - Elif [Else if] Statement 34 | ### 0.2.6 - Boolean Logic 35 | ### 0.2.7 - Ternary Operator 36 | ### 0.2.8 - Helpful Boolean Syntax 37 | 38 | ## Module 0.3.0 - Loops & Iteration 39 | ### 0.3.1 - While Loops 40 | ### 0.3.2 - Range 41 | ### 0.3.3 - For Loops 42 | ### 0.3.4 - Looping With Conditionals 43 | 44 | ## Module 0.4.0 - Data Structures & Lists 45 | ### 0.4.1 - Initializing Lists 46 | ### 0.4.2 - List Functions & Methods 47 | ### 0.4.3 - Boolean Operations With Lists 48 | ### 0.4.4 - List Slicing 49 | ### 0.4.5 - List Comprehension 50 | 51 | ## Module 0.5.0 - Dictionaries, Tuples, Sets 52 | ### 0.5.1 - Dictionaries 53 | ### 0.5.2 - Tuples 54 | ### 0.5.3 - Sets 55 | ### 0.5.4 - Set Operators 56 | ### 0.5.5 - Iterable Unpacking 57 | 58 | ## Module 0.6.0 - Working With Modules 59 | ### 0.6.1 - Importing Modules 60 | ### 0.6.2 - The Zen of Python 61 | ### 0.6.3 - Random Module 62 | ### 0.6.4 - Python Package Index [PYPI] 63 | 64 | ## Module 0.7.0 - Working With Methods 65 | ### 0.7.1 - String Methods 66 | ### 0.7.2 - Numeric Functions 67 | ### 0.7.3 - Iterable Functions 68 | 69 | ## Module 0.8.0 - File Handling 70 | ### 0.8.1 - Opening Files 71 | ### 0.8.2 - Opening File Arguments 72 | ### 0.8.3 - Closing Files 73 | ### 0.8.4 - Reading Files 74 | ### 0.8.5 - Writing Files 75 | ### 0.8.6 - Appending Files 76 | ### 0.8.7 - With Statement 77 | 78 | ## Module 0.9.0 - Exception Handling 79 | ### 0.9.1 - Error Types 80 | ### 0.9.2 - Try & Except Statements 81 | ### 0.9.3 - Raise 82 | ### 0.9.4 - Finally 83 | ### 0.9.5 - Assertion 84 | ### 0.9.6 - Handling Exceptions With Conditionals 85 | ### 0.9.7 - Helpful Summary 86 | 87 | ## Module 0.10.0 - Functional Programming 88 | ### 0.10.1 - Defining and Calling Functions 89 | ### 0.10.2 - Working With Arguments 90 | ### 0.10.3 - Returning Data 91 | ### 0.10.4 - Higher-Order Functions 92 | ### 0.10.5 - Special Arguments 93 | ### 0.10.6 - \_\_main\_\_ 94 | ### 0.10.7 - Mapping and Filtering 95 | ### 0.10.8 - Lambda 96 | 97 | ## Module 0.11.0 - Object Oriented Programming 98 | ### 0.11.1 - Class's Put Into Context 99 | ### 0.11.2 - Creating A Class 100 | ### 0.11.3 - Adding Behaviors 101 | ### 0.11.4 - Inheritance 102 | ### 0.11.5 - More Advanced Topics 103 | -------------------------------------------------------------------------------- /python3/module00/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.0.0 - Installation & Setup 2 | - how to install or use python 3 | 4 | ## 0.0.1 - Online Option 5 | - if you don't want to install Python onto your computer, there are plenty of online options that you can choose 6 | - the one I recommend most is Replit 'https://replit.com/~' 7 | - fun fact, REPL stands for Read Evaluate Print and Loop 8 | - so REPL it is saying Read Evaluate Print and Loop it 9 | --- 10 | - make an account 11 | - to make a python prject, hit the `+ New Repl` button on the top left 12 | - choose `Python` 13 | - I suggest navigating to `My repls` 14 | - click the `+ New folder` button 15 | - name the folder `introductionToPython3` [or something along those lines] 16 | - here you can store your projects and practices form this course 17 | 18 | ## 0.0.2 - Installing Python3 on Windows 10 & MacOS 19 | - navigate to 'https://www.python.org/downloads/' 20 | - click the download button and run the file 21 | - follow the instructions shown on the wizard 22 | 23 | ## 0.0.3 - Installing Python3 on Linux 24 | - open a terminal and run: 25 | ``` 26 | sudo apt-get install python3 27 | ``` 28 | 29 | ## 0.0.4 - Writing Python3 Code 30 | python can be written in two diffent enviorments 31 | 32 | 1. Python Shell 33 | - a python module runs each line of syntax after it is written 34 | - good for tutorials, testing, and light programming 35 | - can be opened by running the following in a powershell, command line, or terminal 36 | ``` 37 | python3 38 | ``` 39 | > Note: Windows has an app for the Python3 Module [if installed via the 0.0.2 instructions] 40 | 41 | 2. IDE or Text Editor 42 | - an IDE [Integrated Developer Enviorment] or Text Editor is a peice of software used to write, run, and often debug code 43 | - in this course we will ue the `Python IDLE` application that came with our Python installation 44 | - if you didn't get the IDLE application, you can use your default text editor or install Atom: 'https://atom.io/' 45 | - default text editors 46 | ``` 47 | Windows: Notepad 48 | MacOS: TextEdit 49 | Linux: Text Editor 50 | ``` 51 | 52 | ## 0.0.5 - Running Python 53 | - Python files use the extension `.py` 54 | - to run them, we can either use an IDE/Text Editor that has running features enabled 55 | - or we can open our respective command line [in the directory of the file] and run 56 | ``` 57 | python3 FILENAME.py 58 | ``` 59 | 'FILENAME' represents the name of the file 60 | 61 | ## 0.0.6 - Python3 Resources 62 | - Course Home - 'https://www.cosmodiumcs.com/introduction-to-python3/' 63 | - Course Overview - 'https://github.com/CosmodiumCS/Introduction-to-Python3' 64 | - Documentation - 'https://docs.python.org/3/contents.html' 65 | - Third Party Resources 66 | - W3Schools - 'https://www.w3schools.com/python/python_reference.asp' 67 | - Principals - 'https://pythonprinciples.com/reference/' 68 | - Have questions? 69 | - Ask at our Discord - 'https://discord.gg/E5YBNpv8hS' 70 | - Ask on our Website - 'https://www.cosmodiumcs.com/contact-information' 71 | -------------------------------------------------------------------------------- /python3/module01/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.1.0 - Fundamentals 2 | - python is case sensitive 3 | 4 | ## 0.1.1 - Datatypes 5 | - There are different data types for handling the different types of data 6 | - string - datatype for text values 7 | - integer - datatype for whole number values 8 | - float - datatype for decimal values 9 | - boolean - datatype for true or false values 10 | 11 | ## 0.1.2 - Comments 12 | - comments can be used to make notes or comments in your code 13 | - comments are not executed by the interpreter 14 | ``` 15 | # this is a comment 16 | ``` 17 | 18 | ## 0.1.3 - Errors 19 | if your code is outputting something like this 20 | ``` 21 | Traceback (most recent call last): 22 | File "", line 1, in 23 | ... 24 | NameError: name '' is not defined 25 | ... 26 | ``` 27 | - then there is an error in your code, the last line tells you what's wrong 28 | - we will go over errors and exceptions in module 0.9.0 29 | - exception, handling an error in your code 30 | - but you probably typed something wrong or you tried to make your syntax [code in text form] do something that it can't 31 | 32 | ## 0.1.4 - Strings & Output 33 | - single or double quotes can be used to represent strings 34 | - the "print" function can be used to output datatypes 35 | - function, a statement that [typically] takes an input [argument], uses that input to perform an operation, and will return some output. 36 | ```python 37 | 38 | print('Hello, World!') 39 | print("Hello, World!") 40 | 41 | # to include quotes within strings 42 | 43 | print('My name is "Cosmo"') 44 | print("I can't code well") 45 | ``` 46 | - the above can also be done with something called escape sequences 47 | - escape sequences are strings that use specialized character to achieve a certain task 48 | - they use a backslash to innitiate 49 | ``` 50 | \" - double quote escape sequence 51 | \' - single quote escape sequence 52 | \n - new line escape sequence 53 | \t - tab escape sequence 54 | \\ - backslash escape sequence 55 | ``` 56 | Example: 57 | ``` 58 | print("My name is \"Cosmo\"") 59 | >>> My name is "Cosmo" 60 | ``` 61 | Docstrings, multilined strings 62 | - created by putting string text between three double quotes 63 | ``` 64 | "This srtring is one line" 65 | 66 | """ 67 | This string has multiple lines 68 | first line 69 | second line 70 | """ 71 | ``` 72 | 73 | ## 0.1.5 - Operators 74 | Keep order of operations (PEMDAS) in mind 75 | ```python 76 | # addition 77 | print(1+1) 78 | 79 | # subtraction 80 | print(1 - 1) 81 | 82 | # multiplication 83 | print(1*1) 84 | 85 | # division 86 | print(1/1) 87 | 88 | # exponets 89 | print(1**1) 90 | 91 | # remainders 92 | print(1%1) 93 | 94 | # quotiants 95 | print(1//1) 96 | ``` 97 | 98 | ## 0.1.6 - Operations with Strings 99 | Concatenation, connecting two or more datatypes in one value 100 | ``` 101 | print("Hello, " + "World!"") 102 | >>> "Hello, World!"" 103 | ``` 104 | if a string is multiplied by a numeric value, it will append it's value to itself (however many times as instructed) 105 | ``` 106 | print("Hello"*3) 107 | >>> "HelloHelloHello" 108 | ``` 109 | 110 | ## 0.1.7 - Converting Datatypes 111 | ``` 112 | String - str() 113 | Integer - int() 114 | Float - float() 115 | ``` 116 | Example: 117 | ``` 118 | print("1"+"1") 119 | >>> "11" 120 | 121 | print(int("1")+int("1")) 122 | >>> 2 123 | ``` 124 | 125 | ## 0.1.8 - Variables 126 | assign data to a name of your choice 127 | - acheived through assignment operator, "=" 128 | - can't start with a number 129 | - use underscores instead of a space 130 | ``` 131 | my_varaible = 5 132 | print(my_variable) 133 | >>> 5 134 | ``` 135 | variables can be reassigned 136 | ``` 137 | my_variable = "Subscribe to CosmodiumCS" 138 | print(my_variable) 139 | >>> "Subscribe to CosmodiumCS" 140 | ``` 141 | variables can be deleted with the "del" command 142 | ``` 143 | del my_variable 144 | ``` 145 | 146 | ## 0.1.9 - Variable Operations 147 | ``` 148 | # assignment operator 149 | x = 5 150 | 151 | # add on to saved data 152 | x = x + 1 153 | # or 154 | x += 1 155 | 156 | # works with other datatypes 157 | full_name = "Blue " 158 | full_name += "Cosmo" 159 | print(full_name) 160 | >>> "Blue Cosmo" 161 | 162 | # works with other operators 163 | x = x - 1 164 | # or 165 | x -= 1 166 | 167 | # others 168 | x /= 2 169 | x *= 2 170 | ``` 171 | 172 | ## 0.1.10 - Input 173 | get user input using the "input" function 174 | ``` 175 | input("What is your name? : ") 176 | >>> What is your name? : cosmo 177 | ``` 178 | let's save this input to a variable and output it 179 | ``` 180 | name = input("What is your name? : ") 181 | >>> What is your name? : cosmo 182 | 183 | print("Your name is " + name) 184 | >>> "Your name is cosmo" 185 | ``` 186 | 187 | ## 0.1.11 - String Formatting 188 | embed other data within a string 189 | - accomplished by using the "format" method 190 | - curly braces "{}" are replaced by the formatted data [seperated by commas] 191 | ``` 192 | formatted_string = "Cosmodium's birthday is on June {}, {}".format(9, 2020) 193 | print(formatted_string) 194 | >>> "Cosmodium's birthday is on June 9, 2020" 195 | ``` 196 | values can be assigned to the formatted data using their index's 197 | - an index is the placement or position of a character in a set of data 198 | ``` 199 | age = 100 200 | 201 | msg = "I am {0} years {1}, how {1} are you".format(age, "old") 202 | print(msg) 203 | >>> "I am 100 years old, how old are you" 204 | ``` 205 | "F" strings are a shortcut for formatting 206 | - indicated by placing an "f" before the single or double quotes of the string 207 | - formatted data is placed directly in the curly braces "{}" 208 | ``` 209 | name = "bob" 210 | age = 30 211 | 212 | print(f"My name is {name} and I am {age} years old") 213 | >>> "My name is bob and I am 30 years old" 214 | ``` 215 | this formatted data can be operations, variables, integers, and more 216 | -------------------------------------------------------------------------------- /python3/module01/m1-practice/survey.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will create a program that will ask a user questions 3 | # and output the information they entered 4 | 5 | # created by : C0SM0 6 | 7 | # banner 8 | print("Survey:") 9 | 10 | # user input, first name 11 | first_name = input("What is your first name? : ") 12 | # user inpur, last name 13 | last_name = input("What is your last name? : ") 14 | # user input, age 15 | age = input("How old are you? : ") 16 | # user input, favorite color 17 | favorite_color = input("What is your favorite color? : ") 18 | 19 | # full name 20 | full_name = first_name +" "+ last_name 21 | 22 | # results 23 | print(f"Here are your results, {first_name}:") 24 | print(f"- Your name is \"{full_name}\"") 25 | print(f"- You are {age} years old") 26 | print(f"- Your favorite color is {favorite_color}") 27 | 28 | # feel free to keep practicing, here are some more ideas 29 | """ 30 | - minimal account creator 31 | - add/subtract/multiply/divide user inputted values together 32 | """ -------------------------------------------------------------------------------- /python3/module02/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.2.0 - Booleans & Conditionals 2 | - learn about the boolean datatype 3 | - how to run code based on certain conditions 4 | 5 | ## 0.2.1 - Boolean Values 6 | ``` 7 | True - value exists and is correct 8 | False - value doesn't exist and is wrong 9 | None - value is absent 10 | ``` 11 | 12 | ## 0.2.2 - Boolean Operators 13 | ``` 14 | == - equal to 15 | != - not equal to 16 | < - less than 17 | > - greater than 18 | <= - less than or equal to 19 | >= - greater than or equal to 20 | ``` 21 | Example: 22 | ``` 23 | print(True == True) 24 | >>> True 25 | 26 | print(True == False) 27 | >>> False 28 | 29 | print(1 == 2) 30 | >>> False 31 | 32 | print(5 <= 10) 33 | >>> True 34 | ``` 35 | 36 | ## 0.2.3 - If Statement 37 | - runs expression[s] if a condition is true 38 | - code that runs if a condition is true[expression] is tabbed under the conditonal 39 | - this area of tabbed code is the scope 40 | ``` 41 | if 5 < 10: 42 | print("5 is less than 10") 43 | print("not part of the if statement") 44 | 45 | >>> "5 is less than 10" 46 | >>> "not part of the if statement" 47 | ``` 48 | "if" statements can be nested 49 | ``` 50 | number = 25 51 | 52 | if number < 50: 53 | print("the number is less than 50") 54 | 55 | if number > 20: 56 | print("number is greater than 20 and less than 50") 57 | 58 | >>> "the number is less than 50" 59 | >>> "number is greater than 20 and less than 50" 60 | ``` 61 | 62 | ## 0.2.4 - Else Statement 63 | runs code if the aforementioned "if" statement is false 64 | ``` 65 | password = "SecurePassord" 66 | 67 | if password == "SecurePassord": 68 | print("password is true") 69 | 70 | else: 71 | print("Password is false") 72 | 73 | >>> "password is true" 74 | ``` 75 | 76 | ## 0.2.5 - Elif [Else if] Statement 77 | a chain of "if" "else" statements 78 | ``` 79 | number = 2 80 | 81 | if number == 1: 82 | print(1) 83 | else: 84 | if number == 2: 85 | print(2) 86 | else: 87 | if number == 3: 88 | print(3) 89 | else: 90 | None 91 | 92 | >>> 2 93 | ``` 94 | "elif" statement, a shortcut for connecting mulitiple "if" "else" statements 95 | ``` 96 | number = 2 97 | 98 | if number == 1: 99 | print(1) 100 | elif number == 2: 101 | print(2) 102 | else: 103 | None 104 | 105 | >>> 2 106 | ``` 107 | 108 | ## 0.2.6 - Boolean Logic 109 | runs code if multiple conditions are true 110 | - boolean operations follow the mathematical "Order of Operations" [PEMDAS] 111 | 112 | 1. and 113 | the "and" operator takes two arguments, if both are true it will return as true 114 | ``` 115 | print(True and True) 116 | >>> True 117 | 118 | print(True and False) 119 | >>> False 120 | 121 | print(False and False) 122 | >>> True 123 | ``` 124 | 125 | 2. or 126 | the "or" operator takes two arguments, if one or both are true it will return as true 127 | ``` 128 | print(True or True) 129 | >>> True 130 | 131 | print(True or False) 132 | >>> True 133 | 134 | print(False or False) 135 | >>> False 136 | ``` 137 | 138 | 3. not 139 | the "not" operator takes one argument and inverts its boolean value 140 | ``` 141 | print(not True) 142 | >>> False 143 | 144 | print(not False) 145 | >>> True 146 | ``` 147 | 148 | 4. in 149 | the "in" operator takes two arguments, if the first argument exists in the second argument, it will return as true 150 | ``` 151 | print("a" in "apple") 152 | >>> True 153 | ``` 154 | 155 | ## 0.2.7 - Ternary Operator 156 | create value based on a rule or condition 157 | ``` 158 | age = 15 159 | movieRating = 13 160 | 161 | canWatchMovie = True if age >= movieRating else False 162 | print(canWatchMovie) 163 | >>> True 164 | ``` 165 | 166 | ## 0.2.8 - Helpful Boolean Syntax 167 | ``` 168 | # Test if a number is positive 169 | number > 0 170 | 171 | # Test if a number is negative 172 | number < 0 173 | 174 | # Test if a number is even by seeing if the remainder is 0 when divided by 2 175 | number % 2 == 0 176 | 177 | # Test if a number is odd by seeing if there is a remainder when divided by 2 178 | number % 2 > 0 179 | 180 | # Test if a number is a multiple of x (or divisible by x with no remainder) 181 | number % x == 0 182 | ``` -------------------------------------------------------------------------------- /python3/module02/m2-practice/animal-trivia.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will make a quiz about animal 3 | 4 | # created by : C0SM0 5 | 6 | # banner 7 | print("Animal Quiz") 8 | 9 | # question 1, q1 10 | print("Question 1:") 11 | q1 = input("Whales breathe air\n1) True\n2) False\n\nAnswer : ") 12 | # checks to see if answer is correct 13 | if q1 == "1": 14 | print("Correct!\n") 15 | # checks to see if answer is incorrect 16 | elif q1 == "2": 17 | print("Incorrect!\n") 18 | # outputs message if an invalid answer was chosen 19 | else: 20 | print("Input not recognized\n") 21 | 22 | # question 2, q2 23 | print("Question 2:") 24 | q2 = input("Which of the following are land animals\n1) dolphin\n2) fish\n3) tiger\n\nAnswer : ") 25 | # checks to see if answer is correct 26 | if q2 == "3": 27 | print("Correct!\n") 28 | # checks to see if answer is incorrect 29 | elif q2 == "1" or q2 == "2": 30 | print("Incorrect!\n") 31 | # outputs message if an invalid answer was chosen 32 | else: 33 | print("Input not recognized\n") 34 | 35 | # question 3, q3 36 | print("Question 3:") 37 | q3 = input("Select all of the carnivors\n1) t-rex\n2) velociraptor\n3) bunny\n\nAnswer : ") 38 | # checks to see if answer is correct 39 | if ("1" in q3 and "2" in q3) and ("3" not in q3): 40 | print("Correct!\n") 41 | # checks to see if answer is incorrect 42 | elif "3" in q3: 43 | print("Incorrect!\n") 44 | # checks to see if answer is incorrect 45 | elif ("2" in q3) and ("1" not in q3): 46 | print("Incorrect!\n") 47 | # checks to see if answer is incorrect 48 | elif ("1" in q3) and ("2" not in q3): 49 | print("Incorrect!\n") 50 | # outputs message if an invalid answer was chosen 51 | else: 52 | print("Input not recognized\n") 53 | 54 | # now this code works but is not effecient 55 | # it is repeating the same steps over and over again 56 | # in the next module, we will learn about loops, to shorten process's like this 57 | # consider coming back and shrotening this code with loops 58 | 59 | # feel free to keep practicing, here are some more ideas 60 | """ 61 | - password authenticator 62 | - suggest movies to a user based on their age 63 | """ -------------------------------------------------------------------------------- /python3/module03/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.3.0 - Loops & Iteration 2 | - loops, run a set of code multiple times 3 | - an iteration is each time a loop reruns 4 | 5 | ## 0.3.1 - While Loops 6 | evaluates code "as long as" a condition is true, if fasle, loop will end [break] 7 | ``` 8 | i = 0 9 | 10 | while i <= 5: 11 | i += 1 12 | print(i) 13 | 14 | print("loop has ended") 15 | 16 | >>> 1 17 | >>> 2 18 | >>> 3 19 | >>> 4 20 | >>> 5 21 | >>> "loop has ended" 22 | ``` 23 | loops can be infinite 24 | ``` 25 | while True: 26 | print("This will not stop running") 27 | ``` 28 | - to end a program from running, enter `ctrl` + `c` 29 | - "break" statement ends loops 30 | ``` 31 | i = 0 32 | 33 | while i <= 5: 34 | i += 1 35 | print(i) 36 | 37 | if i == 3: 38 | print("ending loop") 39 | break 40 | 41 | print("loop has ended") 42 | 43 | >>> 1 44 | >>> 2 45 | >>> 3 46 | >>> "ending loop" 47 | >>> "loop has ended" 48 | ``` 49 | "continue" statement, cancels current iteration and meves to the next one 50 | ``` 51 | i = 0 52 | 53 | while i <= 10: 54 | i += 1 55 | print(i) 56 | 57 | if i == 5: 58 | print("halfway there") 59 | continue 60 | 61 | >>> 1 62 | >>> 2 63 | >>> 3 64 | >>> 4 65 | >>> 5 66 | >>> "halfway there" 67 | >>> 6 68 | >>> 7 69 | >>> 8 70 | >>> 9 71 | >>> 10 72 | >>> 11 73 | ``` 74 | 75 | ## 0.3.2 - Range 76 | a function that creates a sequence of numbers 77 | - the first argument is the start, leave blank to start from 0 78 | - the second argument is the end 79 | - the third argument is the interval, leave blank for no interval 80 | ``` 81 | num_list = list(range(10)) 82 | print(num_list) 83 | >>> [0, 1, 2, 3, 4, 5, 6 ,7, 8, 9] 84 | ``` 85 | - list function, creates a list [a type of data structure] using an argument 86 | - remember, indexing starts from 0. so this list will have 10 values but will only go up to 9 87 | - removing the list function will make the variable an object, good for iteration 88 | ``` 89 | print(list(range(1, 16))) 90 | >>> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] 91 | ``` 92 | listed range with an iterval of 2 93 | ``` 94 | even_nums_lessThan_10 = list(range(0,11,2)) 95 | print(even_nums_lessThan_10) 96 | >>> [0, 2, 4, 6, 8, 10] 97 | ``` 98 | 99 | ## 0.3.3 - For Loops 100 | - iterating through a set of data is excessive with "while" loops 101 | - "for" loops evaluates code "for each" item in a certain set of data 102 | ``` 103 | for i in range(5): 104 | print("hello") 105 | 106 | print("loop has ended") 107 | 108 | >>> "hello" 109 | >>> "hello" 110 | >>> "hello" 111 | >>> "hello" 112 | >>> "hello" 113 | >>> "loop has ended" 114 | ``` 115 | break and continue statements also work with for loops 116 | 117 | ## 0.3.4 - Looping With Conditionals 118 | - the "else" statement can also be used with loops. 119 | - it will run it's segmented code if the loop before it runs sucessfully 120 | ``` 121 | for i in range(5): 122 | print("hello") 123 | 124 | if i == 7: 125 | break 126 | 127 | print("loop has ended") 128 | 129 | else: 130 | print("loop ran sucessfully") 131 | 132 | >>> "hello" 133 | >>> "hello" 134 | >>> "hello" 135 | >>> "hello" 136 | >>> "hello" 137 | >>> "loop has ended" 138 | >>> "loop ran sucessfully" 139 | ``` 140 | -------------------------------------------------------------------------------- /python3/module03/m3-practice/multiplication-tables.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will make a program that will generate multiplication tables 3 | 4 | # created by : C0SM0 5 | 6 | # variables 7 | range_limit = range(1, 13) 8 | 9 | # iterate through each table 10 | for table_number in range_limit: 11 | 12 | # banner 13 | print(f"\nMultiplication Table for {table_number}:") 14 | 15 | # iterate through each multiple 16 | for multiple in range_limit: 17 | answer = table_number * multiple 18 | print(f"{table_number} x {multiple} = {answer}") 19 | 20 | # feel free to keep practicing, here are some more ideas 21 | """ 22 | - multiplication table with user input 23 | - users can ask for certain tables or to list the first 12 24 | - a quiz that can end if a question is answered wrong 25 | """ 26 | -------------------------------------------------------------------------------- /python3/module04/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.4.0 - Data Structures & Lists 2 | - lists [or arrays] are a type of data structure that can hold multiple values 3 | - "arrays" in python are very different than other languages because they can hold multiple datatypes 4 | - the index is the placement or location of a value in an array 5 | - the index for the first item in an array is 0, the second item's index is 1, the third's is 2, and so on... 6 | 7 | ## 0.4.1 - Initializing Lists 8 | lists allocate an area in memory to store multiple values in one variable 9 | - created using square brackets "[]" 10 | - the values stored in the brackets are seperated by commas "," 11 | - the values can be of any datatype 12 | ``` 13 | list1 = [1, 2, 3] 14 | print(list1) 15 | >>> [1, 2, 3] 16 | ``` 17 | lists can be added together 18 | ``` 19 | list2 = [4, 5, 3] 20 | my_list = list1 + list2 21 | print(my_list) 22 | >>> [1, 2, 3, 4, 5, 3] 23 | ``` 24 | you can print the index of a list 25 | ``` 26 | print(my_list[2]) 27 | >>> 3 28 | ``` 29 | 30 | ## 0.4.2 - List Functions & Methods 31 | - a method is a function that relates directly to an object or statement 32 | - "append" method, adds a value to the end of a list 33 | ``` 34 | my_list.append(6) 35 | print(my_list) 36 | >>> [1, 2, 3, 4, 5, 3, 6] 37 | ``` 38 | "insert" method, inserts a value at specific index 39 | - input the index of where you want the value to be stored and then the new value 40 | ``` 41 | my_list.insert(2, 9) 42 | print(my_list) 43 | >>> [1, 2, 9, 3, 4, 5, 3, 6] 44 | ``` 45 | "index" method, returns the index of the first occurance of the argument 46 | ``` 47 | print(my_list.index(2)) 48 | >>> 9 49 | ``` 50 | "count" method, retutns how many times a value appears in a list 51 | ``` 52 | print(my_list.count(3)) 53 | >>> 2 54 | ``` 55 | "remove" method, removes first occurance of a value 56 | ``` 57 | my_list.remove(3) 58 | print(my_list) 59 | >>> [1, 2, 9, 4, 5, 3, 6] 60 | ``` 61 | "pop" method, removes the last value of a list 62 | ``` 63 | my_list.pop() 64 | >>> 5 65 | print(my_list) 66 | >>> [1, 2, 9, 4, 3, 6] 67 | ``` 68 | "reverse" method, reverses the order of a list 69 | ``` 70 | my_list.reverse() 71 | print(my_list) 72 | >>> [6, 3, 4, 9, 2, 1] 73 | ``` 74 | "len" function, returns the length of the list, takes list as argument 75 | ``` 76 | print(len(my_list)) 77 | >>> 6 78 | ``` 79 | "max" function, returns the largest value in a list, takes list as argument 80 | ``` 81 | print(max(my_list)) 82 | >>> 9 83 | ``` 84 | "min" function, returns the lowest value in a list, takes list as argument 85 | ``` 86 | print(min(my_list)) 87 | >>> 1 88 | ``` 89 | 90 | ## 0.4.3 - Boolean Operations With Lists 91 | "in" boolean operator, checks to see if an item is in a list 92 | ``` 93 | print(2 in my_list) 94 | >>> True 95 | ``` 96 | "not" boolean operator, checks to see if an item is not in a list 97 | ``` 98 | print(10 not in my_list) 99 | >>> True 100 | 101 | print(not 10 in my_list) 102 | >>> True 103 | ``` 104 | 105 | ## 0.4.4 - List Slicing 106 | generate new Lists between set indexes 107 | - the first value will be the index that starts the list 108 | - the second value will be the index that ends the list 109 | ``` 110 | list = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] 111 | 112 | print(list[2:4]) 113 | >>> [15, 20, 25] 114 | ``` 115 | negative values count from the end of the list 116 | ``` 117 | list[3:-3] 118 | >>> [20, 25, 30, 35] 119 | ``` 120 | leaving the first value empty will print the indexes until it reaches the listed index 121 | ``` 122 | print(list[:5]) 123 | >>> [5, 10, 15, 20, 25, 30] 124 | ``` 125 | leaving the second value empty will print the indexes until it reaches the final index 126 | ``` 127 | print(list[3:]) 128 | >>> [20, 25, 30, 35, 40, 45, 50] 129 | ``` 130 | leaving both values empty will print the indexes until it reaches the final index 131 | ``` 132 | print(list[:]) 133 | >>> [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] 134 | ``` 135 | adding a third value will create an interval of the listed value 136 | ``` 137 | print(list[2:8:2]) 138 | >>> [15, 25, 35] 139 | ``` 140 | if a negative number is used as the interval, the slice is done backwards 141 | ``` 142 | list[::-1] 143 | >>> [50, 45, 40, 35, 30, 25, 20, 15, 10, 5] 144 | ``` 145 | 146 | ## 0.4.5 - List Comprehension 147 | generate lists using some sort of rule or conditional 148 | ``` 149 | count_by_2 = [i * 2 for i in range(10)] 150 | ``` 151 | conditionals can be added 152 | ``` 153 | odd_numbers_lessThan_5 = [i for i in range(5) if i % 2 > 0] 154 | >>> [1, 3] 155 | ``` 156 | -------------------------------------------------------------------------------- /python3/module04/m4-practice/dog-name-generator.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will make a dog name generator 3 | 4 | # created by : C0SM0 5 | 6 | # banner 7 | print("Dog Name Generator:") 8 | 9 | # dog name lists, gender respective 10 | male_names = ["Duke", "Sam", "Flipper", "Elliot", "Junior"] 11 | female_names = ["Lucy", "Bailey", "Cleo", "Sadie", "Zoe"] 12 | 13 | # output format 14 | output_format = "You should name your dog: " 15 | 16 | # loop code, in case of exception 17 | while True: 18 | # user inpur, gender 19 | print("What is your dog's gender?\n1) Male\n2) Female\n") 20 | dog_gender = int(input("Answer : ")) 21 | 22 | # user input, random number 23 | random_number = int(input("Pick a number between 1 and 5 : ")) 24 | 25 | # check if random number is between 1 and 5 26 | if random_number <= 5 and random_number >= 1: 27 | # checks if dog is male 28 | if dog_gender == 1: 29 | print(output_format+male_names[int(random_number)]) 30 | break 31 | 32 | # checks if dog is female 33 | elif dog_gender == 2: 34 | print(output_format+female_names[int(random_number)]) 35 | break 36 | 37 | # exception, gender 38 | else: 39 | print("You did not choose '1' for 'Male' or '2' for 'Female\n") 40 | continue 41 | 42 | # exception, random number 43 | else: 44 | print("Number not between 1 and 5, try again\n") 45 | continue 46 | 47 | # feel free to keep practicing, here are some more ideas 48 | """ 49 | - vending machine 50 | - filter specific numbers in a list [even numbers, odd numbers, prime numbers, etc] 51 | """ -------------------------------------------------------------------------------- /python3/module05/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.5.0 - Dictionaries, Tuples, Sets 2 | - more data structures 3 | 4 | ## 0.5.1 - Dictionaries 5 | - an array type that can list multiple keys [items] and assign each key a value [definition] 6 | - dictionaries have no order 7 | > Initialization 8 | - created using curly braces "{}" 9 | - keys in between the curly braces are seperated by a comma "," 10 | - each key is assigned a value by using a colon ":" 11 | ``` 12 | my_dict = {"name":"cosmo", "age":100, "occupation":"hacker"} 13 | ``` 14 | dictionaries can be indexed 15 | ``` 16 | print(my_dict["name"]) 17 | >>> "cosmo" 18 | ``` 19 | values can be added or changed through the assignmetn operator 20 | ``` 21 | nums = {"one":1, "two":2, "three":5} 22 | nums["four"] = 4 23 | nums["three"] = 3 24 | print(nums) 25 | >>> {"one":1, "two":2, "three":3, "four":4} 26 | ``` 27 | "in" and "not" boolean operators in work with dictionary keys 28 | ``` 29 | print("two" in nums) 30 | >>> True 31 | 32 | print("one" not in nums) 33 | >>> False 34 | ``` 35 | "get" method, returns the key's value, can return specified value if key is not found 36 | - if no return value is specified, it will return "None" 37 | ``` 38 | print(nums.get("three")) 39 | >>> 3 40 | 41 | print(nums.get("five", "key does not exist")) 42 | >>> "key does not exist" 43 | ``` 44 | 45 | ## 0.5.2 - Tuples 46 | - lists that can not be edited, immutable 47 | - iterate faster than lists 48 | - created using parenthesis "()" or just seperating values with commas "," 49 | - values are seperated by commas "." 50 | ``` 51 | my_tuple = (1, 2, 3, 4, 5) 52 | my_other_tuple = 1, 2, 3, 4, 5 53 | ``` 54 | tuples can be indexed 55 | ``` 56 | print(my_tuple[3]) 57 | >>> 4 58 | ``` 59 | list slicing can also be done with tuples 60 | ``` 61 | print(my_tuple[1:3]) 62 | >>> (2, 3, 4) 63 | ``` 64 | 65 | ## 0.5.3 - Sets 66 | - assign multiple values to one variable 67 | - sets are not ordered, they can not be indexed 68 | - they can not contain duplicate items 69 | - can use most of the list methods 70 | - created using curly braces "{}" or the "set" function, takes list as argument 71 | - each item is seperated by a comma "," 72 | ``` 73 | set_using_braces = {1, 2, 3, 4, 5} 74 | set_using_function = set([1, 2, 3, 4, 5]) 75 | ``` 76 | sets can use "in" and "not" boolean operators 77 | ``` 78 | my_set = {"apple", "orange", "bannana"} 79 | print("apple" in my_set) 80 | >>> True 81 | ``` 82 | "add" method, add item to end of set 83 | - this replaces "append" method 84 | ``` 85 | my_set.add("pear") 86 | print(my_set) 87 | >>> {"apple", "orange", "bannana", "pear"} 88 | ``` 89 | 90 | ## 0.5.4 - Set Operators 91 | sets have unuiqe operators for comining with other sets 92 | ``` 93 | set1 = {0, 2, 4, 6, 8, 9} 94 | set2 = {2, 3, 5, 7, 9, 6} 95 | ``` 96 | "union" operator, combines two sets into one [with no duplicate items] 97 | - created using the pipe "|" 98 | ``` 99 | print(set1 | set2) 100 | >>> {0, 2, 3, 4, 5, 6, 7, 8, 9} 101 | ``` 102 | "intersection" operator, combines two sets into one [with items only in both sets] 103 | - created using the ampersand "&" 104 | ``` 105 | print(set1 & set2) 106 | >>> {9, 2, 6} 107 | ``` 108 | "difference" operator, combines two sets into one [with items in the first, but not in the second] 109 | - created using the minus "-" 110 | ``` 111 | print(set1 - set2) 112 | >>> {0, 8, 4} 113 | ``` 114 | "symmetric difference" operator, combines two sets into one [with items in either set] 115 | - created using carrot "^" 116 | ``` 117 | print(set1 ^ set2) 118 | >>> {0, 3, 4, 5, 7, 8} 119 | ``` 120 | 121 | ## 0.5.5 - Iterable Unpacking 122 | assign each item in an iterable [lists, dictionaries, tuples, sets] to a variable 123 | ``` 124 | nums = (1, 2, 3) 125 | one, two, three = nums 126 | 127 | print(two) 128 | 129 | >>> 2 130 | ``` 131 | allows for easy value swapping for variables 132 | ``` 133 | one, two = two, one 134 | ``` 135 | if there is an asterisk `*` placed before the variable, it will assign itself to the remaining values 136 | ``` 137 | lowest_num, *other_nums, highest_num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 138 | 139 | print(other_nums) 140 | >>> [2, 3, 4, 5, 6, 7, 8, 9] 141 | ``` 142 | -------------------------------------------------------------------------------- /python3/module05/m5-practice/data-comparison.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will use sets to compare data 3 | 4 | # created by : C0SM0 5 | 6 | # sets of animals that can live on land and sea [respectively] 7 | can_live_on_land = {"Wolves", "Alligator", "Deer"} 8 | can_live_in_sea = {"Fish", "Dolphin", "Alligator"} 9 | 10 | # create terrestial specific sets for the creature types 11 | land_creatures = can_live_on_land - can_live_in_sea 12 | sea_creatures = can_live_in_sea - can_live_on_land 13 | amphibious_creatures = can_live_on_land & can_live_in_sea 14 | 15 | # output, creatures that can live on land 16 | print(f"Creatures that live on land:\n{land_creatures}\n") 17 | print(f"Creatures that live in water:\n{sea_creatures}\n") 18 | print(f"Creatures that live in both:\n{amphibious_creatures}\n") 19 | 20 | # feel free to keep practicing, here are some more ideas 21 | """ 22 | - compare food at home to food on your grocery list 23 | - prevent duplicate entries when creating an account or submitting quiz/survey answers 24 | """ -------------------------------------------------------------------------------- /python3/module06/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.6.0 - Working With Modules 2 | - python is a very dynamic language 3 | - one effect of this is how modular it is 4 | - in python, and some other languages, we can import modules to give our code more funcitonality 5 | 6 | ## 0.6.1 - Importing Modules 7 | "import" command, imports a module 8 | ``` 9 | import MODULE 10 | ``` 11 | "as" operator, module to a variable name 12 | ``` 13 | import MODULE as VARIABLE 14 | ``` 15 | - "from" statement, import specific method[s] from certain modules 16 | ``` 17 | from MODULE import METHOD 18 | ``` 19 | "as" statement can be used with "from" 20 | ``` 21 | from MODULE import METHOD as VARIABLE 22 | ``` 23 | 24 | ## 0.6.2 - The Zen of Python 25 | a set of rules on how to write python code effeciently 26 | ``` 27 | import this 28 | 29 | >>> The Zen of Python, by Tim Peters 30 | 31 | >>> Beautiful is better than ugly. 32 | >>> Explicit is better than implicit. 33 | >>> Simple is better than complex. 34 | >>> Complex is better than complicated. 35 | >>> Flat is better than nested. 36 | >>> Sparse is better than dense. 37 | >>> Readability counts. 38 | >>> Special cases aren't special enough to break the rules. 39 | >>> Although practicality beats purity. 40 | >>> Errors should never pass silently. 41 | >>> Unless explicitly silenced. 42 | >>> In the face of ambiguity, refuse the temptation to guess. 43 | >>> There should be one-- and preferably only one --obvious way to do it. 44 | >>> Although that way may not be obvious at first unless you're Dutch. 45 | >>> Now is better than never. 46 | >>> Although never is often better than \*right\* now. 47 | >>> If the implementation is hard to explain, it's a bad idea. 48 | >>> If the implementation is easy to explain, it may be a good idea. 49 | >>> Namespaces are one honking great idea -- let's do more of those! 50 | ``` 51 | 52 | ## 0.6.3 - Random Module 53 | - module used ot generate random values 54 | - import the random module 55 | ``` 56 | import random 57 | ``` 58 | assign module to variable name "r" 59 | ``` 60 | import random as r 61 | ``` 62 | "random" method, returns random value between 0 and 0.999... 63 | ``` 64 | print(r.random()) 65 | >>> 0.6000450210967234 66 | ``` 67 | "uniform" method, returns random value between two points as a float 68 | - values put as the first argument are inclusive, they are included as a possible output 69 | - values put as the second argument are noninclusive, they are not included as a possible output 70 | ``` 71 | print(r.uniform(1, 10)) 72 | >>> 7.20157760130375 73 | ``` 74 | "randint" method, returns value between two points as integrs [inclusive] 75 | ``` 76 | print(r.randint(1, 10)) 77 | >>> 5 78 | ``` 79 | "choice" method, returns random value from a group 80 | ``` 81 | dice = [1, 2, 3, 4, 5, 6] 82 | print(r.choice(dice)) 83 | >>> 4 84 | ``` 85 | "choices" method, returns multiple values from a group 86 | - k variable = number of values we wish to return 87 | ``` 88 | print(dice, k = 3) 89 | ``` 90 | "shuffle" method, returns shuffled values 91 | ``` 92 | numbers = [5, 4, 6, 7, 3] 93 | r.shuffle(numbers) 94 | print(numbers) 95 | >>> [6, 7, 5, 4, 3] 96 | ``` 97 | "sample" method, returns random values [none of witch are repeated] 98 | ``` 99 | pick_numbers = r.sample(numbers, k=3) 100 | print(pick_numbers) 101 | >>> [4, 3, 7] 102 | ``` 103 | 104 | ## 0.6.4 - Python Package Index [PYPI] 105 | - python does come preinstalled with modules, but you can install more modules for more functionality 106 | - you can do this from the PYPI: 'https://pypi.org/' 107 | --- 108 | - "pip", installs modules 109 | - you should have pip if you installed python properly 110 | - if you don't navigate here: 'https://packaging.python.org/tutorials/installing-packages/' 111 | - naviagate to your command line [Command Prompt [CMD], powershell, or terminal; depends on your operating system] 112 | ``` 113 | pip install MODULE 114 | ``` 115 | -------------------------------------------------------------------------------- /python3/module06/m6-practice/password-generator.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will be making a password generator 3 | 4 | # created by : C0SM0 5 | 6 | # import random module, "r" 7 | import random as r 8 | 9 | # banner 10 | print("Password Generator") 11 | 12 | # empty password variable 13 | password = "" 14 | 15 | # variables for password generation 16 | lowercase = "abcdefghijklmnopqrstuvwxyz" 17 | uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 18 | numbers = "0123456789" 19 | symbols = "~!@#$%^&*()_+<>?:{}|\][';/.,']" 20 | all_characters = lowercase+uppercase+numbers+symbols 21 | 22 | # user input, password length 23 | password_length = int(input("Enter the number of characters for your password : ")) 24 | 25 | # generate password 26 | for i in range(password_length): 27 | # gets random character 28 | character = r.choice(all_characters) 29 | # adds random character to password 30 | password += character 31 | 32 | # output password 33 | print(password) 34 | 35 | # feel free to keep practicing, here are some more ideas 36 | """ 37 | - rock paper scissors, dice simulator, coin flipper 38 | - learn to use other modules like 'datetime', 'math', or 'regular expressions' 39 | """ -------------------------------------------------------------------------------- /python3/module07/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.7.0 - Methods and Functions 2 | - a method is a function of a class, module, or object 3 | 4 | ## 0.7.1 - String Methods 5 | "join" method, joins or connects a list of strings with an indicated seperator 6 | ``` 7 | print(','.join(["Hello","World"])) 8 | >>> "Hello,World" 9 | ``` 10 | "split" method, splits a string into a list of substrings 11 | ``` 12 | print("Hello,World".split(",")) 13 | >>> ['Hello', 'World'] 14 | ``` 15 | - "strip" method, strips all leading and trailing characters 16 | - removes [leading and trailing] spaces by default 17 | ``` 18 | print(" Hello, World! ".strip()) 19 | >>> "Hello, World!" 20 | ``` 21 | - "replace" method, replaces a substring with a different string 22 | - "substring", part of a string 23 | ``` 24 | print("Hello World".replace("World", "Earth")) 25 | >>> "Hello Earth" 26 | ``` 27 | - "startswith" method, detect if a string starts with a certain character 28 | - returns a boolean value 29 | ``` 30 | print("Hello, World!".startswith("H")) 31 | >>> True 32 | ``` 33 | - "endswith" method, detect if a string ends with a certain character 34 | - returns a boolean value 35 | ``` 36 | print("Hello, World!".endswith("?")) 37 | >>> False 38 | ``` 39 | "upper" method, makes string text uppercase 40 | ``` 41 | print("Hello, World!".upper()) 42 | >>> "HELLO, WORLD!" 43 | ``` 44 | "lower" method, makes string text lowercase 45 | ``` 46 | print("Hello, World!".lower()) 47 | >>> "hello, world!" 48 | ``` 49 | "title" method, makes every substring start with a capital 50 | ``` 51 | print("hello, world!".title()) 52 | >>> "Hello, World!" 53 | ``` 54 | "isupper" method, returns boolean if string text is uppercase 55 | ``` 56 | print("HELLO, WORLD!".isupper()) 57 | >>> True 58 | ``` 59 | "islower" method, returns boolean if string text is lowercase 60 | ``` 61 | print("hello, world!".islower()) 62 | >>> True 63 | ``` 64 | 65 | ## 0.7.2 - Numeric Functions 66 | "abs" function, gets the absolute value 67 | ``` 68 | print(abs(-50)) 69 | >>> 50 70 | ``` 71 | "round" function, rounds a float to the nearest decimal place 72 | ``` 73 | print(round(9.8)) 74 | >>> 10 75 | ``` 76 | "sum" function, adds all the values in a list 77 | ``` 78 | print(sum([1, 3, 4, 10, 6, 8])) 79 | >>> 32 80 | ``` 81 | "max" function, find the highest number in a list 82 | ``` 83 | print(max([1, 3, 4, 10, 6, 8])) 84 | >>> 10 85 | ``` 86 | "min" function, find the lowest number in a list 87 | ``` 88 | print(min([1, 3, 4, 10, 6, 8])) 89 | >>> 1 90 | ``` 91 | 92 | ## 0.7.3 - Iterable Functions 93 | - "any" function,checks to see if any values of a list follow an argument 94 | - returns boolean value 95 | ``` 96 | num_list = [1, 3, 4, 10, 6, 8] 97 | if any(i < 10 for i in num_list): 98 | print("There are numbers less than 10") 99 | 100 | >>> "There are numbers less than 10" 101 | ``` 102 | - "all" function, checks to see if all values of a list follow an argument 103 | - returns boolean value 104 | ``` 105 | num_list = [1, 3, 4, 9, 6, 8] 106 | if all(i < 10 for i in num_list): 107 | print("All of the numbers are less than 10") 108 | 109 | 110 | >>> "All of the numbers are less than 10" 111 | ``` 112 | "enumerate" function, iterates through the indexes and values of a list 113 | ``` 114 | num_list = [10, 15, 20, 25, 30] 115 | for num in enumerate(num_list): 116 | print(num) 117 | 118 | >>> (0, 10) 119 | >>> (1, 15) 120 | >>> (2, 20) 121 | >>> (3, 25) 122 | >>> (4, 30) 123 | ``` 124 | "items" function, seperates dictionary keys and values for iteration 125 | ``` 126 | laptops = {"Razer Blade":"$2200", "MacBook":"$1500", "Dell XPS": "$1800"} 127 | 128 | for laptop, price in laptops.items(): 129 | print(f"The {laptop} costs {price}") 130 | 131 | >>> "The Razer Blade costs $2200" 132 | >>> "The MacBook costs $1500" 133 | >>> "The Dell XPS costs $1800" 134 | ``` 135 | -------------------------------------------------------------------------------- /python3/module07/m7-practice/encoder.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will make an encoder program 3 | 4 | # created by : C0SM0 5 | 6 | # to save us time 7 | # we will create our 'encoded_alphabet' variable in a python shell 8 | """ 9 | >>> alphabet = "abcdefghijklmnopqrstuvwxyz" 10 | >>> reversed_alph = alphabet[::-1] 11 | >>> for index in range(26): 12 | ... print(f"\t\"{alphabet[index]}\":\"{reversed_alph[index]}\",") 13 | """ 14 | 15 | # our alphabet we will use to encode text 16 | encoded_alphabet = { 17 | "a":"z", 18 | "b":"y", 19 | "c":"x", 20 | "d":"w", 21 | "e":"v", 22 | "f":"u", 23 | "g":"t", 24 | "h":"s", 25 | "i":"r", 26 | "j":"q", 27 | "k":"p", 28 | "l":"o", 29 | "m":"n", 30 | "n":"m", 31 | "o":"l", 32 | "p":"k", 33 | "q":"j", 34 | "r":"i", 35 | "s":"h", 36 | "t":"g", 37 | "u":"f", 38 | "v":"e", 39 | "w":"d", 40 | "x":"c", 41 | "y":"b", 42 | "z":"a" 43 | } 44 | # symbols that can't be encoded 45 | symbols = "~!@#$%^&*()_+=-0987654321`{}[]|\:;\"'?><,./" 46 | 47 | # banner 48 | print("Basic Encoder") 49 | 50 | # option menu 51 | print("Choose an Option:\n1) Encode\n2) Decode\n") 52 | # user input, option 53 | option = input("Option : ") 54 | # user input, message 55 | message = input("Enter text to translate : ") 56 | 57 | # empty output variable 58 | output = "" 59 | 60 | # iterates through message characters 61 | for character in message: 62 | # iterates through encoded alphabet dictionary 63 | for standard, encoded in encoded_alphabet.items(): 64 | # encoding process 65 | if option == "1": 66 | # checks if character is lowercase 67 | if character.islower() and character == standard: 68 | output += encoded 69 | break 70 | # checks if character is uppercase 71 | if character.isupper() and character.lower() == standard: 72 | output += encoded.upper() 73 | break 74 | 75 | # decoding process 76 | if option == "2": 77 | # checks if character is lowercase 78 | if character.islower() and character == encoded: 79 | output += standard 80 | break 81 | # checks if character is uppercase 82 | if character.isupper() and character.lower() == encoded: 83 | output += standard.upper() 84 | 85 | # adds unrecognized characters to outpur, avoids exceptions 86 | if character in symbols: 87 | output += character 88 | break 89 | 90 | # output endoded/decoded message 91 | print(output) 92 | 93 | # feel free to keep practicing, here are some more ideas 94 | """ 95 | - fake identity generator 96 | - basic language translator 97 | """ -------------------------------------------------------------------------------- /python3/module08/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.8.0 - Working With Files 2 | - python can edit files 3 | - read files 4 | - write files 5 | 6 | ## 0.8.1 - Opening Files 7 | - in python, we need to open files before we can read or edit them 8 | - just like how we do 9 | - "open" function, opens files, takes filename as argument 10 | ``` 11 | file = open("file.txt") 12 | ``` 13 | 14 | ## 0.8.2 - Opening File Arguments 15 | - the first argument is the path to the file 16 | - if the file is within the same directory as the program, you can just enter the filename 17 | - the second argument is the mode the file will be opened in 18 | - the three modes we will cover [there are more] in this course are: 19 | 1. "read" mode [r] 20 | ``` 21 | file = open("file.txt", "r") 22 | ``` 23 | - by default, files are opened in read mode 24 | 2. "write" mode [w] 25 | ``` 26 | file = open("file.txt", "w") 27 | ``` 28 | 3. "append" mode [a] 29 | ``` 30 | file = open("file.txt", "a") 31 | ``` 32 | 33 | ## 0.8.3 - Closing Files 34 | - when we are done working with a file, we need to close it in order to effectly save our changes 35 | - "close" method, closes files 36 | ``` 37 | file = open("file.txt", "w") 38 | ... 39 | f.close() 40 | ``` 41 | 42 | ## 0.8.4 - Reading Files 43 | - python reads files from top to bottom, meaning that if a file is read, it needs to be reopened to be read again [so make sure to save the read content to a variable] 44 | - "read" method, reads file contents 45 | ``` 46 | file = open("file.txt", "r") 47 | read_file = f.read() 48 | f.close() 49 | 50 | # prints file contents 51 | print(f"File Contents:\n{read_file}") 52 | ``` 53 | numbers can be used as an argument to read specific lines of a file 54 | ``` 55 | file = open("file.txt", "r") 56 | 57 | # prints line 5 58 | print(f.read(5)) 59 | 60 | file.close() 61 | ``` 62 | - "readlines" method, reads each line of the file rather than each character 63 | - file data is iterable, they can be looped through 64 | ``` 65 | username = "cosmo" 66 | 67 | # gets file data 68 | file = open("file.txt", "r") 69 | read_lines = file.readlines() 70 | file.close() 71 | 72 | # iterates through file data 73 | for line in read_lines: 74 | if username in line: 75 | print("user exists") 76 | ``` 77 | 78 | ## 0.8.5 - Writing Files 79 | - writing to a file will empty it's current contents, and replace it with your inputed data 80 | - if the file python opens doesn't exist, it will create it 81 | - "write" method, writes string data to file 82 | - the srting argument will be the content written to the file 83 | ``` 84 | file = open("file.txt", "w") 85 | 86 | # write to a file 87 | file.write("Hello, World!") 88 | file.close 89 | 90 | read_file = open("file.txt", "r").read() 91 | read_file.close() 92 | 93 | print(read_file) 94 | ``` 95 | 96 | ## 0.8.6 - Appending Files 97 | - as I mentioned before, writing to a file replaces the current existing data with the new attached data 98 | - this doesn't matter if you are generating a file or writing to a blank doucment 99 | - one way we can acheive this is by reading a file, and writing the read data with our new data 100 | ``` 101 | old_data = open("file.txt", "r").read() 102 | old_data.close() 103 | 104 | file = open("file.txt", "w") 105 | file.write(f"{old_data}\nNew Data") 106 | ``` 107 | - this is effective but there is an easier alternative, writing to a file in "append" mode 108 | ``` 109 | file = open("file.txt", "a") 110 | file.write("this line was added on to the old data") 111 | file.close() 112 | ``` 113 | 114 | ## 0.8.7 - With Statement 115 | - ensures that the file will close in case of exception [error] 116 | - will create a variable only accessible within the "with" statements scope 117 | - scope, the area where a variable can be accessed [more on this in the future] 118 | ``` 119 | with open("file.txt", "r") as f: 120 | print(f"File Contents: \n{f.read()}) 121 | ``` 122 | - notice how the file did not need to be opened or closed, it was handled in the "with" statement 123 | -------------------------------------------------------------------------------- /python3/module08/m8-practice/account-manager.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will make an account manager 3 | 4 | # created by : C0SM0 5 | 6 | # banner 7 | print("Account Manager\n") 8 | 9 | # loop code, in case of exception 10 | while True: 11 | # databases 12 | account_db = 'accounts.txt' 13 | read_db = open(account_db).readlines() 14 | 15 | # option menu 16 | print("Account Options:\n1) Create Account\n2) Sign in\n") 17 | option = input("Option : ") 18 | 19 | # user input, username 20 | username = input("\nEnter username : ") 21 | # user input, password 22 | password = input("Enter password : ") 23 | # format account 24 | account = f"{username}=={password}" 25 | 26 | # otpion 1, create account 27 | if option == "1": 28 | # user input, password confirmation 29 | confirm_password = input("Confirm new password : ") 30 | 31 | # confirm password 32 | if password != confirm_password and "=" not in password: 33 | print("Invalid password\n- passwords don't match\n- password can't contain \"=\"\n") 34 | continue 35 | 36 | # updates db with new account 37 | else: 38 | with open(account_db, "w") as db: 39 | db.write(f"{read_db}\n{account}") 40 | print("Account Created, you can now sign in\n") 41 | continue 42 | 43 | # option 2, sign in 44 | elif option == "2": 45 | for user_account in read_db: 46 | if user_account.startswith(f"{username}=="): 47 | if user_account.endswith(f"=={password}"): 48 | print("ACCESS GRANTED!") 49 | break 50 | else: 51 | print("Password is incorrect, try again\n") 52 | continue 53 | 54 | # exception 55 | else: 56 | print("Invalid input option, try again\n") 57 | continue 58 | 59 | break 60 | 61 | # feel free to keep practicing, here are some more ideas 62 | """ 63 | - add options for deleting profiles and resetting passwords in the code above 64 | - search for certain items in a a file 65 | """ -------------------------------------------------------------------------------- /python3/module08/m8-practice/accounts.txt: -------------------------------------------------------------------------------- 1 | [] 2 | cosmo==passw -------------------------------------------------------------------------------- /python3/module09/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.9.0 - Exception Handling 2 | - handling errors [exceptions] in python 3 | - prevents code from breaking 4 | 5 | ## 0.9.1 - Error Types 6 | - in most programming languages, there are three main types of erros 7 | 1. Syntax Error - occurs when the syntax of a program is incorrect 8 | ``` 9 | # the "print" function is spelled incorrectly [pint] 10 | pint("Hello, World") 11 | >>> ERROR 12 | ``` 13 | 2. Run-Time Error - occurs when invalid data is inputted during "runtime" 14 | - runtime, any time after a program starts running 15 | ``` 16 | # this program asks for integer input, the user inputs a string 17 | int(input("What is your favorite number? : ")) 18 | >>> What is your favorite number? : tree 19 | >>> ERROR 20 | ``` 21 | 3. Logical Error - Program runs as normal but not as intended 22 | - typically the hardest to find 23 | ``` 24 | # the program is intended to print their name before their age 25 | name = "bob" 26 | age = "100" 27 | print(f"Hello, my name is {age} and I am {name} years old") 28 | 29 | >>> "Hello, my name is 100 and I am bob years old" 30 | ``` 31 | 32 | ## 0.9.2 - Try & Except Statements 33 | - permits the developer to *try* a code segment, *except* if it doesn't work, it will run a different code segment 34 | - "try" statement, try code that may cause an exception 35 | - "except" statement, if an exception occurs in the try block, it will stop running, and run a different segment of code 36 | ``` 37 | try: 38 | print(2/0) 39 | print("This will not print") 40 | 41 | except: 42 | print("You can't divide by zero") 43 | ``` 44 | it is good practice to specify the exception the program is looking for 45 | ``` 46 | try: 47 | print(2/0) 48 | print("This will not print") 49 | 50 | except ZeroDivisionError: 51 | print("You can't divide by zero") 52 | ``` 53 | you can specify multiple exceptions in the exception block 54 | ``` 55 | try: 56 | print(2/0) 57 | print("This will not print") 58 | 59 | except ZeroDivisionError, TypeError: 60 | print("Error) 61 | ``` 62 | you can chain except statements to specify multiple exceptions 63 | ``` 64 | try: 65 | money = "10" 66 | # "money" is a string, the following will cause a type error 67 | print(money - 3) 68 | print("This will not print") 69 | 70 | except ZeroDivisionError: 71 | print("You can't divide by zero") 72 | 73 | except TypeError: 74 | print("You can't subtract an integer from a string") 75 | ``` 76 | 77 | ## 0.9.3 - Raise 78 | - "raise" statement, displays the error that occured in the "try" statement 79 | - good for figuring out what error you are dealing with 80 | ``` 81 | try: 82 | print(2/0) 83 | print("This will not print") 84 | 85 | except: 86 | print("Error") 87 | raise 88 | ``` 89 | "raise" can also be used to throw an exception into runtime 90 | ``` 91 | print("Hello World!") 92 | raise ZeroDivisionError 93 | print("Will not run") 94 | ``` 95 | you can add a description with raised errors 96 | ``` 97 | print("Hello World!") 98 | raise ZeroDivisionError("incorrect value") 99 | print("Will not run") 100 | ``` 101 | 102 | ## 0.9.4 - Finally 103 | - "finally" statement, runs code no matter what 104 | - comes last when creating "try" and "except" statements 105 | ``` 106 | try: 107 | print(2/0) 108 | print("This will not print") 109 | 110 | except ZeroDivisionError: 111 | print("You can't divide by zero") 112 | 113 | finally: 114 | print("This will print no matter what") 115 | ``` 116 | 117 | ## 0.9.5 - Assertion 118 | - "assert" statement, uses boolean operators to test an expression 119 | - if true, the code will run as normal 120 | - if false, the code will raise an "AssertionError" exception 121 | - good for testing 122 | ``` 123 | account = 100 124 | 125 | # checks to see if account has the proper value 126 | assert account == 50 127 | >>> AssertionError 128 | ``` 129 | an argument can be added to the "assert" statement where it returns said argument in the exception message 130 | ``` 131 | account = 100 132 | 133 | # checks to see if account has the proper value 134 | assert account == 50, "account should equal '100'" 135 | >>> AssertionError: account should equal '100' 136 | ``` 137 | 138 | ## 0.9.6 - Handling Exceptions With Conditionals 139 | - the else statement can be used to handle exceptions 140 | - it will run its segmented code if no exceptions occur withing the try statement 141 | ``` 142 | try: 143 | print(2/0) 144 | print("This will not print") 145 | 146 | except ZeroDivisionError: 147 | print("You can't divide by zero") 148 | 149 | else: 150 | print("This will print if there are no errors") 151 | 152 | finally: 153 | print("This will print no matter what") 154 | ``` 155 | 156 | ## 0.9.7 - Helpful Summary 157 | If you are still confused, here is a helpful summary 158 | ``` 159 | try - tries to run a segment of code 160 | except - runs if an error occurs 161 | else - runs if no errors occur 162 | finally - runs no matter what 163 | ``` -------------------------------------------------------------------------------- /python3/module09/m9-practice/rock-paper-scissors.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will make the game "Rock, Paper, Scissors" [rps] 3 | 4 | # created by : C0SM0 5 | 6 | # import random module, "r" 7 | import random as r 8 | 9 | # loop code, avoid exception 10 | while True: 11 | # banner 12 | print("Rock, Paper, Scissors") 13 | 14 | # available options 15 | options = ("Rock", "Paper", "Scissors") 16 | 17 | # option menu 18 | print("Choose your move:\n1) Rock\n2) Paper\n3) Scissors\n") 19 | 20 | # try to get integer user input 21 | try: 22 | # user input, option 23 | user_option = int(input("Option : ")) 24 | comp_option = r.choice(options) 25 | 26 | # rock 27 | if user_option == 1: 28 | user_move = options[0] 29 | 30 | # paper 31 | elif user_option == 2: 32 | user_move = options[1] 33 | 34 | # scissors 35 | elif user_option == 3: 36 | user_move = options[2] 37 | 38 | # exception 39 | else: 40 | print("Invalid option, try again\n") 41 | continue 42 | 43 | # shoot 44 | print("\nRock...\nPaper...\nScissors...\nSHOOT!\n") 45 | print(f"Your move : {user_move}") 46 | print(f"Computer move : {comp_option}") 47 | 48 | # calculates draw 49 | if user_move == comp_option: 50 | print("Draw :|\n\n") 51 | break 52 | 53 | # calculates loss 54 | elif (user_move == options[0] and comp_option == options[1]) or (user_move == options[1] and comp_option == options[2]) or (user_move == options[2] and comp_option == options[1]): 55 | print("You lose :(\n\n") 56 | break 57 | 58 | # calcualtes win 59 | else: 60 | print("You Win :)") 61 | break 62 | 63 | # exception 64 | except ValueError: 65 | print("Enter a whole number option [1, 2, or 3]\n") 66 | 67 | # feel free to keep practicing, here are some more ideas 68 | """ 69 | - a money/coin counter 70 | - a minimal calculator 71 | """ -------------------------------------------------------------------------------- /python3/module10/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.10.0 - Functional Programming 2 | - a method of programming using funcitons 3 | - function, a statement that [typically] takes an input, uses that input to perform an operation, and will return some output. 4 | ``` 5 | print("Hello, World") 6 | >>> Hello, World 7 | ``` 8 | functions are typically structured as a statement, followed by some parenthesis "()" 9 | 10 | ## 0.10.1 - Defining and Calling Functions 11 | - in python, and most programming languages, we can make our own functions 12 | - in order to do this, we must define them 13 | - "def" statement, defines function 14 | ``` 15 | # defines function 16 | def my_func(): 17 | print("Hello, World!") 18 | ``` 19 | - now we that we have a function defined, we can call it 20 | - functions are called by placing the name of the function, followed by parenthesis "()" 21 | ``` 22 | my_func() 23 | >>> "Hello, World!" 24 | ``` 25 | - functions can be called multiple times 26 | 27 | ## 0.10.2 - Working With Arguments 28 | - functions can take argument, allows for ease of use and optimal code 29 | - argument, data that is inputted into a function [of some sort] 30 | - arguments [can] serve as varibles, only available in the functions scope 31 | ``` 32 | # this function squares numbers, "number" is the argument 33 | def squared(number): 34 | print(number**2) 35 | 36 | squared(2) 37 | squared(3) 38 | squared(4) 39 | 40 | >>> 4 41 | >>> 9 42 | >>> 16 43 | ``` 44 | - multiple arguments can be used within a function. 45 | - each argument is seperated by a comma. 46 | ``` 47 | # this function will add two numbers together 48 | def add_together(num1, num2): 49 | print(num1 + num2) 50 | 51 | add_together(1, 2) 52 | 53 | >>> 3 54 | ``` 55 | 56 | ## 0.10.3 - Returning Data 57 | - functions can return data that can be assigned and used in operations 58 | - "return" statement, returns data that can be used in operetions 59 | - the function will stop once the "return" statement is used 60 | ``` 61 | # this function will double a number and return the value 62 | def double(num): 63 | return num * 2 64 | 65 | print(double(2)) 66 | >>> 4 67 | ``` 68 | - the function can now be used as an object, argument, or value; because it can be assigned a value 69 | ``` 70 | four = double(2) 71 | multiply_by_2 = double 72 | print(multiply_by_2(5)) 73 | print(multiply_by_2(four)) 74 | 75 | >>> 10 76 | >>> 8 77 | ``` 78 | - the 'double' function above is a pure function, this is because it returns a value that only depends on the arguments attached 79 | - pure functions are more ideal in the programming world 80 | - an impure function depends on an external value or datatpype 81 | ``` 82 | message = "Hello, " 83 | def impure_function(text): 84 | return message + text 85 | 86 | greeting = impure_function 87 | greeting("World!") 88 | 89 | >>> "Hello, World!" 90 | ``` 91 | 92 | ## 0.10.4 - Higher-Order Functions 93 | a type of function that utilizes another function as an argument 94 | ``` 95 | # normal function 96 | def talk(message): 97 | return message 98 | 99 | uppercase_msg = talk 100 | uppercase_msg("Hello, World!") 101 | 102 | # higer-order function 103 | def message(func): 104 | uppercase_msg = func("Hello, World") 105 | print(uppercase_msge) 106 | 107 | message(talk) 108 | 109 | >>> Hello, World! 110 | >>> Hello, World 111 | ``` 112 | - this allows us to make our functions versatile, and add more functionality 113 | - we can use this same example to output different types of text. 114 | ``` 115 | def title_case(text): 116 | return text.title() 117 | 118 | def lower_case(text): 119 | return text.lower() 120 | 121 | def upper_case(text): 122 | return text.upper() 123 | 124 | def message(case, text): 125 | output = case(text) 126 | print(output) 127 | 128 | hw = "Hello, World!" 129 | message(upper_case, hw) 130 | message(lower_case, hw) 131 | message(title_case, hw) 132 | 133 | >>> HELLO, WORLD! 134 | >>> hello, world! 135 | >>> Hello, World! 136 | ``` 137 | 138 | ## 0.10.5 - Special Arguments 139 | - python has special arguments we can use in our functions 140 | - defined arguments, assinging default values to arguments 141 | - in the event that they are not defined, avoids error 142 | - defining arguments can be done with the assigment operator "=" 143 | ``` 144 | def profile(name = "Enter name", age = "Enter age", status = "Enter status"): 145 | return f"Name : {name}\nAge : {age}\nStatus : {status}\n" 146 | 147 | bobs_account = profile("bob", "25") 148 | joes_account = profile("Joe", "48", "single") 149 | 150 | print(bobs_account) 151 | print(joes_account) 152 | ``` 153 | - "\*" args argument, allows you to pass an undefined amount of arguments to a function, and assigns them to a tuple labled after your args variable name 154 | - the default is "args" 155 | ``` 156 | def class_schedule(mandatory_class, *args): 157 | print(f"Period 1: {mandatory_class}") 158 | 159 | period_number = 2 160 | 161 | for course in args: 162 | print(f"Period {period_number}: {course}") 163 | period_number += 1 164 | 165 | class_schedule("Homeroom", "Math", "Science", "English", "History") 166 | 167 | >>> Period 1: Homeroom 168 | >>> Period 2: Math 169 | >>> Period 3: Science 170 | >>> Period 4: English 171 | >>> Period 5: History 172 | ``` 173 | - "\*\*" kwargs argument, passes defined arguments into a dictionary labled after your kwarg variable name 174 | - the default is "kwargs" 175 | - dictionary key = argument name, dictionary value = argument value 176 | ``` 177 | def groceries(store_name, **kwargs): 178 | print("\n"+store_name) 179 | for food, price in kwargs.items(): 180 | print(f"{food} --> {price}") 181 | 182 | groceries("Giant", apples = "$1.50", oranges = "$2.50", bananas = "$1.75") 183 | groceries("Publix", apples = "$1.00", oranges = "$3.50", bananas = "$2.00") 184 | 185 | >>> Giant 186 | >>> apples --> $1.50 187 | >>> oranges --> $2.50 188 | >>> bananas --> $1.75 189 | >>> 190 | >>> Publix 191 | >>> apples --> $1.00 192 | >>> oranges --> $3.50 193 | >>> bananas --> $2.00 194 | ``` 195 | 196 | ## 0.10.6 - \_\_main\_\_ 197 | - allows your code to be both imported into other projects and scripts, or can run as is 198 | - the conditional `if __name__ == "__main__:"` detects if the code is being ran or imported, respectively 199 | - the attached expression will run if the code is being ran 200 | - let's make a file called 'script.py' and run it 201 | - script.py syntax 202 | ``` 203 | def double(n): 204 | return n*2 205 | 206 | def main(): 207 | # write main code in here 208 | print(f"2 doubled is {double(2)}") 209 | 210 | if __name__ == "__main__": 211 | main() 212 | 213 | >>> "2 doubled is 4" 214 | ``` 215 | - we can now effeciently import other dictionaries it into another file 216 | - calculator.py syntax 217 | ``` 218 | import script # name of file [in same directory] 219 | 220 | print(script.double(4)) 221 | 222 | >>> 8 223 | ``` 224 | 225 | ## 0.10.7 - Mapping and Filtering 226 | - "map" function, use each item in a list as an argument to a function 227 | - the first argument is the function 228 | - the second argument is the iterable 229 | ``` 230 | def double(n): 231 | return n * 2 232 | 233 | numbers = [1, 2, 3, 4] 234 | mapped_list = map(double, numbers) 235 | print(list(mapped_list)) 236 | 237 | >>> [2, 4, 6, 8] 238 | ``` 239 | - "filter" function, iterates through a list, only returns values that follow a certain argument 240 | - the first argument is the function 241 | - the second argument is the iterable 242 | ``` 243 | def even(n): 244 | return n % 2 == 0 245 | 246 | numbers = [1, 2, 3, 4] 247 | filtered_list = filter(even, numbers) 248 | print(list(filtered_list)) 249 | 250 | >>> [2, 4] 251 | ``` 252 | 253 | ## 0.10.8 - Lambda 254 | - a less powerful function that works in one line 255 | - can take in many arguments but only returns one expression 256 | ``` 257 | double = lambda x : x * 2 258 | double(2) 259 | double(3) 260 | double(4) 261 | 262 | >>> 4 263 | >>> 6 264 | >>> 8 265 | ``` 266 | - lambda's can take more than one argument 267 | ``` 268 | add_together = lambda x, y = x + y 269 | add_together(3, 7) 270 | 271 | >>> 10 272 | ``` 273 | - lambda's aren't always assigned to varaibles 274 | - they can be used as arguments for functions 275 | ``` 276 | num_list = list(range(-10, 11)) 277 | positive_values = list(filter(lambda x: x > 0, num_list)) 278 | print(positive_values) 279 | 280 | >>> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 281 | ``` -------------------------------------------------------------------------------- /python3/module10/m10-practice/calculator.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will be building a aimple calclulator 3 | 4 | # created by : C0SM0 5 | 6 | # addition function 7 | def addition(n1, n2): 8 | return n1 + n2 9 | 10 | # subtraction function 11 | def subtraction(n1, n2): 12 | return n1 - n2 13 | 14 | # multiplication function 15 | def multiplication(n1, n2): 16 | return n1 * n2 17 | 18 | # division funciton 19 | def division(n1, n2): 20 | return n1 / n2 21 | 22 | # loop code, in case of exception 23 | while True: 24 | # banner 25 | print("Simple Calculator") 26 | 27 | # option menu 28 | print("Choose an Operation:\n1) Addition\n2) Subtraction\n3) Multiplication\n4) Division\n") 29 | # user input, operation 30 | operation = input("Option : ") 31 | 32 | # try to get numeric values 33 | try: 34 | # user input, first number 35 | first_number = float(input("Enter first number : ")) 36 | second_number = float(input("Enter second number : ")) 37 | 38 | # addition 39 | if operation == "1": 40 | print(f"{first_number} + {second_number} = {addition(first_number, second_number)}") 41 | break 42 | # subtraction 43 | elif operation == "2": 44 | print(f"{first_number} - {second_number} = {subtraction(first_number, second_number)}") 45 | break 46 | # multiplication 47 | elif operation == "3": 48 | print(f"{first_number} × {second_number} = {multiplication(first_number, second_number)}") 49 | break 50 | # division 51 | elif operation == "4": 52 | print(f"{first_number} ÷ {second_number} = {division(first_number, second_number)}") 53 | break 54 | # exception 55 | else: 56 | print("Input was invalid, try again\n") 57 | continue 58 | 59 | # exception 60 | except ValueError: 61 | print("Enter a numeric value [1, 2.5, 7, etc.]\n") 62 | 63 | # feel free to keep practicing, here are some more ideas 64 | """ 65 | - simplify this calculator using lambdas 66 | - remove ".0" in float values for a cleaner look 67 | - hint: you can convert float data to string, use ".endswith" 68 | """ -------------------------------------------------------------------------------- /python3/module11/README.md: -------------------------------------------------------------------------------- 1 | # Module 0.11.0 - Object Oriented Programming 2 | - a programming style based on the use of classes and objects 3 | - a class is a blueprint for an object 4 | - an object is a variable created from a class's definition 5 | - object's have attributes and behaviors 6 | - an attribute is an object's properties 7 | - a behavior [or method] is what an object does 8 | 9 | ## 0.11.1 - Class's Put Into Context 10 | This will be our hypothetical for most of this lesson 11 | - let's say you are making a game with python 12 | - in this game, there will be different types of dogs 13 | - instead of individually programming each dog, we can create a blueprint or class that all the dogs can follow 14 | --- 15 | - let's say we make a dog class (or blueprint) 16 | - we will need to account for a dog's attributes and behaviors 17 | - the attributes of a dog: 18 | - name 19 | - color 20 | - breed 21 | - the behaviors of a dog 22 | - bark 23 | - they play fetch 24 | - move forward, backward, left, and right 25 | 26 | ## 0.11.2 - Creating A Class 27 | - "class" statement, creates a class 28 | - it is a good programming practice to make class's start with a capital letter 29 | - to differentiate them from functions and modules 30 | ``` 31 | # this is our "Dog" class 32 | class Dog: 33 | ``` 34 | - we now need to add our instance variables, these variables will contain the dogs' attributes 35 | - things like the dogs name and fur color 36 | - "\_\_init\_\_" method, *init*ializes instance variables to the class [init = initialize] 37 | - this "\_\_init\_\_" method is reffered to as the class constructor 38 | - class methods are structured like functions 39 | - **all methods** in a class take "self" as their first parameter 40 | - "self" parameter, an access point to the current instance of the class 41 | - the "self" parameter doesn't actually have to be called self, it's just good practice 42 | ``` 43 | # this is our "Dog" class 44 | class Dog: 45 | 46 | # init method, takes in the attributes "name" and "color" 47 | def __init__(self, name, color): 48 | self.name = name 49 | self.color = color 50 | ``` 51 | - we can now add our dog objects 52 | ``` 53 | duke = Dog("Duke", "White") 54 | sam = Dog("Sam", "Black") 55 | ``` 56 | - we can output and use the dog object's attributes 57 | ``` 58 | dog_tuple = (duke, sam) 59 | 60 | for dog in dog_tuple: 61 | print(f"{dog.name} has {dog.color} fur") 62 | 63 | >>> "Duke has White fur" 64 | >>> "Sam has Black fur" 65 | ``` 66 | 67 | ## 0.11.3 - Adding Behaviors 68 | - now that the dog objects have their own attributes, we can give them behaviors like barking or growling 69 | ``` 70 | # this is our "Dog" class 71 | class Dog: 72 | 73 | # init method, takes in the attributes "name" and "color" 74 | def __init__(self, name, color): 75 | self.name = name 76 | self.color = color 77 | 78 | # barking method 79 | def bark(self): 80 | print("Woof") 81 | 82 | # growling method 83 | def growl(self): 84 | print("Grrr") 85 | 86 | duke = Dog("Duke", "White") 87 | sam = Dog("Sam", "Black") 88 | 89 | duke.bark() 90 | sam.growl() 91 | 92 | >>> "Woof" 93 | >>> "Grrr" 94 | ``` 95 | - class's can also have attributes that are only accessible to the class 96 | - created by initializing variables in the class 97 | ``` 98 | # this is our "Dog" class 99 | class Dog: 100 | 101 | # class specific attribute 102 | legs = 4 103 | 104 | # init method, takes in the attributes "name" and "color" 105 | def __init__(self, name, color): 106 | self.name = name 107 | self.color = color 108 | 109 | # barking method 110 | def bark(self): 111 | print("Woof") 112 | 113 | # growling method 114 | def growl(self): 115 | print("Grrr") 116 | 117 | duke = Dog("Duke", "White") 118 | sam = Dog("Sam", "Black") 119 | 120 | duke.bark() 121 | sam.legs 122 | 123 | >>> "Woof" 124 | >>> 4 125 | ``` 126 | 127 | ## 0.11.4 - Inheritance 128 | - congrats, the game is sucessful upon it's release 129 | - eventually, people get tired of dogs, they want more animals like cats 130 | - now we could make another entire class for cats, but cat's have the same attributes as dogs, but different behaviours 131 | - for situations like this we can inherit attribues and behaviors from other class's. 132 | --- 133 | - a super class is a class that other class's [subclass's] can inherit from 134 | - let's make a super class called "Animal" 135 | ``` 136 | # this is our super class 137 | class Animal: 138 | ``` 139 | let's say that all of the animals in our game share these same attributes 140 | - name 141 | - color 142 | - breed 143 | ``` 144 | # this is our super class 145 | class Animal: 146 | # intialize our shared attributes 147 | def __init__(self, name, color, breed): 148 | self.name = name 149 | self.color = color 150 | self.breed = breed 151 | ``` 152 | - note that if an object doesn't have attributes or behaviours, you don't need to add them in the blueprint or class 153 | - let's make our animal subclass's 154 | - to inherit from a class, mention the super class's name in parenthesis "()" after the supclass 155 | ``` 156 | # this is our super class 157 | class Animal: 158 | # intialize our shared attributes 159 | def __init__(self, name, color, breed): 160 | self.name = name 161 | self.color = color 162 | self.breed = breed 163 | 164 | # this dog subclass inherits from our "Animal" super class 165 | class Dog(Animal): 166 | # we only need to initialize anything specific to dogs, no init needed 167 | 168 | # barking method 169 | def bark(self): 170 | print("Woof") 171 | 172 | # this cat subclass inherits from our "Animal" super class 173 | class Cat(Animal): 174 | # we only need to initialize anything specific to cats, no init needed 175 | 176 | # purring method 177 | def purr(self): 178 | print("Purr") 179 | ``` 180 | now we can make our animal objects 181 | ``` 182 | sam = Dog("Same", "Black", "Doberman") 183 | jasper = Cat("Jasper", "White", "American Bobtail") 184 | 185 | sam.bark() 186 | jasper.purr() 187 | 188 | >>> "Woof" 189 | >>> "Purr" 190 | ``` 191 | when a subclass inherits from a super class, behaviors or attributes with the same name are overwritten by the subclass 192 | ``` 193 | # this is our super class 194 | class Animal: 195 | # intialize our shared attributes 196 | def __init__(self, name, color, breed): 197 | self.name = name 198 | self.color = color 199 | self.breed = breed 200 | 201 | # superclass speaking method 202 | def speak(self): 203 | print("Rawr") 204 | 205 | # this dog subclass inherits from our "Animal" super class 206 | class Dog(Animal): 207 | # we only need to initialize anything specific to dogs, no init needed 208 | 209 | # bsubclass speaking method overwrites superclass speaking method 210 | # because they share the same name 211 | def speak(self): 212 | print("Woof") 213 | 214 | sam = Dog("Same", "Black", "Doberman") 215 | sam.speak() 216 | 217 | >>> "Woof" 218 | ``` 219 | 220 | ## 0.11.5 - More Advanced Topics 221 | - OOP [Object Oriented Programming] can get very complicated very quickly 222 | - due to this being a beginner friendly, cybersecurity focused, curriculem we will end the topic of OOP here 223 | - however, CosmodiumCS will be releasing an Advanced level Python course in the near future 224 | - here we will more advanced topics like generators, recursion, decorators, magic methods [dunders], hiding class data, class and static methods, properties, and more 225 | - until then, I will link some free and open source resources for if you wish to continue learning 226 | ``` 227 | Tech With Tim, Python OOP - 'https://www.youtube.com/watch?v=JeznW_7DlB0' 228 | W3Schools - 'https://www.w3schools.com/python/python_reference.asp' 229 | ``` 230 | -------------------------------------------------------------------------------- /python3/module11/m11-practice/Contact.py: -------------------------------------------------------------------------------- 1 | # contact module for 'main.py' 2 | 3 | # creates a class for contacts 4 | class Contact: 5 | 6 | # initialize instance variables 7 | def __init__(self, name, email, phone, database): 8 | self.name = name 9 | self.email = email 10 | self.phone = phone 11 | self.db = database 12 | 13 | # updates current database 14 | def updateDbLines(self): 15 | # reads current version of database 16 | read_db = open(self.db, "r").readlines() 17 | return read_db 18 | 19 | # updates current database 20 | def updateDatabase(self): 21 | # reads current version of database 22 | read_db = open(self.db, "r").read() 23 | return read_db 24 | 25 | # output profile 26 | def generateProfile(self): 27 | profile = f"\n=====\nName : {self.name}\nEmail : {self.email}\nPhone : {self.phone}\n=====" 28 | return profile 29 | 30 | # write profile to file 31 | def writeProfile(self, profile): 32 | read_db = self.updateDatabase() 33 | # writes profile to database 34 | with open(self.db, "w") as contact_db: 35 | contact_db.write(f"{read_db}\n{profile}") 36 | 37 | # remove profile from file 38 | def removeProfile(self, profile): 39 | updated_db = "" 40 | read_db = self.updateDbLines() 41 | # iterates through database of contacts 42 | for contact in read_db: 43 | # checks if the contact exists 44 | if contact in profile: 45 | continue 46 | # writes all existing contact info that isn't part of the contact 47 | else: 48 | updated_db += contact 49 | # write updated database 50 | with open(self.db, "w") as db: 51 | db.write(updated_db) 52 | 53 | # output contact 54 | def outputProfiles(self): 55 | read_db = self.updateDatabase() 56 | return read_db 57 | 58 | # main code 59 | def main(): 60 | print("Please run 'main.py'") 61 | 62 | # checks running type 63 | if __name__ == "__main__": 64 | main() -------------------------------------------------------------------------------- /python3/module11/m11-practice/__pycache__/Contact.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CosmodiumCS/OpenCourse/01a97b365a14be60b4e1e976d04169b0ff05e897/python3/module11/m11-practice/__pycache__/Contact.cpython-39.pyc -------------------------------------------------------------------------------- /python3/module11/m11-practice/contacts.txt: -------------------------------------------------------------------------------- 1 | Name : cosmo 2 | Email : mail 3 | Phone : 222 4 | -------------------------------------------------------------------------------- /python3/module11/m11-practice/main.py: -------------------------------------------------------------------------------- 1 | # for this module's practice: 2 | # we will be building a contact page [phonebook] 3 | 4 | # import contact script, "c" 5 | from Contact import Contact as c 6 | 7 | def add_contact(info, profile): 8 | info.writeProfile(profile) 9 | return f"The profile:{profile}\nWas added" 10 | 11 | def remove_contact(info, profile): 12 | info.removeProfile(profile) 13 | return f"The profile:{profile}\nWas removed" 14 | 15 | def edit_contact(option, db): 16 | # user input, name, email, phone 17 | if option == "1" or option == "2": 18 | name = input("Enter Contact's Name : ") 19 | email = input("Enter Contact's Email : ") 20 | phone = input("Enter Contact's Phone Number : ") 21 | 22 | # class object 23 | contact_information = c(name, email, phone, db) 24 | # generates phone profile for editing database 25 | phone_contact = contact_information.generateProfile() 26 | 27 | # option 1, adds contact 28 | if option == "1": 29 | print(add_contact(contact_information, phone_contact)) 30 | return True 31 | # option 2, removes contact 32 | elif option == "2": 33 | print(remove_contact(contact_information, phone_contact)) 34 | return True 35 | # option 3, outputs contacts 36 | elif option == "3": 37 | read_db = open(db).read() 38 | print(read_db) 39 | return True 40 | # exception 41 | else: 42 | print("Invalid argument added") 43 | return False 44 | 45 | # main code 46 | def main(): 47 | # loops code, in case of exception 48 | while True: 49 | # databse 50 | database = "contacts.txt" 51 | 52 | # banner 53 | print("Phone Book") 54 | 55 | # options menu 56 | print("Choose an option:\n1) Add Contact\n2) Remove Contact\n3) Display Contacts\n") 57 | # user input, option 58 | option = input("Option : ") 59 | # handles contact info, depending on option 60 | process = edit_contact(option, database) 61 | 62 | # detects if process was sucessful 63 | if process == True: 64 | break 65 | else: 66 | continue 67 | 68 | # checks running type 69 | if __name__ == "__main__": 70 | main() 71 | 72 | # feel free to keep practicing, here are some more ideas 73 | """ 74 | - allow users to store addresses 75 | - optimize previous projects with your new found knowledge 76 | """ -------------------------------------------------------------------------------- /usb-rubberducky/README.md: -------------------------------------------------------------------------------- 1 | # USB Rubber Ducky Book Notes 2 | > Blue Cosmo | 05/17/2021 3 | 4 | ## Resources 5 | notes drawn from: 6 | ``` 7 | USB Rubber Ducky, 'A GUIDE TO KEYSTROKE INJECTION ATTACKS' 8 | By: Darren Kitchen, Hak5 9 | ``` 10 | ## Module 1 - Keystroke Injection Attacks 11 | - relies on inherent trust 12 | - keyboards 13 | - human operations 14 | - rely on keyboard rather than GUI [Graphic User Interface] 15 | ``` 16 | xcopy documents\*.txt d:\ 17 | ``` 18 | above will copy all ".txt" files in the documents directory, moves them to "d" drive 19 | - rather than moving each file manually 20 | 21 | ## Module 2 - The USB Rubber Ducky 22 | - keystroke injection tool, programmable keyboard 23 | - remote access 24 | - back doors 25 | - reconnaissance 26 | - exfiltration 27 | - 1000 WPM [Words Per Minute] 28 | 29 | ## Module 3 - Anatomy of the Duck 30 | 31 | Payloads 32 | - tells the ducky what to do 33 | 34 | Ducky Script 35 | - scripting language for ducky 36 | 37 | Ducky Encoder 38 | - encodes payloads into injectable code for the ducky 39 | 40 | Inject.bin 41 | - the encoded version of a payload file 42 | 43 | Firmware 44 | - the code running on the ducky's CPU [Central Processing Unit] 45 | 46 | ### Hardware Overview 47 | Micro SD card Reader 48 | - supports up to 2GB [Gigabyte] SD cards 49 | 50 | Micro Push Button 51 | - used to replay payload [one press] or flash firmware [press and hold upon plugin] 52 | 53 | Multi-color LED Indicator 54 | - green - payload is running successfully 55 | - red - error 56 | 57 | Standard USB Type A Connector 58 | - connects ducky to most computers [adapters can be used] 59 | 60 | Generic Flash Drive Case 61 | - houses ducky 62 | 63 | ## Module 4 - The Attack Workflow 64 | Pre-engagement Interactions 65 | - allows for a better understanding for your targets/clients environment 66 | - hardware 67 | - software 68 | - network 69 | 70 | Reconnaissance 71 | - get a better understanding of the systems and challenges you may face 72 | 73 | Target 74 | - know your objective 75 | 76 | Research 77 | - understand the most effective way to achieve that objective 78 | 79 | Write 80 | - create the payload in an effective manner 81 | 82 | Encode 83 | - allow for it to be ran by the ducky 84 | 85 | Test 86 | - see how well it works 87 | 88 | Optimize 89 | - make it more efficient based on testing results 90 | 91 | Deploy 92 | - once the payload is as effective as it can be, it is ready for use 93 | 94 | ## Module 5 - Ducky Script 95 | - see 'ducky-syntax.md' for full syntax list 96 | 97 | ## Module 6 - Payload Principles 98 | 1. Speed 99 | - payloads need to be fast, every second counts 100 | - instead of using GUI, keyboard shortcuts and typing is faster and more affective 101 | 102 | 2. Stages 103 | - ducky payloads can be 'inline' or 'staged' 104 | 105 | Inline 106 | - complete objective in one payload, no external resources necessary 107 | 108 | Staged 109 | - the payload works in stages, or steps 110 | 111 | 3. Resources 112 | - requires external resources 113 | 114 | ## Module 7 - Writing Your First Payload 115 | Objective 116 | ``` 117 | open notepad and enter 'Hello, World!' 118 | ``` 119 | Research 120 | - how do we open notepad effeciently 121 | - start menu 122 | - runbox <-- 123 | - how many delays do we need 124 | 125 | Write 126 | ``` 127 | REM opens notepad and enter 'Hello, World!' 128 | 129 | DELAY 1000 130 | GUI r 131 | DELAY 100 132 | STRING c:\windows\notepad.exe 133 | DELAY 1000 134 | STRING Hello, World! 135 | ``` 136 | 137 | Encode 138 | - use ducky encoder to encode payload 139 | - java 140 | - python 141 | - online 142 | 143 | Java 144 | - using the java duck encoder 145 | ``` 146 | java -jar duckencoder.jar 147 | java -jar duckencoder.jar -i payload.txt -o inject.bin 148 | ``` 149 | 150 | Python 151 | - using python duck encoder 152 | ``` 153 | python3 duckencoder.py 154 | python3 duckencoder.py -i payload.txt -o inject.bin 155 | ``` 156 | 157 | Online 158 | - use 'https://ducktoolkit.com/encode' to encode payload 159 | 160 | Test 161 | - delays too long 162 | - unnecessary string text 163 | 164 | Optimize 165 | ``` 166 | REM opens notepad and enter 'Hello, World!' 167 | 168 | DELAY 1000 169 | GUI r 170 | DELAY 100 171 | STRING notepad 172 | DELAY 400 173 | STRING Hello, World! 174 | ``` 175 | 176 | ## Module 8 - Obfuscation & Optimization 177 | Obfuscation 178 | - reducing the visibility of the payload 179 | 180 | > Example - Hiding CMD [Command Prompt] 181 | ``` 182 | REM assuming we have a CMD open, we have to obfuscate it 183 | 184 | REM this will make the CMD have yellow text, white background 185 | STRING color FE 186 | ENTER 187 | 188 | REM this will reduce the CMD window size 189 | STRING mode con:cols=18 lines=1 190 | ENTER 191 | ``` 192 | 193 | Optimization 194 | - making the payload faster and more effective 195 | 196 | > Example - start a obfuscated CMD 197 | ``` 198 | REM assuming we have a runbox open, start an obfuscated CMD 199 | STRING cmd /c color FE&mode con:cols=18 lines=1&ipconfig 200 | ENTER 201 | ``` 202 | 203 | - what would be multiple lines and take long, now only takes ~3 seconds 204 | 205 | > Example - start a minimized CMD, autoruns command 206 | ``` 207 | REM assuming we have a runbox open, start a minimized CMD 208 | STRING cmd /c "start /min cmd /c ipconfig" 209 | ENTER 210 | ``` 211 | -------------------------------------------------------------------------------- /usb-rubberducky/ducky-syntax.md: -------------------------------------------------------------------------------- 1 | # USB Rubber Ducky Syntax 2 | > Blue Cosmo | 05/17/2021 3 | 4 | ## To be Noted 5 | - BASIC based 6 | - commands are in all caps 7 | - attributes are lowercase 8 | - Delays are measured in milliseconds, 1 second = 1000 milliseconds 9 | 10 | ## REM 11 | - remark or comment, attributes are not processed 12 | ``` 13 | REM this will not be ran 14 | STRING this will be typed 15 | ``` 16 | 17 | ## DEFAULT_DELAY | DEFAULTDELAY 18 | - creates a default delay between commands 19 | ``` 20 | REM there will be a one second delay between commands 21 | DEFAULT_DELAY 1000 22 | GUI r 23 | STRING notepad 24 | ``` 25 | 26 | ## DELAY 27 | - creates a single delay 28 | ``` 29 | REM this will delay for one second 30 | DELAY 1000 31 | GUI r 32 | 33 | REM this will delay for half a second 34 | DELAY 500 35 | STRING notepad 36 | ``` 37 | 38 | ## STRING 39 | - inputs text 40 | ``` 41 | REM this will type 'Hello, World!' 42 | STRING Hello, World! 43 | ``` 44 | 45 | ## GUI | WINDOWS 46 | - acts as the special key [windows key] 47 | ``` 48 | REM this will lock your screen 49 | GUI l 50 | ``` 51 | 52 | ## MENU | APP 53 | - right click 54 | ``` 55 | REM this will paste the users clipboard 56 | MENU 57 | STRING p 58 | ``` 59 | 60 | ## SHIFT 61 | - holds down 'shift' key along with any selected key 62 | ``` 63 | REM this will paste the users clipboard 64 | SHIFT INSERT 65 | ``` 66 | 67 | ## ALT 68 | - holds down 'alt' key along with any selected key 69 | ``` 70 | REM this will close the open window 71 | ALT F4 72 | ``` 73 | 74 | ## CONTROL | CTRL 75 | - holds down 'control' key along with any selected key 76 | ``` 77 | REM this will select all and add content to clipboard 78 | CTRL a 79 | CONTROL c 80 | ``` 81 | 82 | ## ARROW KEYS 83 | - each direction hits each respective arrow key 84 | ``` 85 | REM 'DOWNARROW' or 'DOWN' will hit the down arrow 86 | REM 'UPARROW' or 'UP' will hit the up arrow 87 | REM 'LEFTARROW' or 'LEFT' will hit the left arrow 88 | REM 'RIGHTARROW' or 'RIGHT' will hit the right arrow 89 | ``` 90 | 91 | ## OTHER COMMANDS 92 | ``` 93 | REM 'BREAK' or 'PAUSE' will hit pause 94 | REM 'CAPSLOCK' will hit the 'caps lock' key 95 | REM 'DELETE' will hit the 'delete' key 96 | REM 'END' will hit the 'end' key 97 | REM 'ESC' or 'ESCAPE' will hit the 'escape' key 98 | REM 'HOME' will hit the 'home' key 99 | REM 'INSERT' will hit the 'insert' key 100 | REM 'NUMLOCK' will hit the 'num lock' key 101 | REM 'PAGEUP' will hit the 'page up' key 102 | REM 'PAGEDOWN' will hit the 'page down' key 103 | REM 'PRINTSCREEN' will hit the 'print screen' key 104 | REM 'SCROLLOCK' will hit the 'scroll lock' key 105 | REM 'SPACE' will hit the 'space' bar 106 | REM 'TAB' will hit the 'tab' key 107 | ``` 108 | -------------------------------------------------------------------------------- /wifi-pineapple/README.md: -------------------------------------------------------------------------------- 1 | # Wifi Pineapple Book Notes 2 | > Blue Cosmo | 08/26/21 3 | --- 4 | 5 | ## Resources: 6 | notes drawn from: 7 | ``` 8 | Wifi Pineapple, 'A GUIDE TO THE TOP AUDITING TOOLKIT' 9 | ``` 10 | - note that notes are modified to the MkVII 11 | 12 | ## Module 1 - Pineapple What? 13 | - wifi auditing tool 14 | - passively gather intel 15 | - rouge access points 16 | - man in the middle 17 | 18 | ## Module 2 - Wifi Audit Workflow 19 | - Pre-Engagement Interactions 20 | - determine scope and rules 21 | - Intelligence Gathering 22 | - reconaissance 23 | - Vulnerability Analysis 24 | - find possible attack vectors 25 | - Exploitation 26 | - exploit said vectors 27 | - Post Exploitation 28 | - persistance, pivot attack 29 | - Reporting 30 | - report on vulnerabilites and issue within the network to better client's security 31 | --- 32 | - PineAP Workflow 33 | - Recon 34 | - gather intel on the 'wireless landscape' 35 | - Filter 36 | - limit collateral damage 37 | - Log 38 | - keep track of wireless actions 39 | - Analyze 40 | - determinie your targets 41 | - Capture 42 | - a pool of SSIDs 43 | - Prepare 44 | - setup how attacks will be conducted 45 | - Test 46 | - ensure attack sucess 47 | - Broadcast 48 | - advertise SSIDs to nearby devices 49 | - Associate 50 | - filter specific targets 51 | - Deauthenticate 52 | - encourage devices to join your network 53 | - Monitor/Manipulate 54 | - monitor traffic or manipulate connections 55 | - Report 56 | - summarize attack workflow 57 | 58 | ## Module 3 - Basics of Wifi Operation 59 | - learn, know, and understand the basics of wifi and wifi hacking 60 | 61 | ## Module 4 - The PineAP Suite 62 | the 'engine' for the Pineapples hacking abilities 63 | 64 | ## Module 5 - Hardware Overview 65 | we will skip this one due to them being specific to the TETRA and NANO 66 | 67 | ## Module 6 - Wifi Pineapple Setup 68 | 1. connect to 2-Amp USB powersource 69 | 2. join the "Pineapple_XXXX" Wi-Fi network 70 | 3. browse to *http://172.16.42.1:1471* and follow the on-screen instructions 71 | 72 | ## Module 7 - Setup From Android 73 | specific to TETRA and NANO 74 | - however, because the MkVII works through the web, it is accessible on practically any device 75 | 76 | ## Module 8 - Connectiong to The Internet 77 | we will skip this one due to them being specific to the TETRA and NANO 78 | 79 | ## Module 9 - The Web Interface 80 | if your Pineapple is connected sucessfully than you can access the web interface [here](http://172.16.42.1:1471) 81 | 82 | ## Module 10 - Wifi Pineapple Modules 83 | - the wifi pineapple is designed to be modular 84 | - community members can contribute modules to this [repository](https://github.com/hak5/mk7-modules) 85 | 86 | ## Module 11 - Shell Access And Upgrades 87 | - remote acces for the MkVII is carried through CloudC2 and the Web Interface 88 | --- 89 | ssh 90 | ``` 91 | ssh root@172.16.42.1 92 | ``` 93 | serial 94 | ``` 95 | flowcontrol: none 96 | baudrate: 115200 97 | parity: none 98 | databits: 8 99 | stopbit: 1 100 | ``` --------------------------------------------------------------------------------