Skip to content

Commit 85c078c

Browse files
authored
Merge branch 'main' into add/solution-lc-2550
2 parents a8893c4 + d905b0c commit 85c078c

File tree

14 files changed

+680
-54
lines changed

14 files changed

+680
-54
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+

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ title: Welcome to CodeHarborHub Tutorials
44
sidebar_label: Welcome to CodeHarborHub
55
sidebar_position: 1
66
slug: /
7+
sidebar_class_name: "tutorial-learning-tasks"
78
---
89

910
Hello, and welcome to CodeHarborHub! Our mission is to provide accessible and comprehensive educational resources to learners of all levels, from beginners to advanced professionals. Whether you're looking to kickstart your career in web development, master a new programming language, or stay updated on the latest tech trends, we've got you covered.

docusaurus.config.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
2-
import { faLinkedin, faYoutube, faDiscord, } from '@fortawesome/free-brands-svg-icons';
3-
4-
import { themes as prismThemes } from "prism-react-renderer";
51
import { default as npm2yarn } from "@docusaurus/remark-plugin-npm2yarn";
2+
import { themes as prismThemes } from "prism-react-renderer";
3+
64
const remarkMath = require("remark-math");
75
const rehypeKatex = require("rehype-katex");
86

@@ -96,11 +94,21 @@ const config = {
9694
{ name: "twitter:creator", content: "@CodesWithAjay" },
9795
{ property: "og:type", content: "website" },
9896
{ property: "og:site_name", content: "CodeHarborHub" },
99-
{ property: "og:title", content: "CodeHarborHub - A place to learn and grow" },
100-
{ property: "og:description", content: "CodeHarborHub is a place to learn and grow. We provide accessible and comprehensive educational resources to learners of all levels, from beginners to advanced professionals."},
101-
{ property: "og:image", content: "https://codeharborhub.github.io/img/nav-logo.jpg" },
97+
{
98+
property: "og:title",
99+
content: "CodeHarborHub - A place to learn and grow",
100+
},
101+
{
102+
property: "og:description",
103+
content:
104+
"CodeHarborHub is a place to learn and grow. We provide accessible and comprehensive educational resources to learners of all levels, from beginners to advanced professionals.",
105+
},
106+
{
107+
property: "og:image",
108+
content: "https://codeharborhub.github.io/img/nav-logo.jpg",
109+
},
102110
{ property: "og:url", content: "https://codeharborhub.github.io" },
103-
{ name: "robots", content: "index, follow" },
111+
{ name: "robots", content: "index, follow" },
104112
],
105113

