私はWikiのRSAアルゴリズムに従っています:http://en.wikipedia.org/wiki/RSA_(algorithm)
Python 3.3.0を使用していて、RSA暗号化を実行しようとしていますが、実行方法がわからない2つの問題が発生しました。
Encryptionクラスでは、メソッドがクラスのメソッドであり、グローバル関数ではないことを示すために、すべてのメソッドを1レベルインデントする必要があります。
メインスクリプトが最後に入力を要求するときに、returnキーを押すと、Pythonが予期しないEOFに到達したという例外がスローされます。
どうやってやるの ?
これまでの私のコード:
Modular.py
def _base_b_convert(n, b):
if b < 1 or n < 0:
raise ValueError("Invalid Argument")
q = n
a = []
while q != 0:
value = int(q % b)
a.append(value)
q =int(q / b)
return a
def mod_exp(base, n, mod):
if base < 0 or n < 0 or mod < 0:
raise ValueError("Invalid Argument")
a = (_base_b_convert(n, 2))
x = 1
pow = base % mod
for i in range(0, len(a)):
if a[i] == 1:
x = (x * pow) % mod
pow = pow**2 % mod
return x
main.py
from encryptions import Encryptions
def main():
enc = Encryptions()
message = enc.encrypt(message)
print(message)
print()
print("Decrypting message:")
message = enc.decrypt(message)
print(message)
input("--Press any key to end--")
if __name__ == '__main__':
main()