Beispiel #1
0
def main():
  print(sys.argv)
  CRT = True
  k = 6
  d = 256
  keygen = Keygen()
  decryptor = Decryptor()
  encryptor = Encryptor()
  file_processor = File_processor()
  keys = keygen.generate_keys(k,  d, CRT)
  file_processor.save_keys(keys, CRT)
  file_processor.read_keys(CRT)
  start_time = timer()
  encrypted = encryptor.encrypt(keys['public_n'], keys['public_e'], 'data/plain.txt', CRT)
  print("ENCRYPTION TIME MEASUE:")
  print(timer() - start_time) 
  start_time = timer()
  decrypted = decryptor.decrypt(keys, CRT, k, 'data/plain.txt.enc')
  print("DECRYPTION TIME MEASUE:")
  print(timer() - start_time) 
  print(decrypted)
  return 0
Beispiel #2
0
    main()
  elif sys.argv[1] == 'gen':
    k, d = int(sys.argv[2]), int(sys.argv[3])
    CRT = True if int(sys.argv[4]) == 1 else False
    keygen = Keygen()
    file_processor = File_processor()
    start_time = timer()
    keys = keygen.generate_keys(k,  d, CRT)
    file_processor.save_keys(keys, CRT)
  elif sys.argv[1] == 'enc':
    CRT = True if int(sys.argv[2]) == 1 else False
    file_processor = File_processor()
    keys = file_processor.read_keys(CRT)
    encryptor = Encryptor()
    start_time = timer()
    encrypted = encryptor.encrypt(keys['public_n'], keys['public_e'], 'data/plain.txt', CRT)
    print("ENCRYPTION TIME MEASUE:")
    print(timer() - start_time) 
  elif sys.argv[1] == 'dec':
    k = int(sys.argv[2])
    CRT = True if int(sys.argv[3]) == 1 else False
    file_processor = File_processor()
    keys = file_processor.read_keys(CRT)
    decryptor = Decryptor()
    start_time = timer()
    decrypted = decryptor.decrypt(keys, CRT, k, 'data/plain.txt.enc')
    print("DECRYPTION TIME MEASUE:")
    print(timer() - start_time) 
    print(decrypted)

Beispiel #3
0
    if(output_file is None):
        split_extension = encrypted_file.name.rsplit('.', 1)
        output_file = "{}_decrypted.{}".format(split_extension[0], split_extension[1])

    output_dir = output_file[:output_file.rindex('/')]

    if os.path.isdir(output_dir) is False:
        print("Invalid output file '{}' provided.".format(output_file))
        sys.exit(1)

    return output_file

def getArgs():
    arg_parser = argparse.ArgumentParser(description='File decrypter.')
    arg_parser.add_argument('file', help='Path to the encrypted file to decrypt.', type=argparse.FileType('r'))
    arg_parser.add_argument('--output_file', '-o', help='Path to save the decrypted output file to.', type=str)
    args = arg_parser.parse_args()

    args.output_file = fix_output_file(args.output_file, args.file)
    return args


if __name__ == "__main__":
    #args = getArgs()
    decryptor = Decryptor()
    result = decryptor.decrypt("Znoy oy gt ktixevzkj yktzktik zngz O gs zkyzotm cozn. Znkxk oy vatizagzout otburbkj, yotik O cgtz zu zkyz zngz oz yzorr cuxqy cozn vatizagzout.")
    if result.solution_found is True:
        print("Result: {}\nCertainty: {:.1f}%".format(result.text, result.solution_certainty*100))
    else:
        print("Did not find a solution")
Beispiel #4
0
                    print("Sent at: ", myMsg['createdAt'])
                    body = myMsg['message_body']                    #get message body
                    bodyList = body.split(" ")                      #parse message body into list
                    HMAC = None                                     #init body fields
                    Keys = None
                    Msg = None
                    try:                                            #get body fields
                        HMAC = bodyList[1]
                        Keys = bodyList[3]
                        Msg = bodyList[5]
                    except:
                        print("Parse failed")

                    try:                                            #Decrypt message
                        data = {'HMAC': HMAC, 'Keys': Keys, 'Msg': Msg}
                        print("My decrypted msg: ", myDecryptor.decrypt(data))
                    except:
                        print("Decrypt failed\n")

                    print("\n")
        elif(option == '3'):
            session = False                                     #session boolean = false
            print("Logging out user: "******"Invalid option selected\n")
elif(choice =='2'):
    regEmail = input("Input registration email: ")
    regPass = input("Input password: ")
    myClient = Client(loginURL)
    myClient.register(regEmail, regPass)
Beispiel #5
0
from encryptor import Encryptor
from decryptor import Decryptor
publicCertificate = "/Users/mcastro/Desktop/public.pem"
privateCertificate = "/Users/mcastro/Desktop/private.pem"
jsonFile = "/Users/mcastro/Desktop/encrypt.json"

keysize = 32  #32 bytes
blockSize = 128  #128 bits
ivSize = 16  #16 bytes

inputString = input("Input message to encrypt: ")
print("Encrypting message: ", inputString)
myEncryptor = Encryptor(keysize, blockSize, ivSize, inputString,
                        publicCertificate, jsonFile)
myEncryptor.encrypt()
print("Message encrypted")

print("\nMessasge will now be decrypted")
myDecryptor = Decryptor(keysize, blockSize, ivSize, jsonFile,
                        privateCertificate)
myDecryptor.decrypt()
Beispiel #6
0
def main():
    with open('data.txt', 'r') as file:
        dec = Decryptor(file.read())

    print(dec.decrypt())