Skip to content

Commit 0b5647a

Browse files
authored
Merge branch 'main' into PradnyaGaitonde-patch-32
2 parents 67cf321 + daa3365 commit 0b5647a

File tree

5 files changed

+545
-0
lines changed

5 files changed

+545
-0
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+
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: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
id: word-search
3+
title: Word Search(LeetCode)
4+
sidebar_label: 0079-Word Search
5+
tags:
6+
- Array
7+
- String
8+
- Backtracking
9+
- Matrix
10+
description: Given an m x n grid of characters board and a string word, return true if word exists in the grid.
11+
---
12+
13+
## Problem Statement
14+
15+
Given an `m x n` grid of characters `board` and a string `word`, return `true` if `word` exists in the grid.
16+
17+
The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.
18+
19+
### Examples
20+
21+
**Example 1:**
22+
23+
![image](https://github.com/PradnyaGaitonde/codeharborhub.github.io/assets/116059908/dc23f6be-e216-4ad1-89bc-178cf3039262)
24+
25+
```plaintext
26+
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
27+
Output: true
28+
```
29+
30+
**Example 2:**
31+
32+
![image](https://github.com/PradnyaGaitonde/codeharborhub.github.io/assets/116059908/c3905a94-2a40-4dee-a4bf-42b77ba2b91a)
33+
34+
```plaintext
35+
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"
36+
Output: true
37+
```
38+
39+
**Example 3:**
40+
41+
![image](https://github.com/PradnyaGaitonde/codeharborhub.github.io/assets/116059908/c56f9ea3-8247-484b-943a-0c38ea32465c)
42+
43+
```plaintext
44+
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"
45+
Output: false
46+
```
47+
48+
### Constraints
49+
50+
- `m == board.length`
51+
- `n = board[i].length`
52+
- `1 <= m, n <= 6`
53+
- `1 <= word.length <= 15`
54+
- `board` and `word` consists of only lowercase and uppercase English letters.
55+
56+
## Solution
57+
58+
### Approach
59+
60+
#### Algorithm
61+
62+
1. Initialization:
63+
* Convert the input word to a character array `w`.
64+
* Iterate through each cell in the board using nested loops.
65+
2. Recursive Search:
66+
* For each cell in the board, call the recursive function `exist`.
67+
* The recursive function `exist` takes parameters: the board, current cell coordinates `(y, x)`, the word array, and the current index `i` in the word array.
68+
* Base cases:
69+
* If `i` equals the length of the word, return `true` (all characters are matched).
70+
* If the current cell `(y, x)` is out of bounds or does not match the current character in the word array, return `false`.
71+
* Mark the current cell as visited by toggling the 8th bit using `board[y][x] ^= 256`.
72+
* Recursively check all four possible directions (right, left, down, up) from the current cell.
73+
* After the recursive calls, unmark the current cell by toggling the 8th bit again using `board[y][x] ^= 256`.
74+
* Return `true` if any of the recursive calls return `true`, indicating that the word exists in the board starting from the current cell.
75+
3. Return Result:
76+
* Return `true` if the word is found starting from any cell, otherwise return `false`.
77+
78+
#### Implementation
79+
80+
```Java
81+
public boolean exist(char[][] board, String word) {
82+
char[] w = word.toCharArray();
83+
for (int y=0; y<board.length; y++) {
84+
for (int x=0; x<board[y].length; x++) {
85+
if (exist(board, y, x, w, 0)) return true;
86+
}
87+
}
88+
return false;
89+
}
90+
91+
private boolean exist(char[][] board, int y, int x, char[] word, int i) {
92+
if (i == word.length) return true;
93+
if (y<0 || x<0 || y == board.length || x == board[y].length) return false;
94+
if (board[y][x] != word[i]) return false;
95+
board[y][x] ^= 256;
96+
boolean exist = exist(board, y, x+1, word, i+1)
97+
|| exist(board, y, x-1, word, i+1)
98+
|| exist(board, y+1, x, word, i+1)
99+
|| exist(board, y-1, x, word, i+1);
100+
board[y][x] ^= 256;
101+
return exist;
102+
}
103+
```
104+
105+
### Complexity Analysis
106+
107+
- **Time complexity**: $O(N.3^L)$
108+
* N is the number of cells in the board (i.e., board.length * board[0].length).
109+
* L is the length of the word.
110+
* Each cell can be a starting point, and from each cell, we explore up to 3 directions (since we cannot revisit the previous cell, reducing from 4 to 3).
111+
112+
- **Space complexity**: O(L)
113+
* The recursion stack can go up to a depth of L, which is the length of the word.
114+
* No additional data structures are used that grow with input size (in-place modification of the board is used).
115+
116+
### Conclusion
117+
118+
This recursive solution effectively finds the word in the board by exploring all possible paths and backtracking when a path does not lead to the solution. By marking cells with a bitmask, it avoids using additional memory for visited states, making the algorithm space-efficient. The time complexity reflects the worst-case scenario of exploring all possible paths, while the space complexity is primarily driven by the depth of the recursion stack. This approach is both time and space-efficient, making it suitable for large boards and words.

0 commit comments

Comments
 (0)