Skip to content

Commit 31bdc34

Browse files
authored
Merge branch 'main' into PradnyaGaitonde-patch-29
2 parents 0f7b420 + d5d91c2 commit 31bdc34

File tree

11 files changed

+472
-6
lines changed

11 files changed

+472
-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: 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+
```
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
id: alternating-digit-sum
3+
title: Count Collisions of Monkeys on a Polygonaximum
4+
sidebar_label: 2550 Count Collisions of Monkeys on a Polygonaximum
5+
- Array
6+
- Recursion
7+
- LeetCode
8+
- C++
9+
description: "This is a solution to the Count Collisions of Monkeys on a Polygonaximum problem on LeetCode."
10+
---
11+
12+
## Problem Description
13+
14+
There is a regular convex polygon with n vertices. The vertices are labeled from 0 to n - 1 in a clockwise direction, and each vertex has exactly one monkey. The following figure shows a convex polygon of 6 vertices.
15+
16+
Simultaneously, each monkey moves to a neighboring vertex. A collision happens if at least two monkeys reside on the same vertex after the movement or intersect on an edge.
17+
18+
Return the number of ways the monkeys can move so that at least one collision happens. Since the answer may be very large, return it modulo 10^9 + 7.
19+
20+
### Examples
21+
22+
**Example 1:**
23+
24+
```
25+
Input: n = 3
26+
Output: 6
27+
Explanation:
28+
There are 8 total possible movements.
29+
30+
```
31+
32+
**Example 2:**
33+
34+
```
35+
Input: n = 4
36+
Output: 14
37+
38+
```
39+
40+
41+
### Constraints
42+
43+
- `3 <= n <= 10^9`
44+
45+
46+
### Approach
47+
48+
According to the problem description, each monkey has two ways of moving, either clockwise or counterclockwise. Therefore, there are a total of $2^n$ ways to move. The non-collision ways of moving are only two, that is, all monkeys move clockwise or all monkeys move counterclockwise. Therefore, the number of collision ways of moving is $2^n - 2$.
49+
50+
We can use fast power to calculate the value of $2^n$, then use $2^n - 2$ to calculate the number of collision ways of moving, and finally take the remainder of $10^9 + 7$.
51+
52+
The time complexity is $O(\log n)$, where $n$ is the number of monkeys. The space complexity is $O(1)$.
53+
54+
#### Python3
55+
56+
```python
57+
class Solution:
58+
def monkeyMove(self, n: int) -> int:
59+
mod = 10**9 + 7
60+
return (pow(2, n, mod) - 2) % mod
61+
```
62+
63+
#### Java
64+
65+
```java
66+
class Solution {
67+
public int monkeyMove(int n) {
68+
final int mod = (int) 1e9 + 7;
69+
return (qpow(2, n, mod) - 2 + mod) % mod;
70+
}
71+
72+
private int qpow(long a, int n, int mod) {
73+
long ans = 1;
74+
for (; n > 0; n >>= 1) {
75+
if ((n & 1) == 1) {
76+
ans = ans * a % mod;
77+
}
78+
a = a * a % mod;
79+
}
80+
return (int) ans;
81+
}
82+
}
83+
```
84+
85+
#### C++
86+
87+
```cpp
88+
class Solution {
89+
public:
90+
int monkeyMove(int n) {
91+
const int mod = 1e9 + 7;
92+
using ll = long long;
93+
auto qpow = [&](ll a, int n) {
94+
ll ans = 1;
95+
for (; n; n >>= 1) {
96+
if (n & 1) {
97+
ans = ans * a % mod;
98+
}
99+
a = a * a % mod;
100+
}
101+
return ans;
102+
};
103+
return (qpow(2, n) - 2 + mod) % mod;
104+
}
105+
};
106+
```

0 commit comments

Comments
 (0)