In [71]:
BITS=64
In [72]:
p=3900617629
In [73]:
q=2378309513
In [74]:
n=p*q
In [75]:
d=pow(e,-1,(p-1)*(q-1))
In [76]:
e=17
In [77]:
# Encrypt this message
m=0x11bb112233445566
c=pow(m,e,n)
c
Out[77]:
8928775984050890995
In [78]:
blinding_factor=getrandbits(BITS)
blinding_factor
Out[78]:
14123525067114681355
In [79]:
# encrypt blinding factor, since we know e and n
# multiply c by it
new_c=c*pow(blinding_factor,e,n) % n
new_c
Out[79]:
3674308646917453413
In [82]:
# new_c is transmitted to decrypting code/device/server for decryption
decrypted=pow(new_c,d,n)
# device/server still can't deduce the true plaintext!
hex(decrypted)
Out[82]:
'0x281f61e67043d68c'
In [84]:
# restore true plaintext on client side:
hex(decrypted/blinding_factor)
Out[84]:
'0x11bb112233445566'
In [ ]: