Exemple #1
0
def main():
    while True:
        print "Choose from job"
        print "1.Key Generation"
        print "2.Encrytion"
        print "3.Decryption"
        print "4.Exit"
        choice = sys.stdin.readline()
 
        if (choice == '1\n'): 
            myKeyGenerator = keyGenerator()
            myKeyGenerator.keyGen()
            print "Key Generation Finished\n"
        elif (choice  == '2\n'):
            encryptor = Encryption()
            encryptor.encrypt()
            print "Encryption Finished\n"
        elif (choice == '3\n'):
            decryptor = Decryption()
            decryptor.decrypt()
            print "Decryption Finished\n"
        elif (choice == '4\n'):
            break;
        else: 
            print "invalid input"
            choice = sys.stdin.readline()
Exemple #2
0
    def crypt(argv):
        message = bitarray()
        with argv.Sourcefile as fh:
            message.fromfile(fh)

        key = bitarray()
        with argv.Keyfile as fh:
            key.fromfile(fh)

        start_time = datetime.now()

        encrypted = Encryption.encrypt(message, key)

        time_elapsed = datetime.now() - start_time
        print('Time elapsed (hh:mm:ss.ms) {}'.format(time_elapsed))

        with argv.Destinationfile as fh:
            encrypted.tofile(fh)
Exemple #3
0
class Encoder:

    MODES = {'GCM': 8}

    def __init__(self,
                 password,
                 source_image_folder_path,
                 destination_image_folder_path,
                 mode='GCM'):
        self.mode = Encoder.MODES[mode]
        self.source_image_folder_path = source_image_folder_path
        self.destination_image_folder_path = destination_image_folder_path
        if os.path.exists(self.destination_image_folder_path):
            shutil.rmtree(self.destination_image_folder_path)
        os.makedirs(self.destination_image_folder_path)

        self.gcm = GCM()
        self.gcm.make_key(password)
        self.transcriber = Transcriber(self.mode, source_image_folder_path,
                                       destination_image_folder_path)

    def encode_file(self, file_path):
        with open(file_path, 'rb') as source:
            file_bytes = source.read()
            encrypted = self.gcm.encrypt(file_bytes)
            tag = self.gcm.encrypt_finalize()

        header = self.gcm.password_salt + self.gcm.iv

        full_length = len(header) + len(encrypted) + len(tag)
        # if not self.transcriber.can_fit_bytes(full_length):
        #     print("Not enough images to store the necessary data")
        #     exit()
        self.transcriber.choose_needed_images(full_length)

        print("full length", full_length, full_length * 8)

        self.transcriber.set_encoding(header + encrypted + tag)
        # with open("encode-test", "wb") as f:
        #     f.write(header + encrypted + tag)
        self.transcriber.finish_encoding()
Exemple #4
0
 def __init__(self, word, count):
     word_to_hash = str.encode(word + Config['hashing_salt'])
     self.hashed_id = sha512(word_to_hash).digest()
     self.count = count
     self.encrypted_word = Encryption.encrypt(str.encode(word))