%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/waritko/suave/
Upload File :
Create Path :
Current File : //home/waritko/suave/KRYtester.py

import sys
if sys.version_info[0] < 3:
    raise "Chci byt spusten v pythonu 3 !!"
    
import subprocess
import os
from random import choice
import string

encryptDecriptOnly = True  # If True, RSA key is generated by python RSA lib
generateMessage = True      # If True, random message is generated
messageSize = 10            # Number of hexa chars in message
keySize = 512               # RSA Key (n) size
testNum = 50                # Number of tests

orig_message = "0x2AF37BC48D1"
app_name = "kry"

################################################################################
rsaImported = False
try:
	import rsa
	rsaImported = True
except ImportError:
	pass 

app_path = os.path.join(os.getcwd(), app_name)

def randomHex(length=8, chars=string.hexdigits):
    return "0x" + ''.join([choice(chars) for i in range(length)])

def runProcess(params=[]):
    args = ' '.join(str(e) for e in params)
    kry_output = subprocess.check_output(app_path + " " + args, shell=True)
    results = []
    for param in kry_output.decode("utf-8").split():
        results.append(hex(int(param, 0)))
    return results


successCounter = 0
for x in range(0, testNum):
    if generateMessage:
        orig_message = randomHex(messageSize)

    if encryptDecriptOnly and rsaImported:
        RSAkey = rsa.newkeys(keySize)
        keyChain = [hex(RSAkey[1].p), hex(RSAkey[1].q), hex(RSAkey[1].n), hex(RSAkey[1].e), hex(RSAkey[1].d)]
    else:
        keyChain = runProcess(["-g", keySize])

    ciphertext = runProcess(["-e", keyChain[3], keyChain[2], orig_message])
    message = runProcess(["-d", keyChain[4], keyChain[2], ciphertext[0]])
    if int(orig_message, 0) == int(message[0], 0):
        #print("SUCCESS")
        print("-g  >> " + ", ".join(keyChain))
        print("-e  >> " + ", ".join(ciphertext))
        print("-d  >> " + ", ".join(message))
        print("orig>> " + orig_message.lower())
        successCounter += 1
    else:
        print("FAILED")
        print("-g  >> " + ", ".join(keyChain))
        print("-e  >> " + ", ".join(ciphertext))
        print("-d  >> " + ", ".join(message))
        print("orig>> " + orig_message.lower())

print("Total: " + str(testNum) + " Success: " + str(successCounter) +" >> " + str((successCounter/testNum) * 100) + "%")

Zerion Mini Shell 1.0