Esempio n. 1
0
 def encrypt1():
     conn1 = sqlite3.connect('Database.db')
     with conn1:
         cursor1 = conn1.cursor()
     # Searching for users
     find_key = ('SELECT * FROM Users')
     cursor1.execute(find_key)
     key_users = cursor1.fetchall()
     print(username)
     for key_user in key_users:
         #print(key_user[2])
         if (username == key_user[2]):
             key = key_user[4]
             #print(type(key_user[4]))
     print(len(str(key)))  
     if key1_entry.get() == '': 
         ms.showerror('Oops', 'Enter key !!')
     elif key1_entry.get() == str(key):    
         file1 = filedialog.askopenfile(mode='r')
         if file1 is not None:
             file_name = file1.name
             enc = Encryptor(str(key))
             enc.encrypt_file(file_name)
             
     else:
         ms.showerror('Oops', 'Key is invalid !!')
Esempio n. 2
0
 def encrypt(self):
     if not os.path.exists("result"):
         os.makedirs("result")
     if not os.path.exists("key"):
          os.makedirs("key")
     encryption = Encryptor(self.file_path)
     encryption.save_file()
     parsed_image = self.parse_image(encryption.main_image, 500)
     self.label_image.setPixmap(parsed_image)
     self.file_path = encryption.encryption_path
     self.makeHistogram()
Esempio n. 3
0
def encode(info, img, tx, key):
    try:
        image = Image.open(img)
        contents = encode_file(tx, img)
        contents = contents + "*//*" + info
        encriptador = Encryptor()
        contents = encriptador.run(key, contents)
        st = stepic.encode(image, contents)
        name = img.split(".png")[0] + ".png"
        st.save(name, "png")
    except Exception as e:
        print(e)
Esempio n. 4
0
def main():
    file_name = input("Choose a file to load: ")
    encryptor = Encryptor(file_name)
    menu = 0
    while menu != "Q":
        menu = input(
            "\n\tE - Encrypt a message\n\tD - Decrypt a message\n\tQ - Quit\n\n"
        ).upper()
        print()
        if menu == "E":
            msg = input("Enter a message to encrypt: ")
            print(encryptor.encryptMessage(msg))
        elif menu == "D":
            msg = input("Enter a message to decrypt: ")
            print(encryptor.decryptMessage(msg))
Esempio n. 5
0
def KPIServer(datasource, kpidb):
    """\   KPIServer(datasource, kpidb) -> activates KPISever
    KPIServer is Session rekeying and Data transmission backend 
    Keyword arguments:
    - datasource -- any component with an outbox. the datasource
                    sends data to encryptor's inbox
    - kpidb    -- KPIDB instance for key lookup
    """
    Backplane("DataManagement").activate()
    Backplane("KeyManagement").activate()
    Graphline(ds=datasource,
              sc=SessionKeyController(kpidb),
              keyRx=subscribeTo("KeyManagement"),
              enc=Encryptor(),
              sender=publishTo("DataManagement"),
              pz=DataTx(),
              linkages={
                  ("ds", "outbox"): ("enc", "inbox"),
                  ("keyRx", "outbox"): ("sc", "userevent"),
                  ("sc", "notifykey"): ("enc", "keyevent"),
                  ("sc", "outbox"): ("pz", "keyIn"),
                  ("enc", "outbox"): ("pz", "inbox"),
                  ("pz", "outbox"): ("sender", "inbox"),
              }).activate()
Esempio n. 6
0
 def __init__(self):
     super(Client, self).__init__()
     self.messages = ""
     self.encryptor = Encryptor()
Esempio n. 7
0
 def load_cipher(self):
     self.e = Encryptor(self.load_file.get())
Esempio n. 8
0
 def __init__(self, master):
     self.encryptor = Encryptor("cipher1.txt")
     super(Application, self).__init__(master)
     self.grid()
     self.create_widgets()
Esempio n. 9
0
def main():
    global INPUT_FILE
    global OUTPUT_FILE

    args = argparse.ArgumentParser(description="Vigenère cipher decryption "
                                   "tool.")

    args.add_argument("-e",
                      "--encrypt",
                      help="Encrypt the input file",
                      action="store_true",
                      dest="mode_encrypt")
    args.add_argument('-k',
                      '--key',
                      help="Add custom key for encryption or "
                      "decryption")
    args.add_argument("-d",
                      "--decrypt",
                      help="Decrypt the input file",
                      action="store_true",
                      dest="mode_decrypt")
    args.add_argument("-i",
                      "--input-file",
                      help="The file from which the text"
                      " will be read to be "
                      "encrypted or decrypted")
    args.add_argument("-o",
                      "--output-file",
                      help="The file where the output "
                      "will be saved")
    args.add_argument("-v",
                      "--verbose",
                      help="Enable verbosity",
                      action="store_true")

    parser = args.parse_args()

    if not parser.mode_encrypt and not parser.mode_decrypt:
        display_error("Mode must be set using --encrypt or --decrypt options.")

    if parser.input_file:
        INPUT_FILE = parser.input_file

        try:
            with open(INPUT_FILE, "r") as _:
                pass
        except FileNotFoundError:
            display_error(f"The file '{INPUT_FILE}' does not exist.")
        except PermissionError:
            display_error(f"You do not have enough permissions to read the "
                          f"file '{INPUT_FILE}'")
    else:
        display_error("No input file provided.")

    if parser.output_file:
        OUTPUT_FILE = parser.output_file
    else:
        display_error("No output file provided")

    if parser.mode_encrypt:
        # Creating a new Encryptor object and uploading the plaintext to be
        # encrypted with a random key
        encryptor = Encryptor(parser.verbose)
        encryptor.read_plaintext_from_file(INPUT_FILE)

        if parser.key:
            encryptor.encrypt(parser.key)
        else:
            encryptor.encrypt()
        encryptor.save_ciphertext_to_file(OUTPUT_FILE)

        display_info("Encryption performed successfully.")
        display_info(f"Saved encrypted text to '{OUTPUT_FILE}'")
    else:
        # Now, prepare the decrypting process by creating a new Decryptor
        # object which will crack the key by itself
        enigma = Decryptor(parser.verbose)
        enigma.read_ciphertext_from_file(INPUT_FILE)

        if parser.key:
            decrypted_key = parser.key
            display_verbose(f"Decrypting using custom key "
                            f"[green]{decrypted_key}[/green] of length "
                            f"[yellow]{len(decrypted_key)}[/yellow]")
        else:
            decrypted_key = enigma.crack_key()

        enigma.decrypt(decrypted_key)
        enigma.save_decrypted_plaintext_to_file(OUTPUT_FILE)

        display_info("Decryption performed successfully.")
        display_info(f"Saved decrypted text to '{OUTPUT_FILE}'")
Esempio n. 10
0
 def __init__(self, rsa_pub_path=None, rsa_pri_path=None, p=None, g=None):
     self.dh = DiffieHellman(p, g) if p is not None and g is not None else None
     self.encryptor = Encryptor(rsa_pub_path)
     self.decryptor = Decryptor(rsa_pri_path)