Пример #1
0
def solve_common_factors(ciphertexts, modulos, exponents):
    plaintexts = []
    factors_found = []
    for i in range(len(modulos)):
        for j in range(i + 1, len(modulos)):
            calc_gcd = gcd(modulos[i], modulos[j])
            if calc_gcd > 1:
                factors_found.append([i, j, calc_gcd])

    for mod_pair in factors_found:

        # Get factors of n1 and n2
        calc_gcd = mod_pair[2]
        q1 = modulos[mod_pair[0]] / calc_gcd
        q2 = modulos[mod_pair[1]] / calc_gcd

        # Decrypt c1
        c1 = ciphertexts[mod_pair[0]]
        e1 = exponents[mod_pair[0]]
        p1 = decrypt(c1, e1, modulos[mod_pair[0]], p=calc_gcd, q=q1)

        # Decrypt c2
        c2 = ciphertexts[mod_pair[1]]
        e2 = exponents[mod_pair[1]]
        p2 = decrypt(c2, e2, modulos[mod_pair[1]], p=calc_gcd, q=q2)

        plaintexts.append(p1)
        plaintexts.append(p2)
    return plaintexts
Пример #2
0
def main():
    #Use argparse to parse arguments
    parser = argparse.ArgumentParser(conflict_handler='resolve')
    parser.add_argument('-d',
                        '--decrypt',
                        metavar='<key>',
                        help='Uses <key> to decrypt a file')
    parser.add_argument('-e',
                        '--encrypt',
                        metavar='<key>',
                        help='Uses <key> to encrypt a file')
    parser.add_argument('-f',
                        '--file',
                        metavar='<file>',
                        help='The <file> to encrypt')
    requiredNamed = parser.add_argument_group('required named arguments')
    requiredNamed.add_argument('-o',
                               '--outfile',
                               metavar='<filename>',
                               help='Writes output to <filename>')
    requiredNamed.add_argument(
        '-w',
        '--wave',
        metavar='<wave>',
        help='The <wave> to hide an encrypted <file> in using LSB steganography'
    )
    args = parser.parse_args()

    # Validates Arguments
    validate_args(args)

    # Print splash
    splash()

    # Load wave
    parsed_wave = wavparser.ParsedWave(args.wave)
    if parsed_wave.binary:
        parsed_wave.debug()
    else:
        print("ERROR: unable to parse {} as a wave".format(args.wave))
        return

    # Check encrypt/decrypt flag
    if args.encrypt:
        encrypted_data = utilities.encrypt(args.file, args.encrypt)
        parsed_wave.encode_data(encrypted_data)
        parsed_wave.write_to_file(args.outfile)
    else:
        encrypted_data, error_found = parsed_wave.decode_data()
        if error_found:
            print("ERROR: Wave file does not appear to contain encoded data")
            exit(1)
        utilities.decrypt(encrypted_data, args.decrypt, args.outfile)

    print("STATUS: Success! Output file {} has been produced".format(
        args.outfile))

    # Exit
    exit(0)
Пример #3
0
    def load_credentials(self,passphrase=''):
        '''
        Tries to load the credentials from the configuration file
        and display them to the user. If the credentials in the
        configuration file are invalid, they will not be loaded.
        '''
        savedPassword = True        #a default condition is needed.
        key = self.gox.config.get_string("gox", "secret_key")
        secret = self.gox.config.get_string("gox", "secret_secret")
        if not passphrase:          #if password is blank (default NOT stored)
            savedPassword = False   #then change the default condition to False
            #and grab password from the password tab password box.
            self.passphrase = str(self.mainWindow.passwordLineEdit.text())
        try:
            utilities.assert_valid_key(key)
            secret = utilities.decrypt(secret, self.passphrase)
        except Exception:
            key = ''
            secret = ''

        self.secret.key = key
        self.secret.secret = secret
        if not key == '' and not secret == '':
            #if everything is OK, set the placeholder text to show credentials were loaded OK
            self.mainWindow.lineEditKey.setPlaceholderText('Loaded Key From File')
            self.mainWindow.lineEditSecret.setPlaceholderText('Decrypted Secret Using Password')
            #and switch current tab back to the main Account Balance Tab
            self.mainWindow.tabWidget_1.setCurrentIndex(0)
            if not savedPassword:       #check for default password. if not, restart the socket.
                self.status_message("Credentials changed. Restarting MtGox Client")
                self.restart_gox()      #restart the gox socket.
        else:
            self.status_message("Key and Secret are blank. Enter them and click Apply.")
            self.mainWindow.tabWidget_1.setCurrentIndex(1)
Пример #4
0
    def get_secret(self):
        '''
        Loads the secret from the configuration file.
        '''
        secret = self.__get('secret')
        if secret == '':
            return secret

        return utilities.decrypt(secret, Preferences.__PASSPHRASE)
Пример #5
0
    def decrypt_secret(self,password=''):
        
        secret = self.get('secret')
        if secret == '':
            return ''
        if password == '':
            password = self.get('password')

        return utilities.decrypt(secret, password)
Пример #6
0
 def __init__(self, keyfile):
     self.keyfile = keyfile
     self.connection = sqlite3.connect(':memory:')
     with open(self.keyfile.database_path, 'rb') as f:
         try:
             self.connection.executescript(
                 utilities.decrypt(
                     self.keyfile.key,
                     self.keyfile.iv, f.read()))
         except sqlite3.OperationalError:
             raise ValueError('Could not decrypt database')
Пример #7
0
    def load_credentials(self):
        '''
        Tries to load the credentials from the configuration file
        and display them to the user. If the credentials in the
        configuration file are invalid, they will not be loaded.
        '''

        key = self.gox.config.get_string("gox", "secret_key")
        secret = self.gox.config.get_string("gox", "secret_secret")

        try:
            utilities.assert_valid_key(key)
            secret = utilities.decrypt(secret, View.PASSPHRASE)
        except Exception:
            key = ''
            secret = ''

        self.secret.key = key
        self.mainWindow.lineEditKey.setText(key)
        self.secret.secret = secret
        self.mainWindow.lineEditSecret.setText(secret)
Пример #8
0
    def load_credentials(self):
        '''
        Tries to load the credentials from the configuration file
        and display them to the user. If the credentials in the
        configuration file are invalid, they will not be loaded.
        '''

        key = self.gox.config.get_string("gox", "secret_key")
        secret = self.gox.config.get_string("gox", "secret_secret")

        try:
            utilities.assert_valid_key(key)
            secret = utilities.decrypt(secret, View.PASSPHRASE)
        except Exception:
            key = ''
            secret = ''

        self.secret.key = key
        self.mainWindow.lineEditKey.setText(key)
        self.secret.secret = secret
        self.mainWindow.lineEditSecret.setText(secret)
Пример #9
0
 def test_encrypt_decrypt_ok(self):
     text = '/GU3lmrgX9LCG7cIpGySlgVIVT8t8CKn3p/uayvc57Z98UhYJYy4/eIdEvi5VSuFd/vwMTroy8ELc5VbqWdQWg==' # @IgnorePep8
     password = '******'
     encrypted = utilities.encrypt(text, password)
     self.assertEqual(text, utilities.decrypt(encrypted, password))
Пример #10
0
 def unlock(self, pin):
     if self.plainpassword is None:
         key = utilities.generate_key(self.domain, self.username, pin)
         self.plainpassword = utilities.decrypt(key, self.iv, self.cipherpassword)
     return self.plainpassword