Notes, summaries, assignments, exams, and exercises for Computer science for Other courses

Python Tuples: Essential Concepts and Operations

Computer science2.38 KB

Introduction to Tuples

  • Immutable: Cannot be changed after creation.
  • Syntax: Defined using parentheses ().
  • Versatile: Can store multiple data types.
  • Performance: Faster than lists due to immutability.

Common Use Cases for Tuples

  • Returning multiple values: Functions can return multiple values as a tuple.
  • Representing records: Ideal for structured data like names, ages, and addresses.
  • Dictionary keys: Tuples can be used as keys in dictionaries.

Basic Tuple Operations

Length

Returns the number of elements in the tuple.
Example: len((1, 2, 3)) Output: 3

Repetition

Repeats the tuple a specified number of times.
Example: (1, 2) * 3 Output: (1, 2, 1, 2, 1, 2)

Iteration

Loop through elements of a tuple.
Example: for x in (1, 2, 3): print(x) Output: 1, 2, 3

Comparison

...
Continue reading "Python Tuples: Essential Concepts and Operations" »

C TCP Sliding Window Client Example with Timeout

Computer science3.49 KB

C TCP Sliding Window Client Example

Source code with timeout and acknowledgment handling

Note: This example demonstrates socket programming in C using a sliding window and a receive timeout. It sends numbered frames, waits for acknowledgments, and resends frames on timeout.

Key points

  • Uses setsockopt to set a receive timeout (SO_RCVTIMEO)
  • Sends sequential frames and handles acknowledgments
  • Resends a window of frames when acknowledgments are not received
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
...
Continue reading "C TCP Sliding Window Client Example with Timeout" »

Nmap, Netcat, and Metasploit Commands Cheat Sheet

Computer science7.67 KB

Nmap Options

-PE: Quickly check if host is up.

-sn: Disable port scanning (host discovery).

-n: Disables DNS resolution (checks IP online without looking up hostnames).

-O: OS detection.

-A: OS detection, Version detection, Script scanning, traceroute.

-sV: Service detection (banner info, version).

-vV: Provides verbose output.

-sC: Scan with default scripts for additional info gathering.

--min-rate=5000: Ensures scan sends at least 5k packets per second.

nmap --script smb-enum-shares.nse -p 445 (ip): List shares and their properties.


To see scripts starting with X: ls /path/X

To execute script with script tracing: sudo nmap -script=smb-os-discovery -script-trace target_ip

To enumerate the SMB share files: sudo nmap -script=smb-enum-shares target_ip

Vulnerability...

Continue reading "Nmap, Netcat, and Metasploit Commands Cheat Sheet" »

Mastering Stacks, Deques, Trees, and Graph Data Structures

Computer science21.54 KB

A stack is a fundamental data structure in computer science that follows the Last In, First Out (LIFO) principle. This means that the last element added to the stack is the first one to be removed. You can think of it like a stack of plates: you can only add or remove the top plate.

### Key Concepts of a Stack:

1. Basic Operations:
   - Push: This operation adds an element to the top of the stack.
   - Pop: This operation removes the element from the top of the stack and returns it.
   - Peek (or Top): This operation returns the top element of the stack without removing it.
   - IsEmpty: This operation checks whether the stack is empty.

2. Implementation:
   Stacks can be implemented using arrays or linked lists. Here are the details for...

Continue reading "Mastering Stacks, Deques, Trees, and Graph Data Structures" »

Python Regex Essentials & Understanding 'self' in OOP

Computer science2.55 KB

Python Regular Expressions: Pattern Matching Power

Regular expressions (regex) are a powerful tool for pattern matching and text manipulation. They allow you to search for patterns within strings, extract specific information, and perform text transformations. Python provides the re module for working with regular expressions.

Basic Regular Expression Components

  1. Literals: Characters that match themselves.
  2. Metacharacters: Special characters with special meanings, such as . (matches any character) and * (matches zero or more occurrences).
  3. Character Classes: [...] matches any single character within the brackets.
  4. Anchors: ^ matches the start of a string, $ matches the end of a string.
  5. Quantifiers: * matches zero or more occurrences, + matches one or
...
Continue reading "Python Regex Essentials & Understanding 'self' in OOP" »

Programming Language Basics & Database Models

Computer science3.29 KB

Programming Language Fundamentals

Level Classification

  • Low Level: Resembles the language used by the computer directly.
  • High Level: Resembles human language, abstracting machine details.

