将下面代码修改成正确格式 import random def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def mod_inverse(a, m): for x in range(1, m): if (a*x) % m == 1: return x return None def blind_sign(m, n, e, d): # Generate random value r r = random.randint(1, n-1) while gcd(r, n) != 1: r = random.randint(1, n-1) # Blind message m_blind = (m * pow(r, e)) % n # Sign blinded message s_blind = pow(m_blind, d) % n # Unblind signed message s = (s_blind * mod_inverse(r, n)) % n return s # Example usage n = 3233 # modulus e = 17 # public exponent d = 2753 # private exponent m = 1234 # message to be signed s = blind_sign(m, n, e, d) print("Message:", m) print("Signature:", s)
时间: 2024-03-04 20:47:51 浏览: 42
在Allegro 中如何输入光绘(Gerber)文件并浏览
5星 · 资源好评率100%
修改后的代码格式如下:
```python
import random
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def mod_inverse(a, m):
for x in range(1, m):
if (a*x) % m == 1:
return x
return None
def blind_sign(m, n, e, d):
# Generate random value r
r = random.randint(1, n-1)
while gcd(r, n) != 1:
r = random.randint(1, n-1)
# Blind message
m_blind = (m * pow(r, e)) % n
# Sign blinded message
s_blind = pow(m_blind, d) % n
# Unblind signed message
s = (s_blind * mod_inverse(r, n)) % n
return s
# Example usage
n = 3233 # modulus
e = 17 # public exponent
d = 2753 # private exponent
m = 1234 # message to be signed
s = blind_sign(m, n, e, d)
print("Message:", m)
print("Signature:", s)
```
阅读全文