Code
a = 5
b = -3
c = 12345678901234567890 #Python 3 can handle very large integers.The majority of the text and code has been generated by AI.
Editor: Witek ten Hove
See book section
Number theory is a branch of mathematics that deals with the properties and relationships of numbers, especially integers. Python, like many programming languages, has several built-in types to handle numbers, each with its own capabilities. The three most common numerical types in Python are int for integers, float for floating-point numbers, and complex for complex numbers.
Let’s start with a basic understanding of these number types:
int): These are positive or negative whole numbers with no decimal point. Integers in Python can be of any size, limited only by the amount of memory your system has.float): These are real numbers (i.e., numbers that can have a decimal point). The float type in Python designates a floating-point number. Float values are specified with a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation.complex): Complex numbers are numbers with a real and an imaginary component. In Python, complex numbers can be created using the complex(real, imag) function, or you can use the ‘j’ suffix in a literal to specify the imaginary part.Now, let’s illustrate some basic number theory concepts using these Python number types.
True
True
True
False
Number theory has many practical applications, particularly in cryptography, which is the study of encoding messages to keep them secure from unauthorized access. Many encryption algorithms rely on the difficulty of factoring large composite numbers into primes, which is a problem that is believed to be computationally infeasible for sufficiently large integers. As a result, number theory plays a crucial role in the security of modern communication systems.
import time
tic = time.time()
def find_factors(num):
factors = []
for i in range(1, num+1):
if num % i == 0:
factors.append(i)
return factors
tic = time.time()
print(find_factors(12))
toc = time.time()
print(f'{toc - tic} secs')
tic = time.time()
print(find_factors(997))
toc = time.time()
print(f'{toc - tic} secs')
tic = time.time()
print(find_factors(999983))
toc = time.time()
print(f'{toc - tic} secs')
tic = time.time()
print(find_factors(997*999983))
toc = time.time()
print(f'{toc - tic} secs')[1, 2, 3, 4, 6, 12]
0.0002880096435546875 secs
[1, 997]
0.00010514259338378906 secs
[1, 999983]
0.06030631065368652 secs
[1, 997, 999983, 996983051]
53.162992000579834 secs
Basic: Make a short video explaining how factorization and prime numbers are used for encryption. Do proper research and use code demos.
Stretch: Expand your video with an exploration of the current state of quantum computing and it’s expected evolution. Discuss and illustrate the implications for current encryption methodologies. Provide a list of interesting resources on the matter.
Challenge: Share your content online (e.g. Linkedin or Medium), gather feedback and write a reflection on it.