Javascipt version
Javascript have the function that reverse the String, so it is pretty easy to do in js.
1 | /** |
Java version
This java version is not prefect through, I have not handle the overflow.
1 | public class Solution { |
Javascript have the function that reverse the String, so it is pretty easy to do in js.
1 | /** |
This java version is not prefect through, I have not handle the overflow.
1 | public class Solution { |
A simple nested for loop
1 | /** |
HashMap have much better search time than a normal queue loop
1 | /** |
1 | public class Solution { |
update at 15-8-2021, review what I know about Vue
There are total 12 commands in Vue(More now, but I only know 12)
Passing a data to html, we can use v-bind
, it can pass the object and array to html:<div v-bind:class="[activeClass, errorClass]"></div>
v-once use when the data will never change, This can be used to optimise update performance
1 | const app = Vue.createApp({ |
or
1 | var app = new Vue({ |
v-on
can replace by @
, for example v-on:click="functionName"
=== @click="functionName"
Used in <div>
, for example:
1 | <div id="app"> |
v-bind is used when attribute in vue instance is needed,
When we try to:<a href={{website}}>some website<a>
It won’t work
we need to use v-bind
:<a v-bind:href={{website}}>some website<a>
v-bind
can be replaced by :
<a :href={{website}}>some website<a>
Just another if-else statement, but there are a notice able use case:
1 | <button @click="function"> |
To show an array of data, we need to use v-for
1 | books:[ |
1 | <ul> |
802.11 is the Wi-Fi(Wireless Fidelity) Alliance
The purpose of WEP:
Problem of WEP:
WEP is publiced at 1997 and design flawed at 2000
Authentication flaws:
New security architecture 802.11i designed to replace WEP during 2003-2004
WPA2/3 should be used
TKIP
AES-CCMP
Three roles of EAP
Sub-phases:
Connect to AS -> EAP exchange -> Secure key delivery(AS generates a master session key and sends it to STA)
Deals with object creation mechanisms
A class of which only a single instance can exist
Application needs one, and only one, instance of an object.
1 | public final class singleton{ |
Pros: Initialised on first call to avoid memory wastage.
Cons: locks must be added to ensure thread safety, and adding locks will affect performance.
1 | public class Singleton { |
1 | public class Singleton { |
Complex objects can be created directly without the user knowing the construction process and details of the object.
Solves the Telescoping Problem.
Product object
1 | public class Computer{ |
A Builder(interface or abstract class)
1 | public abstract class Builder { |
Concrete Builder(extend the Builder)
1 | //装机人员1 |
Director object
1 | public class Director{ |
Creating duplicate object while keeping performance in mind. The operation will directly clone a object in the ram. RAM’s I/O is much faster than storage.
In the factory pattern, we create objects without exposing the creation logic to the public and by using a common interface to point to the newly created object.
There’re two type of Factory Pattern
1 | public interface Dog{ |
1 | public class DogFactory{ |
…write later…
The Goals of computer security include confidentiality, data integrity, service availability.
When a program is executed, both code and data will be copied to ram.
Heap is used to stored dynamic data.
Stack is used to stored local variables, static variables and return address
When copying data into a buffer, the length of the data exceeds the remaining space in the buffer. Normally, buffer overflow data will only corrupt program data and cause unexpected termination. But if someone carefully constructs the contents of the overflow data, then it is possible to gain control of the system
By Buffer Overflow Attacks, When using the unsafe strcpy/gets function, the system will blindly copy the entire data of data into the memory area pointed to by buffer. buffer has a finite length and once the data of data exceeds BUF_LEN, a buffer overflow will occur.
Overflow the buffer with malicous (shell code), overwrite the return address to the shellcode. The function will return to the shellcode instead of the function caller
username: "or""="
password: "or""="
Then the SQL will beSELECT * FROM Users WHERE Name = "" or ""="" AND Pass ="" or ""=""
This will always return true
Attackers ping a machine with a very fast rate, the server will be too busy.
It is Theoretically possible, but not realistic because the basic version of ping-of-death is not an efficient attacks.
A typical ICMP packet is 64 bytes only, and do not expect packet larger than 65535(max size of ipv4). The server might encounter a buffer-overflow.
In TCP three-ways handshaking requires server to respond. The server will response a SYN-ACK to the client. We might issue a lot of SYN request to the server.
Both ping and SYN can be blacklisted
The IP packet header stores the routing information of a packet. IP Spoofing refer to generate a fake random source IP address. That makes server cannot block SYN packet directly.
IPSec can be used to assert the correctness of IP header, but it cannot be used to prevent SYN Flooding.
Some protocols use UDP instead of TCP connect. For example, Network Time protocol and Domain name service.
Attackers can make requests for large vlumes of replies from these service while putting the victims’s IP addresses as the source addresses.
Real life example: Prank call to a restaurant to order 10 people takeaway and ask them to deliver to a victim’s home.
Upgrade version of a DoS attack. Attackers controls a lot of devices to DoS attack the victim. Since packets are sent frm different direction, it is not easy block the packets.
Return a fake/false entry on a DNS server.
Timing is important, for accurately.
Due to the structural differences between servers, different time drifts are generated after a period of time, so that the physical clocks of different servers differ to some extent. As a direct result, event A may occur in a later order than event B, but the timestamp sent over is indeed less than B. If the synchronisation of state is involved B’s data will overwrite A’s data, which we don’t want to see.
Electronic devices that count oscillations occuring in a crystal at a frequency.
Operating System reads the hardware clock value.
Not perfect
Synchronize a group of clocks with an authoritative external source of time
For example, UTC: Coordinated Universal Time
Network Time Protocol(NTP)
Process Time: t+T(round)/2
Synchronize between a group of computer. A coordinator computer is chosen to be the master. Other computers are slaves. Master periodically polls the slaves, and the slaves send back their clock values.
Evaluated by:
All pairs of conflicting operations of the two transactions be executed in the same order
FIFO?
Java synchronized is an implementation of pessimistic locking, where every time a thread wants to modify data it first obtains a lock, ensuring that only one thread can manipulate the data at any one time, while the others are blocked.
Optimistic Lock
Timestamp/version
When the update is committed, check the timestamp of the data in the current database and compare it with the timestamp you got before the update, if it is the same then it is OK, otherwise it is a version conflict.
Deadlock
Read/Write Locks
Checks “conflict operations” before commit
If yes, aborts it and the client may restart
Record the most recent time of reading and writing of each object
Compare timestamp => determine it can be done immediately or must be delayed or rejected.
VPN is Network Layer(IP); Proxy is Transport Layer(TCP/UDP)
IPSec aka IP Security. Its purpose is to provide high security features for IP, and VPNs are solutions that arise from the way this security is achieved. ipsec is a framework architecture, consisting of two specific types of protocols.
Why is AH less used? Because AH cannot provide encrypt. Also, AH cannot pass NAT network(because the authenticate function)
Of course, IPSec can use both AH and ESP to achieve the most complete security features in extreme cases, but such solutions are extremely rare.
Strict-Transport-Sceurity: max-age=31536000
Here is some concept summary of my mid-term. Those maths and case is excluded.
I should understand how the following attack happen:
Symetric has no hard problem, all depands on the key size. When we talk about symetric, We usually use AES. DES and 3DES should not be use anymore. Symetric is much faster than Asymmetric(10-100times).
Avalanclve effect: Small change in bit will lead to big change of the output.
Asymmetric is a Trapdoor function, everyone can lock but only private key can unlock.
Famous Hash:
大集合映射到小集合, collision必然會發生
H(P||s) for salt
Goal:
MAC requies a key to verify
Make Message can be publity verfiable
Example of Digital Signatures:
Mac is faster than DS, MAC only need a hash function.
Ways to distibution a key:
Certificate:
Use dellit-hellman Algorithms
Key agreement: both parties contribute some information
Perfect forward secrecy
Session Key: session key per each commanication session
Authenticated: is able to confirm the identity of the partner
Absent of Secure channel: do not need pre-share secure channel