예제 #1
0
def main(path, password):
    print("\nCWD: " + path)  #Current working directory
    files = []
    directories = []

    for f in os.scandir(
            path):  #iterates through all files and directories in given path
        if (f.is_file()): files.append(f.name)
        else: directories.append(f.name)

    for file in files:
        cyphertext = decode(password, file)  #encrypt
        try:
            os.rename(path + '/' + file,
                      path + '/' + cyphertext)  #change name to encrypted one
        except Exception as e:
            print(file)
            print(str(e))

    for directory in directories:
        main(path + '/' + directory, password)  #recurse on all sub-directories
        cyphertext = decode(password, directory)
        try:
            os.rename(path + '/' + directory,
                      path + '/' + cyphertext)  #change directory name
        except Exception as e:
            print(directory)
            print(str(e))
예제 #2
0
def get_credential(user_flock_id, plugin):
    user_cred = db_models.Credential.query.\
        filter(db_models.Credential.plugin == plugin, db_models.Credential.id == user_flock_id).first()
    if not user_cred:
        return False
    e_username = crypto.decode(user_cred.username)
    e_password = crypto.decode(user_cred.password)
    return e_username, e_password
예제 #3
0
def searchPass(username, description):  #search a password by its description
    archive_name = 'enc_' + username + '.csv'
    already_exists = os.path.isfile(archive_name)
    if already_exists:
        crypto.decodeUserDatabase(username)
        archive_name = username + '.csv'
        flag = False
        with open(archive_name, 'r') as table:
            data = csv.reader(table)
            for line in data:
                if line[0] == description:
                    password = bytes(line[1],
                                     'utf-8')  #converting password to bytes
                    password = str(crypto.decode(password))  #decoding password
                    password = operations.filter_pass(
                        password)  #filtering password
                    flag = True
                    break
        crypto.encodeUserDatabase(username)
        if flag == True:
            return password
        else:
            return False
    else:
        return False
예제 #4
0
파일: demo.py 프로젝트: khodi7/encodator
    def show_registered_message(self,
                                password_file,
                                display_speed,
                                ciphered_message_file="message.txt",
                                fingerprint_file="fingerprint.txt"):
        """
        pre : password, ciphered_message_file et fingerprint_file sont des strings.
        display_speed est un boolean.
        post : montre le message dechiffré a l'aide de password si celui-ci etait correct.
        """
        red = [255, 0, 0]
        try:
            with open(password_file) as file:
                password = file.readline()
                if len(password) == 0:
                    self.show_message("Merci d'entrer un mot de passe",
                                      display_speed, red)
                    return None
        except FileNotFoundError:
            self.show_message("Merci d'entrer un mot de passe", display_speed,
                              red)
            return None

        try:
            with open(ciphered_message_file) as file:
                ciphered_message = file.readline()
                if len(ciphered_message) == 0:
                    self.show_message("Aucun message enregistre",
                                      display_speed, red)
                    return None
        except FileNotFoundError:
            self.show_message(
                "Pas de fichier {0}".format(ciphered_message_file),
                display_speed, red)
            return None

        try:
            with open(fingerprint_file) as file:
                fingerprint = file.readline()
                if len(fingerprint) == 0:
                    self.show_message("Aucune emprunte enregistree",
                                      display_speed, red)
                    return None
        except FileNotFoundError:
            self.show_message("Pas de fichier {0}".format(fingerprint_file),
                              display_speed, red)
            return None

        if crypto.hashing(password) != fingerprint:
            self.show_message("Mauvais mot de passe", display_speed, red)
            return None

        else:
            message = crypto.decode(password, ciphered_message)
            self.show_message(message, display_speed)
예제 #5
0
def decode_page():
    key: str = request.args.get('key', 'None')
    string: str = request.args.get('string', 'None')
    if key == "None":
        return {
            "error": True,
            "status": 400,
            "message": "no key was provided. CDO804719"
        }
    else:
        return decode(string, key)
예제 #6
0
def main(path, password):
    decodedList = []

    for file in os.scandir(
            path):  #iterates through all files and directories in given path
        cyphertext = file.name
        plaintext = decode(password, cyphertext)  #decrypt
        decodedList.append([cyphertext, plaintext])

    for i in range(0, len(decodedList)):  #show the decryptions
        print("%d.%s" % (i + 1, decodedList[i][1]))

    #now wait if the user wants to play a video file
    while (True):
        print('\n')
        no = int(input("Enter serial number of file to play:"))
        command = 'vlc ' + path + '/' + decodedList[no - 1][0]
        os.system(command)
예제 #7
0
def see_message(path):
    """
    Demande le mot de passe et affiche le mot de passe si celui-ci est correct.
    :path: (str) le chemin vers le fichier texte de l'image cliquee
    """
    sense.show_message("Entrez le MDP", 0.05)
    password = get_password()
    with open(path, "r") as file:
        # La variable `lines` est une liste contenant chaque ligne de texte du
        # fichier actuellement ouvert sous la forme de strings sans \n a la fin
        lines = [x.strip() for x in file.readlines()]
        if crypto.hashing(password) == lines[1]:
            decoded_msg = crypto.decode(password, lines[0])
            sense.show_message(decoded_msg, 0.05, (0, 255, 0))
            # Apres affichage du message, demander a l'agent s'il souhaite
            # conserver ou supprimer ce message.
            keep_or_del(path)
        else:
            sense.show_message('MDP incorrect!', 0.05)
            return
