Skip to content

Commit b42f78c

Browse files
committed
Tran:WTFAcademy#60 merge
2 parents 877eeb4 + f01c57d commit b42f78c

File tree

12 files changed

+381
-997
lines changed

12 files changed

+381
-997
lines changed

Languages/en/00_Set/readme.md

+39-39
Large diffs are not rendered by default.

Languages/en/01_Integer/readme.md

+33-32
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
---
2-
title: 01. Integer Arithmetic Basics
2+
title: 01. Basic Integer Operations
33
tags:
44
- zk
55
- basic
66
- integer
77
---
88

9-
# WTF zk Tutorial Lesson 1: Integer Arithmetic Basics
9+
# Zero-Knowledge Proof Tutorial Lesson 1: Basic Integer Operations
1010

1111
As a beginner-friendly tutorial on zero-knowledge proofs, we will start by learning the basics of integer arithmetic. Most of you have probably learned this in secondary school, so it should be quite easy. We will also implement integer arithmetic using Python, making it easy for beginners to get started.
1212

13-
For those who haven't used Python before, it is recommended to install [Anaconda](https://www.anaconda.com/download) to install and manage the Python environment.
13+
14+
If you are new to Python, we recommend installing [Anaconda](https://www.anaconda.com/download) to easily set up and manage your Python environment.
1415

1516
## 1. Basic Definitions
1617

17-
An integer is a number without a decimal part and can be either positive, negative, or zero. We use $\mathbb{Z}$ to represent the set of all integers.
18+
An integer is a whole number without a decimal part. It can be positive, negative, or zero. We use the symbol $\mathbb{Z}$ to represent the set of all integers.
1819

1920
$$
2021
\mathbb{Z} = \lbrace \ldots, -3, -2, -1, 0, 1, 2, 3, \ldots \rbrace
2122
$$
2223

23-
For an integer $a \in \mathbb{Z}$, we use $\lvert a \rvert$ to represent the absolute value of $a$, which is the non-negative value of $a$ regardless of its sign.
24+
For an integer $a \in \mathbb{Z}$, the absolute value of $a$, denoted as $\lvert a \rvert$, represents the non-negative value of $a$ without considering its sign.
2425

2526
$$
2627
\lvert 69 \rvert = 69
@@ -30,85 +31,85 @@ $$
3031
\lvert -69 \rvert = 69
3132
$$
3233

33-
We often use the natural numbers $\mathbb{N}$, which are a subset of integers and include all positive integers.
34+
We often use the term "natural numbers" to refer to positive integers. It is a subset of the set of integers and includes all positive integers.
3435

3536
$$
3637
\mathbb{N} = \lbrace 1, 2, 3, \ldots \rbrace
3738
$$
3839

39-
In addition, we sometimes use non-negative integers, which we denote as $\mathbb{N_0}$:
40+
Additionally, we sometimes refer to non-negative integers as $\mathbb{N_0}$:
4041

4142
$$
4243
\mathbb{N_0} = \lbrace 0, 1, 2, 3, \ldots \rbrace
4344
$$
4445

45-
> Note: Some textbooks include 0 in the set of natural numbers, and there is currently [debate](https://zh.wikipedia.org/wiki/%E8%87%AA%E7%84%B6%E6%95%B0) on whether 0 should be included.
46-
47-
## 2. Integer Arithmetic
46+
> Note: The inclusion of 0 in the set of natural numbers is a topic of debate. Some textbooks include 0, while others do not. (Source: [Wikipedia](https://en.wikipedia.org/wiki/Natural_number))
4847
49-
Integer arithmetic includes addition, subtraction, multiplication, and division. Let's review the rules for these basic operations:
48+
## 2. Integer Operations
5049

51-
- **Addition ( $+$ ):** For integers $a$ and $b$, their sum $a + b$ is the result of adding them together.
50+
Integer operations include addition, subtraction, multiplication, and division. Let's review the rules for these basic operations:
5251

52+
- **Addition ($+$):** To add two integers $a$ and $b$, simply sum them up.
53+
5354
```python
5455
a, b = 7, 5
5556
sum_result = a + b
56-
print(f'Addition example: {sum_result}')
57-
# Addition example: 12
57+
print(f'Example: {sum_result}')
58+
# Example: 12
5859
```
5960

60-
- **Subtraction ( $-$ ):** For integers $a$ and $b$, their difference $a - b$ is the result of subtracting $b$ from $a$.
61-
61+
- **Subtraction ($-$):** To subtract an integer $b$ from another integer $a$, subtract $b$ from $a$.
62+
6263
```python
6364
diff_result = a - b
64-
print(f'Subtraction example: {diff_result}')
65-
# Subtraction example: 2
65+
print(f'Example: {diff_result}')
66+
# Example: 2
6667
```
6768

68-
- **Multiplication ( $\times$ ):** For integers $a$ and $b$, their product $a \times b$ is the result of multiplying them together.
69-
69+
- **Multiplication ($\times$):** To multiply two integers $a$ and $b$, multiply them together.
70+
7071
```python
7172
product_result = a * b
72-
print(f'Multiplication example: {product_result}')
73-
# Multiplication example: 35
73+
print(f'Example: {product_result}')
74+
# Example: 35
7475
```
7576

7677

7778
## 3. Properties of Integers
7879

7980
Integers have some important properties:
8081

81-
- **Closure:** Integer addition and multiplication are closed operations within the set of integers, meaning that the sum or product of any two integers is still an integer.
82+
- **Closure Property:** Integer addition and multiplication are closed within the set of integers. This means that the sum or product of any two integers will still be an integer.
8283

83-
- **Commutativity:** Integer addition and multiplication are commutative, meaning that $a + b = b + a$ and $a \times b = b \times a$ hold true for any integers $a$ and $b$.
84+
- **Commutative Property:** Integer addition and multiplication are commutative. This means that the order of the integers does not affect the result. For any integers $a$ and $b$, $a + b = b + a$ and $a \times b = b \times a$.
8485

85-
- **Associativity:** Integer addition and multiplication are associative, meaning that $(a + b) + c = a + (b + c)$ and $(a \times b) \times c = a \times (b \times c)$ hold true for any integers $a$, $b$, and $c$.
86+
- **Associative Property:** Integer addition and multiplication are associative. This means that the grouping of integers does not affect the result. For any integers $a$, $b$, and $c$, $(a + b) + c = a + (b + c)$ and $(a \times b) \times c = a \times (b \times c)$.
8687

8788
## 4. Euclidean Division
8889

8990
The division we commonly use is real number division, where the result of dividing two integers may not be an integer, e.g., $7 \div 5 = 1.4$ is not an integer. Therefore, we introduce integer division, also known as Euclidean Division. Its result consists of two parts: the quotient and the remainder. The definition of Euclidean Division is as follows:
9091

91-
For integers $a$ and $b$ (where $b \neq 0$), there exists a unique pair of integers $(q, r)$ such that $a = bq + r$, where $q$ is the quotient, $r$ is the remainder, and $0 \leq r \lt |b|$.
92+
For integers $a$ and $b$ (where $b \neq 0$), there exists a unique pair of integers $(q, r)$ such that $a = bq + r$. Here, $q$ represents the quotient, $r$ represents the remainder, and $0 \leq r \lt |b|$.
9293

93-
If the remainder when dividing $a$ by $b$ is zero, we say that $a$ is divisible by $b$ ($b$ divides $a$) and write $b \mid a$. We can also call $b$ a factor of $a$. If the remainder is not zero, we write $b \nmid a$.
94+
If the remainder of $a$ divided by $b$ is zero, we say that $a$ is divisible by $b$ ($b$ divides $a$), denoted as $b \mid a$. We can also say that $b$ is a factor of $a$. If the remainder is not zero, we denote it as $b \nmid a$.
9495

95-
We can implement Euclidean Division in Python, taking care to handle the case when $a$ or $b$ is negative: the `divmod` function in Python allows for negative remainders, whereas Euclidean Division requires $0 \leq r \lt |b|$. On the contrary, the modulo operation (`%`) in Python allows for negative numbers. Here, it is necessary to understand the internal implementation formula for the modulo operation in programming languages: $a\%b=a-(a//b) * b$. (The `//` here is Python's internal implementation of Euclidean Division, ensuring a positive remainder less than the divisor).
96+
We can implement Euclidean Division in Python. When implementing it, we need to handle the cases where $a$ or $b$ is negative. The `divmod` function in Python allows for negative remainders, but Euclidean Division requires the remainder to be non-negative and less than the divisor. On the other hand, the modulo operation (`%`) in Python allows for negative remainders. It is necessary to understand the internal implementation formula of the modulo operation in programming languages: $a\%b=a-(a//b) * b$ (where `//` represents the internal implementation of Euclidean Division in Python, ensuring that the remainder is positive and less than the divisor).
9697

9798
```python
9899
def euclidean_division(a, b):
99100
quotient, remainder = divmod(a, b)
100101
if remainder < 0:
101102
# Adjust the remainder to ensure it is non-negative
102103
remainder += abs(b)
103-
# Adjust the quotient to maintain the equation
104+
# Adjust the quotient to maintain the equation's validity
104105
quotient += 1
105106
return quotient, remainder
106107

107108
quotient, remainder = euclidean_division(a, b)
108-
print(f'Division example: quotient is {quotient}, remainder is {remainder}')
109-
# Division example: quotient is 1, remainder is 2
109+
print(f'Example: Quotient is {quotient}, Remainder is {remainder}')
110+
# Example: Quotient is 1, Remainder is 2
110111
```
111112

112113
## 5. Summary
113114

114-
In this lesson, we introduced the basics of integers, including their definitions and basic operations (addition, subtraction, multiplication, and Euclidean Division), and implemented them using Python. We believe that most of you have learned these concepts in secondary school and find them straightforward. Let's continue the WTF zk journey!
115+
In this lesson, we introduced the basics of integers, including their definitions and basic operations (addition, subtraction, multiplication, and Euclidean Division), and implemented them using Python. These concepts are usually covered in middle school and are relatively simple. Now, let's continue our journey into the world of Zero-Knowledge Proofs (ZKPs)!

Languages/en/02_Prime/readme.md

+22-29
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,56 @@
1-
---
2-
title: 02. Prime Number Basics
3-
tags:
4-
- zk
5-
- basic
6-
- integer
7-
---
1+
# WTF zk Series: Tutorial 02 - Basics of Prime Numbers
82

93
# WTF zk Tutorial Lesson 2: Prime Number Basics
104
Welcome to the second lesson of the WTF zk tutorial series! In this tutorial, we will explore the basics of prime numbers. Prime numbers play a crucial role in cryptography, making it essential to understand them for learning zero-knowledge proofs.
115

6+
127
## 1. Definition of Prime Numbers
138

14-
Prime numbers are also known as prime numbers and are defined as follows: For a natural number greater than 1, if it cannot be divided evenly by any natural number other than 1 and itself, then it is a prime number.
9+
Prime numbers are natural numbers greater than 1 that cannot be evenly divided by any other natural number except 1 and itself. In other words, a prime number has no factors other than 1 and itself.
1510

16-
2, 3, 5, and 7 are all prime numbers because they can only be divided evenly by 1 and themselves. In addition, all even numbers except 2 are not prime numbers because they can be divided evenly by 2 in addition to 1 and themselves.
11+
For example, 2, 3, 5, and 7 are prime numbers because they can only be divided evenly by 1 and themselves. On the other hand, all even numbers (except 2) are not prime numbers because they can be divided evenly by 2.
1712

1813
## 2. Properties of Prime Numbers
1914

20-
Prime numbers are fundamental units of all natural numbers, and the fundamental theorem of arithmetic tells us:
21-
22-
> Any natural number greater than 1 can be expressed as a unique product of prime numbers, regardless of the order of the prime numbers.
15+
Prime numbers are the basic building blocks of all natural numbers. The fundamental theorem of arithmetic states that any natural number greater than 1 can be expressed as a unique product of prime numbers, regardless of the order of the prime numbers.
2316

2417
For example:
2518

2619
$$
2720
84 = 2^2 \times 3 \times 7
2821
$$
2922

30-
Here, 2, 3, and 7 are prime numbers, and this factorization is unique.
23+
In this example, 2, 3, and 7 are prime numbers, and this factorization is unique.
3124

3225
Prime Number Theorem: The number of prime numbers less than or equal to N is approximately $N/\ln{N}$, and there are infinitely many prime numbers.
3326

3427
Proof:
3528

36-
Euclidean proof
29+
Euclidean Proof
3730

38-
1. **Assume a Finite Number of Prime Numbers:** First, assume that there are a finite number of prime numbers, which we denote as $p_1, p_2, \ldots, p_n$.
31+
1. **Assume a Finite Number of Prime Numbers:** Let's assume that there are only a finite number of prime numbers and denote them as $p_1, p_2, \ldots, p_n$.
3932

40-
2. **Construct a New Number:** Consider the new number $N = p_1 \times p_2 \times \ldots \times p_n + 1$, which is obtained by multiplying all known prime numbers and adding 1.
33+
2. **Construct a New Number:** Consider a new number $N = p_1 \times p_2 \times \ldots \times p_n + 1$. This number is obtained by multiplying all known prime numbers and adding 1.
4134

42-
3. **Properties of the New Number:** The number N is obviously a prime number because it is not a multiple of any known prime number, as dividing it by any known prime number leaves a remainder of 1.
35+
3. **Properties of the New Number:** The number N is obviously a prime number because it is not divisible by any known prime number. Dividing N by any known prime number leaves a remainder of 1.
4336

44-
4. **Contradiction:** Hence, this leads to a contradiction, because if N is not a prime number, it must have a prime factor, which either is a known prime number or a new prime number different from the known prime numbers.
37+
4. **Contradiction:** This leads to a contradiction because if N is not a prime number, then it must have a prime factor. This prime factor either belongs to the known prime numbers or is a new prime number different from the known ones.
4538

46-
5. **Conclusion:** In any case, this results in a contradiction with the initial assumption of a finite number of prime numbers. Therefore, the initial assumption is incorrect, and there must be infinitely many prime numbers.
39+
5. **Conclusion:** In either case, this contradicts the initial assumption of a finite number of prime numbers. Therefore, the initial assumption is incorrect, and the number of prime numbers must be infinite.
4740

4841
## 3. Prime Numbers and Composite Numbers
4942

50-
We can classify natural numbers into prime numbers and composite numbers. Composite numbers are the complements of prime numbers: For a natural number greater than 1, if it has factors other than 1 and itself, it is a composite number. For example, 4, 6, 8, and 9 are composite numbers.
43+
Natural numbers can be divided into two categories: prime numbers and composite numbers. Composite numbers are the opposite of prime numbers. A composite number is a natural number greater than 1 that has factors other than 1 and itself. For example, 4, 6, 8, and 9 are all composite numbers.
5144

5245
## 4. Finding Prime Numbers
5346

54-
Finding prime numbers is an important task in number theory, which has attracted attention since medieval times. People tried to find prime number formulas (formulas that can generate prime numbers only) during that time. By the time of Gauss, it was basically confirmed that simple prime number formulas do not exist. Therefore, Gauss believed that primality testing is a fairly difficult problem. Since then, this problem has attracted a large number of mathematicians. Primality testing algorithms can be divided into two main categories: deterministic algorithms and probabilistic algorithms. The former provides a definite result but is usually slower, while the latter provides a result that may vary.
47+
Finding prime numbers is an important task in number theory. This problem gained attention in the Middle Ages when people tried to find formulas that could generate prime numbers exclusively. In the era of Gauss, it was basically confirmed that simple prime formulas do not exist. Gauss believed that determining primality is a very difficult problem. Since then, many mathematicians have been fascinated by this problem. Primality testing algorithms can be divided into two categories: deterministic algorithms and random algorithms. Deterministic algorithms provide a definite result but are usually slower, while random algorithms are the opposite.
5548

5649
### Deterministic Algorithms
5750

5851
- [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
5952

60-
The most commonly used method is the Sieve of Eratosthenes. Its logic is very simple: first, determine a range to search, then eliminate all multiples of prime numbers between 0 and $\sqrt n$, leaving behind all prime numbers within the range.
53+
The most commonly used method is the Sieve of Eratosthenes. Its logic is very simple: first, determine a range to search, then eliminate all multiples of prime numbers between 0 and $\sqrt{n}$. The remaining numbers within the range are all prime numbers.
6154

6255
We can implement this method in Python:
6356

@@ -78,19 +71,19 @@ print(f'Prime numbers less than or equal to {limit}: {prime_numbers}')
7871
# Prime numbers less than or equal to 20: [2, 3, 5, 7, 11, 13, 17, 19]
7972
```
8073

81-
- [Lucas-Lehmer Primality Test](https://en.wikipedia.org/wiki/Lucas-Lehmer_test)
74+
- [Lucas-Lehmer Primality Test](https://en.wikipedia.org/wiki/Lucas%E2%80%93Lehmer_primality_test)
8275
- [AKS Primality Test](https://en.wikipedia.org/wiki/AKS_primality_test)
8376

84-
### Probabilistic Algorithms
77+
### Random Algorithms
8578

8679
- Fermat Primality Test
87-
- Uses [Fermat's Little Theorem](../07_Exp/readme.md) for testing.
80+
- Test using [Fermat's Little Theorem](../07_Exp/readme.md).
8881
- [Miller-Rabin Primality Test](https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test)
8982

90-
## 5. Applications of Prime Numbers in Cryptography
83+
## 5. Application of Prime Numbers in Cryptography
9184

92-
Prime numbers play a significant role in the field of cryptography, particularly in public-key cryptography. For example, RSA (Rivest-Shamir-Adleman) is an asymmetric encryption algorithm that uses the product of large prime numbers as part of the public and private keys: Calculating the product of prime numbers is simple, but factoring a large composite number into prime factors is extremely difficult, ensuring the security of the RSA encryption algorithm.
85+
Prime numbers play a crucial role in cryptography, especially in public-key cryptography. For example, RSA (Rivest-Shamir-Adleman) is an asymmetric encryption algorithm that uses the product of large prime numbers as part of the public and private keys. Calculating the product of prime numbers is simple, but factoring large composite numbers into prime factors is very difficult. This difficulty ensures the security of the RSA encryption algorithm.
9386

94-
## 6. Conclusion
87+
## 6. Summary
9588

96-
In this tutorial, we have learned the basics of prime numbers, including their definition, properties, and methods for finding prime numbers. Prime numbers have important applications in both mathematics and cryptography, laying the foundation for understanding zero-knowledge proofs.
89+
In this tutorial, we have learned the basics of prime numbers, including their definition, properties, and methods for finding prime numbers. Prime numbers have important applications in mathematics and cryptography, laying the foundation for our understanding of zero-knowledge proofs.

0 commit comments

Comments
 (0)