forked from Abhimanyu0197/bitcoin_tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
modulo.py
26 lines (25 loc) · 908 Bytes
/
modulo.py
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 mod(x,m): #modulo operation based on addition and subtraction x(number) m(modulus) for arbitrarily large integers
if x > 0: #to check how many cut_down or add_up ops are necessary
if x < m:
return x
else:
res = x // m
print(f'Positive[+] number of cut_down ops [{res}]')
x = x - (res*m)
return x
else:
res = abs(x) // m
x = x + (res*m)
if x == 0:
print(f'Negative[-] number of add_up ops [{res}]')
else:
x += m
print(f'Negative[-] number of add_up ops [{res+1}]')
return x
P = 115792089237316195423570985008687907853269984665640564039457584007908834671663
N = 115792089237316195423570985008687907852837564279074904382605163141518161494337
print(mod(P*2, P))
print(mod(-P, P))
print(mod(P+2*88,P))
print(mod(-111,11))
print(mod(35+36,37))