This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def kiem_tra_so_nguyen_to_miller_rabin(n): | |
"""Phương pháp miller - rabin là một phương pháp kiểm tra tính nguyên tố của một số, thực chất là kiểm tra một số không phải là số nguyên tố \ | |
để loại trừ. Cơ sở lý thuyết của phương pháp này như sau: \ | |
1. Định lý nhỏ fermat cho chúng ta biết rằng, nếu n là một số nguyên tố, thì với mọi số a sao cho \ | |
1 <= a < n thì a ^ (n-1) % n = 1. | |
2. n chắc chắn là số lẻ, vì n lẻ nên n-1 là một số chẵn và có thể biểu đạt dưới dạng: n-1 = d*2^s \ | |
trong đó d là số lẻ và s>0 . \ | |
3. Nhờ hai điều trên, với một số bất kỳ trong khoảng [2, n-2] thì a^(d*2^s) % n phải bằng 1. | |
4. Một tính chất toán học khác nữa là nếu x^2 % n = 1 thì x^2 -1 % n = 0""" | |
s = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_fermat(a,b,c,n): | |
if n < 3: | |
print("please enter n > 2!") | |
return | |
if a**n + b**n == c**n: | |
print("Holy smokes, Fermat was wrong!") | |
else: | |
print("No, that doesn't work.") | |
try: | |
a = int(input("enter a: \n")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_arg(s): | |
print(s, end=' ') | |
def print_four(f,s): | |
for i in range(0,4): | |
f(s) | |
def so_o_doc(h,f,s): | |
for i in range(0,int(h)): | |
print_arg(f) | |
print_four(print_arg,s) | |
print_arg(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Ma Hoa AES256. Dung cho python 3.5+ | |
Can cai dat pycryptodome. https://pypi.org/project/pycryptodome/ | |
Script nay co su dung code tu: https://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/ | |
""" | |
import os, random, struct | |
import hashlib | |
from Crypto.Cipher import AES | |