This is the setup: I have both public and private keys of one "instance" of RSA. And I have only the public key of another RSA cryptosystem, but this system has the same modulus as the first one. I need to decrypt a message encrypted with second cryptosystem. I tried to go with approach explained in this book (6th page of pdf, Relation to factoring) http://cacr.uwaterloo.ca/hac/about/chap8.pdf . This is the code I have written using sage
[ea,da]=[39179044089, 156228379005810487826203993004368317129]
[n,eb]=[26878770809509021607148455705681865402854989, 41068762391]
m=45174946057484071617993476375198277813392972
x=ea*da-1
s=0
while mod(x,2)==0:
x = x / 2
s=s+1
t = Integer(x)
a = 2
i = 2
a0=1
a1=power_mod(a, t*2, n)
while(mod(a1,n)!=1) or (abs(Integer(mod(a0,n))) == 1):
if(i > s):
a = a + 1
i = 2
a0=1
a1=power_mod(a, t*2, n)
a0 = a1
a1 = power_mod(a, t*2^i, n)
i = i + 1
a0
This algorithm should give me a possible prime factor of n. But this code just gets stuck in the loop but I can't figure out why. I would appreciate any help or alternate solution to the problem.