문제 설명
기본 숫자를 10 ^ 9 이상으로 늘리면 코드가 작동하지 않습니다. (Code fails to work when i increase the base numbers to anything over 10 ^ 9)
저는 소수인 두 개의 기본 숫자를 요구하는 RSA 암호화 프로그램을 작성 중입니다. 크면 클수록 좋습니다. 아래는 메소드의 코드입니다.
def PrimeNumber(self):
number=random.randint(10**8, 10**9)
while True:
prime = self.PrimeTest(number)
if prime:
return number
number+=1
이 형식의 코드는 완벽하게 작동하지만 난수 생성기를 변경하여 10 ^ 9보다 큰 숫자를 생성하면 암호 해독으로 이동할 때 코드가 더 이상 작동하지 않습니다. 아래 메시지(아래에서 수행 방법 설명)는 마사지를 암호화 및 암호 해독하는 데 사용하는 방법입니다.</ p>
def encryption(self,m):
c=1
y =self.publicKey[0]
d = self.publicKey[1]
m=m%y
for num in range (d):
c=((c*m)%y)
return c
def decryption(self,base):
total = 1
power = self.d
y = self.num
while power > 0:
r = power % 2
if r == 1:
total = (total base) % y
base = (base base) % y
power = power// 2
return total
</code></pre>
이 함수는 서로 역이며 숫자가 10^9 이하일 때 다시 작동합니다. 메시지를 암호화하기 위해 문자열을 분리하고 문자를 ASCII 번호로 변경한 다음 해당 숫자를 암호화하고 해독을 위해 역순으로 수행합니다. RSA에 대해 잘 모르는 경우 RSA에 대한 간략한 설명입니다. <a href="https:/ /ko
참조 솔루션
(by M.Trossman)
참조 문서