-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodulo.py
More file actions
27 lines (25 loc) · 820 Bytes
/
modulo.py
File metadata and controls
27 lines (25 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def modulo(number,puissance,N):
binary = bin(puissance)
char_list = [char for char in binary]
converted_list = [int(char) if char.isdigit() else char for char in char_list]
clean_list=(converted_list[2:])
reversed_list = list(reversed(clean_list))
lista=[number]
nbr=number
for i in range(len(reversed_list)) :
nbr=(nbr**2 )% N
lista.append(nbr)
nlista=[]
for i in range(len(reversed_list)):
if reversed_list[i]==1 :
nlista.append(lista[i])
s=1
for i in range(len(nlista)):
s=s*nlista[i]
return s%N
print("*"*100)
number = input("==> Enter un nombre")
puissance = input("==> Enter le puissance ")
N= input("==> Enter le N")
print("*"*100)
print("==> Le resultat de modulo est:", modulo(int(number),int(puissance),int(N)))