Added commands: genrand, genprime
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
ec2bbf116b
commit
b034158d2f
14
rsa.py
14
rsa.py
@ -118,6 +118,12 @@ def main():
|
||||
if sys.argv[1] == "is_prime_mr" and len(sys.argv) == 4: #rsa is_prime_mr <base> <N>
|
||||
isPrime_cmd(1)
|
||||
sys.exit(0)
|
||||
if sys.argv[1] == "genrand" and len(sys.argv) == 3: #rsa genrand <bits>
|
||||
print(gen_random(int(sys.argv[2])))
|
||||
sys.exit(0)
|
||||
if sys.argv[1] == "genprime" and len(sys.argv) == 3: #rsa genprime <bits>
|
||||
print(getPrime(int(sys.argv[2])))
|
||||
sys.exit(0)
|
||||
if sys.argv[1] == "print" and len(sys.argv) == 3: #rsa print <key>
|
||||
printKey(readKeyFile(sys.argv[2]))
|
||||
sys.exit(0)
|
||||
@ -190,9 +196,9 @@ def getPrime(bits):
|
||||
x = int.from_bytes(os.urandom(int(bits/8)), byteOrder)
|
||||
print('Trying: ', x, end="\n")
|
||||
if mr.is_prime(x):
|
||||
print("\nprime: ", x)
|
||||
print("\nprime: ", x, '\n')
|
||||
return x
|
||||
backTrack(x)
|
||||
#backTrack(x)
|
||||
|
||||
|
||||
def isPrime(number):
|
||||
@ -217,6 +223,10 @@ def isPrime(number):
|
||||
return False
|
||||
return True
|
||||
|
||||
def gen_random(bits: int):
|
||||
x = int.from_bytes(os.urandom(int(bits/8)), byteOrder)
|
||||
return x
|
||||
|
||||
def sign(encrypted_msg, key):
|
||||
enc_msg = str(encrypted_msg)
|
||||
encrypted_msg_list = enc_msg.split()
|
||||
|
Loading…
Reference in New Issue
Block a user