Skip to content

Commit 4c1ba36

Browse files
authored
Merge branch 'main' into PradnyaGaitonde-patch-30
2 parents e55f103 + 07f08aa commit 4c1ba36

File tree

12 files changed

+596
-6
lines changed

12 files changed

+596
-6
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: 'Cryptography and Its Use in Cyber Security'
3+
sidebar_label: Cryptography and Cyber Security
4+
authors: [pujan-sarkar]
5+
tags: [cryptography, cyber security, encryption, technology]
6+
date: 2024-06-24
7+
hide_table_of_contents: true
8+
---
9+
10+
## Introduction
11+
12+
In the realm of cyber security, cryptography stands as a critical tool for protecting information. As digital data exchange grows exponentially, the importance of cryptography in ensuring data security and privacy cannot be overstated. This blog explores the fundamental concepts of cryptography, its historical significance, and its contemporary applications in cyber security.
13+
14+
## Understanding Cryptography
15+
16+
Cryptography is the science of encoding and decoding information to protect it from unauthorized access. It involves various techniques and algorithms that transform readable data, known as plaintext, into an unreadable format, known as ciphertext. Only those who possess the appropriate decryption key can convert the ciphertext back into plaintext.
17+
18+
### Key Concepts in Cryptography
19+
20+
1. **Encryption and Decryption**: The process of converting plaintext into ciphertext is called encryption, while the process of converting ciphertext back into plaintext is called decryption.
21+
2. **Symmetric Key Cryptography**: The same key is used for both encryption and decryption. Examples include AES and DES.
22+
3. **Asymmetric Key Cryptography**: Uses a pair of keys - a public key for encryption and a private key for decryption. Examples include RSA and ECC.
23+
4. **Hash Functions**: Take an input and produce a fixed-size string of characters, which is typically a hash value. Hash functions are used for data integrity and password storage.
24+
25+
## Historical Significance of Cryptography
26+
27+
Cryptography has been used for centuries to secure communication. Some historical milestones include:
28+
29+
- **Caesar Cipher**: Used by Julius Caesar to protect military messages, this substitution cipher shifts letters by a fixed number of positions in the alphabet.
30+
- **Enigma Machine**: Used by the Germans during World War II, this electromechanical device encrypted messages. The successful decryption of Enigma-encrypted messages by the Allies significantly impacted the war's outcome.
31+
- **Diffie-Hellman Key Exchange**: Introduced in 1976, this method allowed secure key exchange over a public channel, laying the groundwork for modern public-key cryptography.
32+
33+
## Cryptography in Modern Cyber Security
34+
35+
In today's digital world, cryptography is essential for securing data and maintaining privacy. Its applications are vast and varied:
36+
37+
### Secure Communication
38+
39+
Cryptography ensures that communication between parties remains confidential and secure. Protocols like SSL/TLS use cryptographic techniques to protect data transmitted over the internet, such as during online banking and shopping.
40+
41+
### Data Integrity
42+
43+
Hash functions play a crucial role in ensuring data integrity. When data is transmitted or stored, hash functions can verify that the data has not been altered. This is particularly important for software distribution and digital signatures.
44+
45+
### Authentication
46+
47+
Cryptographic methods are used to verify the identities of users and devices. Passwords are typically stored as hash values, and public-key infrastructure (PKI) systems use digital certificates to authenticate entities.
48+
49+
### Blockchain Technology
50+
51+
Cryptography is the backbone of blockchain technology. Cryptographic hashing ensures the integrity of data blocks, while asymmetric cryptography secures transactions and verifies identities. This technology underpins cryptocurrencies like Bitcoin and has applications in various fields, including supply chain management and healthcare.
52+
53+
### Secure Storage
54+
55+
Encrypting data at rest ensures that even if unauthorized individuals gain access to storage media, they cannot read the data without the decryption key. This is crucial for protecting sensitive information on devices and in cloud storage.
56+
57+
## Challenges in Cryptography
58+
59+
While cryptography is a powerful tool, it is not without challenges:
60+
61+
- **Key Management**: Securely generating, storing, and distributing cryptographic keys is complex and critical for maintaining security.
62+
- **Performance Overheads**: Cryptographic operations can be computationally intensive, affecting system performance, especially in resource-constrained environments.
63+
- **Quantum Computing**: Emerging quantum computers have the potential to break many of the cryptographic algorithms currently in use, necessitating the development of quantum-resistant algorithms.
64+
65+
## Future Directions in Cryptography
66+
67+
The field of cryptography is continuously evolving to address emerging threats and challenges. Some future directions include:
68+
69+
### Post-Quantum Cryptography
70+
71+
With the advent of quantum computing, researchers are developing cryptographic algorithms that are resistant to quantum attacks. These algorithms aim to provide security even in the presence of powerful quantum computers.
72+
73+
### Homomorphic Encryption
74+
75+
This advanced form of encryption allows computations to be performed on encrypted data without decrypting it. Homomorphic encryption has significant implications for data privacy, particularly in cloud computing and data analysis.
76+
77+
### Zero-Knowledge Proofs
78+
79+
Zero-knowledge proofs enable one party to prove to another that a statement is true without revealing any information beyond the validity of the statement. This concept has applications in authentication, privacy-preserving protocols, and blockchain technology.
80+
81+
## Conclusion
82+
83+
Cryptography is a cornerstone of cyber security, providing the means to protect data and maintain privacy in an increasingly interconnected world. As technology advances and new threats emerge, the field of cryptography will continue to evolve, offering innovative solutions to ensure the security and integrity of our digital lives. By understanding and implementing cryptographic techniques, individuals and organizations can safeguard their information and build a secure future.
84+