106114
algolia: {
@@ -130,13 +138,15 @@ const config = {
130138
<a href="/docs/category/html/" class="nav__icons"> <img src="/icons/html-5.svg" title="HTML5" alt="HTML" /> </a>
131139
<a href="/docs/" class="nav__icons"> <img src="/icons/css.svg" title="CSS" alt="CSS" /> </a>
132140
<a href="/docs/category/javascript/" class="nav__icons" > <img src="/icons/js.svg" title="JavaScript" alt="JavaScript" /> </a>
133-
<a href="/docs/category/react/" class="nav__icons"> <img src="/icons/jsx.svg" title="React.Js" alt="React" /> </a>
134-
<a href="/docs/category/typescript/" class="nav__icons"> <img src="/icons/ts.svg" title="TypeScript" alt="TypeScript" /> </a>
135-
<a href="/docs/category/python/" class="nav__icons"> <img src="/icons/py.svg" title="Python" alt="Python" /> </a>
136-
<a href="/docs/category/java/" class="nav__icons"> <img src="/icons/java.svg" title="Java" alt="Java" /> </a>
141+
<a href="/docs/category/react/" class="nav__icons"> <img src="/icons/jsx.svg" title="React.Js" alt="React" /> </a>
142+
<a href="/docs/category/typescript/" class="nav__icons"> <img src="/icons/ts.svg" title="TypeScript" alt="TypeScript" /> </a>
143+
<a href="/docs/category/python/" class="nav__icons"> <img src="/icons/py.svg" title="Python" alt="Python" /> </a>
144+
<a href="/docs/category/java/" class="nav__icons"> <img src="/icons/java.svg" title="Java" alt="Java" /> </a>
137145
<a href="/docs/category/tailwind/" class="nav__icons"> <img src="/icons/tailwind-css.svg" title="Tailwind CSS" alt="Tailwind" /> </a>
138146
<a href="/docs/category/cpp/" class="nav__icons"> <img src="/icons/cpp.svg" title="CPP" alt="CPP" /> </a>
139-
<a href="/docs/category/NextJs/" class="nav__icons"> <img src="/icons/next-js.svg" title="NextJs" alt="Next" /> </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>
140150
</div>
141151
</div>`,
142152
},
@@ -151,7 +161,7 @@ const config = {
151161
value: `<div class="dropdown">
152162
<a class="dropbtn" href="/courses/"> Courses&nbsp; </a>
153163
<div class="dropdown-content">
154-
<a href="/courses/category/reactjs/" class="nav__icons"> <img src="/icons/jsx.svg" alt="React" /> </a>
164+
<a href="/courses/category/reactjs/" class="nav__icons"> <img src="/icons/jsx.svg" alt="React" /> </a>
155165
</div>
156166
</div>`,
157167
},
@@ -362,22 +372,19 @@ const config = {
362372
{
363373
label: "LinkedIn",
364374
href: "https://www.linkedin.com/company/codeharborhub/",
365-
icon: 'faLinkedin',
366375
},
367376
{
368377
label: "YouTube",
369378
href: "https://www.youtube.com/",
370-
icon: 'faYoutube',
379+
icon: "faYoutube",
371380
},
372381
{
373382
label: "Discord",
374383
href: "https://discord.gg/c53FQn3pRv",
375-
icon: 'faDiscord',
376384
},
377385
{
378386
label: "Twitter(X)",
379387
href: "https://twitter.com/CodesWithAjay",
380-
icon: 'faTwitter',
381388
},
382389
],
383390
},

dsa-solutions/gfg-solutions/Basic/0093.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
id: replace-zeros-with-fives
2+
id: replace-zeros-with-five
33
title: Replace All 0's with 5
44
sidebar_label: 0093 Replace All 0's with 5
55
tags:
6-
- Python
7-
- Java
8-
- C++
9-
- C
6+
- Python
7+
- Java
8+
- C++
9+
- C
1010
description: "This document covers methods to replace all occurrences of the digit 0 with the digit 5 in a given number in various programming languages."
1111
---
1212

@@ -15,7 +15,9 @@ description: "This document covers methods to replace all occurrences of the dig
1515
Given a number N. The task is to complete the function **convertFive()** which replaces all zeros in the number with 5 and returns the number.
1616

1717
### Examples:
18+
1819
**Example 1:**
20+
1921
```
2022
Input
2123
2
@@ -50,7 +52,9 @@ Since this is a functional problem you don't have to worry about input, you just
5052
- $1 <= N <= 10^4$
5153

5254
## Solution
55+
5356
### Python
57+
5458
```python
5559
def convertFive(self,n):
5660
num_str = str(n)
@@ -64,6 +68,7 @@ def convertFive(self,n):
6468
```
6569

6670
### Java
71+
6772
```java
6873
public static int convertFive(int n){
6974
String numStr = String.valueOf(n);
@@ -72,7 +77,7 @@ public static int convertFive(int n){
7277
char currentChar = numStr.charAt(i);
7378
if (currentChar == '0') {
7479
result.append('5');
75-
}
80+
}
7681
else {
7782
result.append(currentChar);
7883
}
@@ -83,6 +88,7 @@ public static int convertFive(int n){
8388
```
8489

8590
### C++
91+
8692
```cpp
8793
int convertFive(int n) {
8894
string numStr = to_string(n);
@@ -97,6 +103,7 @@ int convertFive(int n) {
97103
```
98104
99105
### C
106+
100107
```c
101108
int convertFive(int n) {
102109
int result = 0;
@@ -105,7 +112,7 @@ int convertFive(int n) {
105112
int digit = n % 10;
106113
if (digit == 0) {
107114
result += 5 * position;
108-
}
115+
}
109116
else {
110117
result += digit * position;
111118
}
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)