Generations of Programming Languages

  • 1st Generation (1GL): Machine Language
  • 2nd Generation (2GL): Assembler
  • 3rd Generation (3GL): High-level languages (e.g., Fortran, Pascal, C, C++, Cobol)
  • 4th Generation (4GL): Languages for specific purposes (e.g., web development, PHP, Java, HTML)

Key Programming Concepts

Program

A set of instructions or orders based on a programming language that a computer interprets to solve a problem or perform a specific function.

Programming Language

Tools that allow us to create programs and software. An artificial language used to define a sequence...

Continue reading "Programming Language Basics & Database Models" »

Computer Architecture Fundamentals: Bits, Bytes, and Components

Computer science3.1 KB

Computer Architecture Basics

Item 1: Is that a bit?

1. What is a Bit?

The binary digit.

2. What values can a bit take?

1 or 0.

5. How many bits is a nibble?

4 bits.

6. How many bits is a byte?

8 bits.

7. How many bits is a word?

16 bits.

8. How many bits has a doubleword?

32 bits.

9. How many bits has a quadword?

64 bits.

Central Processing Units and Computers

10. What is a microprocessor?

One central processing unit (CPU) integrated into a single chip.

11. What is a microcomputer?

A printed circuit board with a microprocessor, memory, and ports.

12. What is a microcomputer (alternative definition)?

A printed circuit board with a microprocessor where cards can be added or removed.

13. What is a computer?

A printed circuit board with a central microprocessor, where

...

Continue reading "Computer Architecture Fundamentals: Bits, Bytes, and Components" »

Data, Information, and Network Communication Essentials

Computer science4.25 KB

Data

Data is the collection of facts considered in isolation. It describes an organization and carries meaning, but generally is not useful by itself.

Information

Information is data that has been manipulated and is useful to someone. Information must have value; otherwise, it would be considered just data. Information tells people something that confirms what they knew or suspected. (What, who, and when?)

Why? Because telecommunication networks transmit data, the networks do not identify meanings (information). The objective of networking is to take data from one place to another.

Data Types

  • Analog: Continuous
  • Digital: Discrete

Symbols limited by their use and origin:

  • Alphanumeric
  • Graphic
  • Image
  • Audio
  • Video
  • Multimedia

Model of a Basic Communication System

Components:...

Continue reading "Data, Information, and Network Communication Essentials" »

Secure Internet Connections: SSL, PGP, PPTP, and IPsec

Computer science2.93 KB

Secure Sockets Layer (SSL)

Secure Sockets Layer (SSL) is most often used to encrypt information on the Internet. It is a protocol that encrypts database (DB) connections by selecting an encryption method and generating the necessary keys for the entire session.

How SSL Works

  1. The browser requests a page from a secure server. The request is identified by the HTTPS protocol.
  2. They agree on algorithms that ensure confidentiality, integrity, and authenticity.
  3. The server sends the browser its standard X509 certificate containing its public key. If the application requires it, it in turn requests the client's certificate.
  4. The browser sends the server a master key from which it generates the session key to encrypt data to be exchanged.
  5. Finally, it checks the
...
Continue reading "Secure Internet Connections: SSL, PGP, PPTP, and IPsec" »

Troubleshooting Nero 7 DVD Burning Errors and Logs

Computer science1.36 KB

System and Software Configuration

OS: Windows XP 5.1 (IA32)
Nero Version: 7.2.0.3 (Nero Express)
Recorder: TSSTcorp CD/DVDW SH-S182D (Firmware: SB04)

Hardware Map

  • Disk: SAMSUNG HD161HJ (Port 0, ID 0)
  • CD/DVD Drive: TSSTcorp CD/DVDW SH-S182D (Port 2, ID 0)

Burning Process Logs

Step 1: Image Creation

The image creation process completed successfully. The system utilized Disc-At-Once (DAO) mode for the DVD-R media.

Step 2: Burn Process Failure

The burning process failed during the finalization stage. Below are the critical error details:

  • Error Code: NeroError(-1176)
  • Sense Key: 0x03 (KEY_MEDIUM_ERROR)
  • Sense Code: 0x72
  • Issue: Session fixation error

Technical Diagnostics

The log indicates a Medium Error during the write process at 18x speed. The drive reported a...

Continue reading "Troubleshooting Nero 7 DVD Burning Errors and Logs" »