docusaurus.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ const config = {
143143
<a href="/docs/category/python/" class="nav__icons"> <img src="/icons/py.svg" title="Python" alt="Python" /> </a>
144144
<a href="/docs/category/java/" class="nav__icons"> <img src="/icons/java.svg" title="Java" alt="Java" /> </a>
145145
<a href="/docs/category/tailwind/" class="nav__icons"> <img src="/icons/tailwind-css.svg" title="Tailwind CSS" alt="Tailwind" /> </a>
146-
<a href="/docs/category/cpp/" class="nav__icons"> <img src="/icons/cpp.svg" title="CPP" alt="CPP" /> </a>
147-
<a href="/docs/category/NextJs/" class="nav__icons"> <img src="/icons/next-js.svg" title="NextJs" alt="Next" /> </a>
146+
<a href="/docs/category/cpp/" class="nav__icons"> <img src="/icons/cpp.svg" title="CPP" alt="CPP" /> </a>
147+
<a href="/docs/category/NextJs/" class="nav__icons"> <img src="/icons/next-js.svg" title="NextJs" alt="Next" /> </a>
148+
<a href="/docs/category/MATLAB/" class="nav__icons"> <img src="/icons/matlab.svg" title="MATLAB" alt="MATLAB" /> </a>
149+
<a href="/docs/category/Julia/" class="nav__icons"> <img src="/icons/julia.svg" title="Julia" alt="Julia" /> </a>
148150
</div>
149151
</div>`,
150152
},
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
id: valid-number
3+
title: Valid Number(LeetCode)
4+
sidebar_label: 0065-Valid Number
5+
tags:
6+
- String
7+
description: Given a string s, return whether s is a valid number.
8+
---
9+
10+
## Problem Statement
11+
12+
Given a string `s`, return whether `s` is a valid number.
13+
14+
For example, all the following are valid numbers: `"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"`, while the following are not valid numbers: `"abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"`.
15+
16+
Formally, a valid number is defined using one of the following definitions:
17+
18+
1. An integer number followed by an optional exponent.
19+
2. A decimal number followed by an optional exponent.
20+
An integer number is defined with an optional sign `'-'` or `'+'` followed by digits.
21+
22+
A decimal number is defined with an optional sign `'-'` or `'+'` followed by one of the following definitions:
23+
24+
1. Digits followed by a dot `'.'`.
25+
2. Digits followed by a dot `'.'` followed by digits.
26+
3. A dot `'.'` followed by digits.
27+
An exponent is defined with an exponent notation `'e'` or `'E'` followed by an integer number.
28+
29+
The digits are defined as one or more digits.
30+
31+
### Examples
32+
33+
**Example 1:**
34+
35+
```plaintext
36+
Input: s = "0"
37+
Output: true
38+
```
39+
40+
**Example 2:**
41+
42+
```plaintext
43+
Input: s = "e"
44+
Output: false
45+
```
46+
47+
**Example 3:**
48+
49+
```plaintext
50+
Input: s = "."
51+
Output: false
52+
```
53+
54+
### Constraints
55+
56+
- `1 <= s.length <= 20`
57+
- `s` consists of only English letters (both uppercase and lowercase), digits (`0-9`), plus `'+'`, minus `'-'`, or dot `'.'`.
58+
59+
## Solution
60+
61+
### Approach
62+
63+
#### Algorithm
64+
65+
1. Trim the Input String: Remove leading and trailing whitespace using `s.trim()`.
66+
2. Initialize Flags:
67+
* `pointSeen`: Tracks if a decimal point has been encountered.
68+
* `eSeen`: Tracks if an exponent 'e' has been encountered.
69+
* `numberSeen`: Tracks if at least one digit has been encountered.
70+
* `numberAfterE`: Tracks if at least one digit exists after an 'e'.
71+
3. Iterate Over Each Character:
72+
* If the character is a digit (`0-9`), set `numberSeen` and `numberAfterE` to `true`.
73+
* If the character is a decimal point (`.`), ensure no 'e' or previous decimal point has been seen.
74+
* If the character is an exponent (`e`), ensure no previous 'e' has been seen and that at least one digit has been encountered before it. Set numberAfterE to false.
75+
* If the character is a sign (`+` or `-`), ensure it appears at the beginning or immediately after an 'e'.
76+
* If any other character is encountered, return `false`.
77+
4. Final Check: Ensure that at least one digit has been encountered (`numberSeen` is `true`) and if an 'e' was encountered, ensure there is at least one digit after it (`numberAfterE` is `true`).
78+
79+
#### Implementation
80+
81+
```Java
82+
public boolean isNumber(String s) {
83+
s = s.trim();
84+
85+
boolean pointSeen = false;
86+
boolean eSeen = false;
87+
boolean numberSeen = false;
88+
boolean numberAfterE = true;
89+
for(int i=0; i<s.length(); i++) {
90+
if('0' <= s.charAt(i) && s.charAt(i) <= '9') {
91+
numberSeen = true;
92+
numberAfterE = true;
93+
} else if(s.charAt(i) == '.') {
94+
if(eSeen || pointSeen) {
95+
return false;
96+
}
97+
pointSeen = true;
98+
} else if(s.charAt(i) == 'e') {
99+
if(eSeen || !numberSeen) {
100+
return false;
101+
}
102+
numberAfterE = false;
103+
eSeen = true;
104+
} else if(s.charAt(i) == '-' || s.charAt(i) == '+') {
105+
if(i != 0 && s.charAt(i-1) != 'e') {
106+
return false;
107+
}
108+
} else {
109+
return false;
110+
}
111+
}
112+
113+
return numberSeen && numberAfterE;
114+
}
115+
```
116+
117+
### Complexity Analysis
118+
119+
- **Time complexity**: $O(N)$
120+
- **Space complexity**: $O(1)$
121+
122+
### Conclusion
123+
124+
The solution effectively validates if a string represents a valid number by processing it in a single pass and using flags to ensure the correct format. The key checks include ensuring correct placement of decimal points, exponents, and signs, as well as ensuring the presence of digits both before and after an exponent if present. This approach is efficient with a linear time complexity and constant space complexity.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
id: maximum-price-to-fill-a-bag
3+
title: Maximum Price to Fill a Bag
4+
sidebar_label: 2548 Maximum Price to Fill a Bag
5+
tags:
6+
- Array
7+
- Maths
8+
- sort
9+
- LeetCode
10+
- java
11+
description: "This is a solution to the Maximum Price to Fill a Bag problem on LeetCode."
12+
---
13+
14+
## Problem Description
15+
16+
You are given a 2D integer array items where items[i] = [pricei, weighti] denotes the price and weight of the ith item, respectively.
17+
18+
You are also given a positive integer capacity.
19+
20+
Each item can be divided into two items with ratios part1 and part2, where part1 + part2 == 1.
21+
22+
The weight of the first item is weighti * part1 and the price of the first item is pricei * part1.
23+
Similarly, the weight of the second item is weighti * part2 and the price of the second item is pricei * part2.
24+
Return the maximum total price to fill a bag of capacity capacity with given items. If it is impossible to fill a bag return -1. Answers within 10-5 of the actual answer will be considered accepted.
25+
26+
27+
### Examples
28+
29+
**Example 1:**
30+
31+
```
32+
Input: items = [[50,1],[10,8]], capacity = 5
33+
Output: 55.00000
34+
Explanation:
35+
We divide the 2nd item into two parts with part1 = 0.5 and part2 = 0.5.
36+
37+
```
38+
39+
**Example 2:**
40+
41+
```
42+
Input: items = [[100,30]], capacity = 50
43+
Output: -1.00000
44+
Explanation: It is impossible to fill a bag with the given item.
45+
46+
```
47+
48+
49+
### Constraints
50+
51+
- `1 <= items.length <= 105`
52+
- `items[i].length == 2`
53+
- `1 <= pricei, weighti <= 104`
54+
- `1 <= capacity <= 109`
55+
56+
### Approach
57+
58+
We sort the items in descending order by unit price, and then take out the items one by one until the backpack is full.
59+
60+
If the backpack is not full in the end, return $-1$, otherwise return the total price.
61+
62+
The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log n)$, where $n$ is the number of items.
63+
64+
#### Python3
65+
66+
```python
67+
class Solution:
68+
def maxPrice(self, items: List[List[int]], capacity: int) -> float:
69+
ans = 0
70+
for p, w in sorted(items, key=lambda x: x[1] / x[0]):
71+
v = min(w, capacity)
72+
ans += v / w * p
73+
capacity -= v
74+
return -1 if capacity else ans
75+
76+
```
77+
78+
#### Java
79+
80+
```java
81+
class Solution {
82+
public double maxPrice(int[][] items, int capacity) {
83+
Arrays.sort(items, (a, b) -> a[1] * b[0] - a[0] * b[1]);
84+
double ans = 0;
85+
for (var e : items) {
86+
int p = e[0], w = e[1];
87+
int v = Math.min(w, capacity);
88+
ans += v * 1.0 / w * p;
89+
capacity -= v;
90+
}
91+
return capacity > 0 ? -1 : ans;
92+
}
93+
}
94+
```
95+
96+
#### C++
97+
98+
```cpp
99+
class Solution {
100+
public:
101+
double maxPrice(vector<vector<int>>& items, int capacity) {
102+
sort(items.begin(), items.end(), [&](const auto& a, const auto& b) { return a[1] * b[0] < a[0] * b[1]; });
103+
double ans = 0;
104+
for (auto& e : items) {
105+
int p = e[0], w = e[1];
106+
int v = min(w, capacity);
107+
ans += v * 1.0 / w * p;
108+
capacity -= v;
109+
}
110+
return capacity > 0 ? -1 : ans;
111+
}
112+
};
113+
```

0 commit comments

Comments
 (0)