예제 #8
0
def seePasswords(username):  #list every registered password of an user
    archive_name = 'enc_' + username + '.csv'
    already_exists = os.path.isfile(archive_name)
    if already_exists:
        crypto.decodeUserDatabase(username)
        archive_name = username + '.csv'
        with open(archive_name, 'r') as table:
            data = csv.reader(table)
            next(data)  #don't wanna fist line
            for line in data:
                description = line[0]  #get description from .csv
                password = line[1]  #get encoded password from .csv
                password = bytes(password, 'utf-8')  #converting to bytes
                password = str(crypto.decode(password))  #decoding password
                password = operations.filter_pass(
                    password)  #filtering password
                print(' ' + description + ' - ' + password)
        crypto.encodeUserDatabase(username)
        return True
    else:
        return False
예제 #9
0
파일: main.py 프로젝트: wuxh123/Rhinoceros
    def _auth(self):

        params = {'user': self.cfgs.get('account'), 'pwd': self.cfgs.get('password')}

        data = urllib.urlencode(params)
        data = crypto.encode(data)
        params={
            'client_id': self.cfgs.get('client_id')
        }

        url = self.cfgs.get('auth_url') + '/' + data
        # print 'auth request:'+ url
        cert = os.path.join(instance.getConfigPath(),self.cfgs.get('cert_file'))
        resp = requests.post(url,params,verify=cert)
        # print resp.text
        data = crypto.decode(resp.text)
        data = json.loads(data)
        if data.get('status') !=1001:
            instance.getLogger().warning('adapter(zjxl) auth request failed. status:%s'%data.get('status'))
            return False
        self.token = data.get('result')
        instance.getLogger().debug('adapter(zjxl) auth-token:'+ self.token)
예제 #10
0
파일: main.py 프로젝트: wuxh123/Rhinoceros
    def __request_getLocation(self,vehicles):

        self._auth()
        # for vehicle_id in vehicles:
        carnums = ','.join(vehicles)

        params = {'token': self.token, 'vclN': carnums.encode('utf-8'),'timeNearby':30 }
        data = urllib.urlencode(params)
        data = crypto.encode(data)

        url = self.cfgs.get('access_url_batch') +'/' + data
        params = {'client_id': self.cfgs.get('client_id')}

        cert = os.path.join(instance.getConfigPath(), self.cfgs.get('cert_file'))
        resp = requests.post(url, params, verify=cert)
        print resp.text
        data = crypto.decode(resp.text)
        data = json.loads(data)
        if data.get('status') != 1001:
            instance.getLogger().warning('adapter(zjxl) getLocation request failed. status:%s'%data.get('status'))
            return False

        resp = requests.post(url, data=params)
        content = resp.json()
        if content.get('code', -1) != 0:  # 0: okay else false
            return
        data = content.get('result', {})
        loc = LocationData(vehicle_id)  # spawn location point
        loc.version = '0.1'
        loc.provider = ProviderType.ZJXL.value
        loc.lon = int(data.get('lng', 0))/600000.0
        loc.lat = int(data.get('lat', 0))/600000.0
        loc.speed = float(data.get('spd', 0))
        loc.time = int(data.get('utc', 0))  #
        loc.direction = int( data.get('drc',0))
        loc.extra['address'] = data.get('adr', '')
        self._onDataReady(vehicle_id, loc)
예제 #11
0
파일: main.py 프로젝트: wuxh123/Rhinoceros
    def _request_getLocation(self,vehicles):
        # return self.__request_getLocation(vehicles)

        self._auth()
        for vehicle_id in vehicles:
        # carnums = ','.join(vehicles)

            params = {'token': self.token, 'vclN': vehicle_id.encode('utf-8'),'timeNearby':30 }
            data = urllib.urlencode(params)
            data = crypto.encode(data)

            url = self.cfgs.get('access_url') +'/' + data
            params = {'client_id': self.cfgs.get('client_id')}

            cert = os.path.join(instance.getConfigPath(), self.cfgs.get('cert_file'))
            resp = requests.post(url, params, verify=cert)
            # print resp.text
            data = crypto.decode(resp.text)
            data = json.loads(data)
            if data.get('status') != 1001:
                instance.getLogger().warning('adapter(zjxl) getLocation request failed. status:%s'%data.get('status'))
                return False
            loc = self.assignLocation(vehicle_id,data)
            self._onDataReady(vehicle_id, loc)
예제 #12
0
    if connect(ssid, psw) == True:
        try:
            file = open("wifi_config", "w")
            file.write(crypto.encode(ssid + "." + psw))
        except OSError:
            print("Kayıt hatası.")
        finally:
            file.close()
    else:
        print('\033[31m',
              "Wifi bağlanamadı lütfen Ağ adı ve parolayı yeniden girin")
        config()


try:
    file = open("wifi_config", "r")
    credidentials = crypto.decode(file.read())
    crd = credidentials.split(".")
    file.close()
    if connect(crd[0], crd[1]) == False:
        print('\033[31m',
              "Wifi bağlanamadı lütfen Ağ adı ve parolayı yeniden girin")
        config()

except OSError:
    print(
        '\033[31m',
        "Wifi ağ adı ve parola kayıtlı değil kayıt için lütfen aşağıdaki ağlardan birisini seçin"
    )
    config()