Esempio n. 1
0
def delete_file(filename):
    try:
        if '.' not in filename:
            ch = ''
            while ch != 'Y' and ch != 'N':
                ch = raw_input("Are you trying to delete a folder?(Y/N)? ").upper()
            if ch == 'Y':
                directory = validate_dir(filename)
                if directory == -1:
                    return False
                rmtree(directory)
                s = directory + " has been deleted"
                print(s)
                return True
            else:
                final_path = validate_file(filename)
        else:
            final_path = validate_file(filename)
        if final_path != -1:
            remove(final_path)
            s = final_path+" has been deleted"
            print(s)
            return True
        return False
    except Exception as e:
        print('Exception thrown in deleteFile() ' + str(e))
Esempio n. 2
0
def move_file_type_2(filename, source, destination):
    try:
        if source.upper() in ["THIS", "CURRENT", "PRESENT", "THE"]:
            source = getcwd()
        if destination.upper() in ["THIS", "CURRENT", "PRESENT", "THE"]:
            destination = getcwd()
        src1 = source + "\\" + filename
        if '.' not in src1:
            ch = ''
            while ch != 'Y' and ch != 'N':
                ch = raw_input("Are you trying to move a folder?(Y/N)? ").upper()
            if ch == 'Y':
                src1 = validate_dir(src1)
            else:
                src1 = validate_file(src1)
        else:
            src1 = validate_file(src1)
        if src1 == -1:
            return False
        dst1 = validate_dir(destination)
        if dst1 == -1:
            return False
        move(src1, dst1)
        s = src1 + " has been moved to " + dst1
        print(s)
        return True
    except Exception as e:
        print("Exception occurred in moveFile(f,s,d)" + str(e))
        return False
Esempio n. 3
0
def audio_encrypt(filename, msg):
    output_filename = ""
    if filename != "":
        if not filename.endswith(".wav"):
            print("Invalid image file format! Encryption only accepts .wav audio file")
            return False
        filename = validate_file(filename)
        if filename == -1:
            return False
    else:
        files = listdir(getcwd())
        for i in files:
            if i.endswith(".wav"):
                filename = i
                print filename
                break
        flag = 0
        if filename != "":
            print("Found some audio files in the current directory")
            ch = raw_input("Do you want me to encrypt on "+filename+"?(Y/N)? ").upper()
            if ch == 'Y':
                flag = 1
        if flag == 0:
            ch = raw_input("Would you like to enter a filename?(Y/N)? ").upper()
            if ch == 'Y':
                filename = raw_input("Enter the filename: ")
                filename = validate_file(filename)
                if filename == "-1":
                    return False
            else:
                ch = raw_input("Would you like me to encrypt it on any random file?(Y/N)").upper()
                if ch == 'Y':
                    files = listdir(FILE_PATH+"Audio")
                    output_filename = choice(files)
                    filename = FILE_PATH+"Audio\\"+output_filename
                    output_filename = output_filename[:-4]+"_encrypted.wav"
                else:
                    return False
    aud = Steganography.open(filename, "rb")
    if msg == "":
        msg = raw_input("Enter a message to be hidden: ")
    new_data = Steganography.audio_encryption(aud, msg)
    x = 1
    if output_filename == "":
        output_filename = filename[:-4] + "_encrypted.wav"
    while isfile(output_filename):
        output_filename = output_filename[:-4] + str(x) + ".wav"
        x += 1
    new_aud = Steganography.open(output_filename, "wb")
    new_aud = Steganography.set_params(new_aud, aud)
    new_aud.writeframes(new_data)
    new_aud.close()
    print("Encryption Done")
    print("File is saved as: "+output_filename)
    startfile(output_filename)
    return True
Esempio n. 4
0
def encrypt(filename,  msg):
    output_filename = ""
    if filename != "":
        if not filename.endswith(".png"):
            print("Invalid image file format! Encryption only accepts .png file")
            return False
        filename = validate_file(filename)
        if filename == -1:
            return False
    else:
        files = listdir(getcwd())
        for i in files:
            if i.endswith(".png"):
                filename = i
                print filename
                break
        flag = 0
        if filename != "":
            print("Found some image files in the current directory")
            ch = raw_input("Do you want me to encrypt on "+filename+"?(Y/N)? ").upper()
            if ch == 'Y':
                flag = 1
        if flag == 0:
            ch = raw_input("Would you like to enter a filename?(Y/N)? ").upper()
            if ch == 'Y':
                filename = raw_input("Enter the filename: ")
                filename = validate_file(filename)
                if filename == "-1":
                    return False
            else:
                ch = raw_input("Would you like me to encrypt it on any random file?(Y/N)").upper()
                if ch == 'Y':
                    files = listdir(FILE_PATH+"Image")
                    output_filename = choice(files)
                    filename = FILE_PATH+"Image\\"+output_filename
                    output_filename = output_filename[:-4]+"_encrypted.png"
                else:
                    return False
    img = Steganography.imread(filename)
    if msg == "":
        msg = raw_input("Enter a message to be hidden: ")

    new_img = Steganography.image_encryption(img, msg)
    x = 1
    if output_filename == "":
        output_filename = filename[:-4] + "_encrypted.png"
    while isfile(output_filename):
        output_filename = output_filename[:-4] + str(x) + ".png"
        x += 1
    Steganography.imwrite(output_filename, new_img)
    print("Encryption Done")
    print("File is saved as: "+output_filename)
    startfile(output_filename)
    return True
Esempio n. 5
0
def open_file(filename):
    try:
        if '.' not in filename:
            ch = ''
            while ch != 'Y' and ch != 'N':
                ch = raw_input("Are you trying to open a folder?(Y/N)? ").upper()
            if ch == "Y":
                filename = validate_dir(filename)
            else:
                filename = validate_file(filename)
        else:
            filename = validate_file(filename)
        if filename == -1:
            return False
        startfile(filename)
        s = filename + " has been opened"
        print(s)
        return True
    except Exception as e:
        print("Exception occurred in open()"+str(e))
        return False
Esempio n. 6
0
def rename_file(old_name, new_name):
    try:
        if '.' not in old_name:
            ch = ''
            while ch != 'Y' and ch != 'N':
                ch = raw_input("Are you trying to rename a folder?(Y/N)? ").upper()
            if ch == 'Y':
                final_path = validate_dir(old_name)
            else:
                final_path = validate_file(old_name)
        else:
            final_path = validate_file(old_name)

        if final_path != -1:
            rename(final_path, final_path.replace(old_name, new_name))
            s = old_name + " has been renamed with " + new_name
            print(s)
            return True
        return False
    except Exception as e:
        print('Exception thrown in renameFile() ' + str(e))
Esempio n. 7
0
def audio_decrypt(filename):
    if not filename.endswith(".wav"):
        print("Invalid input filename")
        return False
    filename = validate_file(filename)
    if filename == -1:
        return False
    try:
        aud = Steganography.open(filename, "rb")
        msg = Steganography.audio_decryption(aud)
        print "Message is: ", msg
    except Exception as e:
        print str(e)
    return True
Esempio n. 8
0
def decrypt(filename):
    if not filename.endswith(".png"):
        print("Invalid input filename")
        return False
    filename = validate_file(filename)
    if filename == -1:
        return False
    try:
        img = Steganography.imread(filename)
        msg = Steganography.image_decryption(img)
        print "Message is: ", msg
    except Exception as e:
        print str(e)
    return True
Esempio n. 9
0
from apriori import apriori
from rules import rule_gen
import validate as vd
import time



# Request filename from user
file = input("Please enter a dataset filename: ")
T = vd.validate_file(file)

# Preprocess data
T['items'] = T['items'].str.replace(", ", ",").str.split(",")
T['items'] = T['items'].apply(tuple)

# Request minimum support from user
min_sup = input("Please enter a minimum support between 0.0-1.0 or 1-" + str(len(T)) + ": ")
min_sup = vd.validate_measure(min_sup, T)

# Request minimum support from user
min_conf = input("Please enter a minimum confidence between 0.0-1.0: ")
min_conf = vd.validate_measure(min_conf)

# Output all frequent itemsets
start_time = time.time()
F = apriori(T, min_sup)
print("\nFrequent itemsets: \n", F)
print("--- %s seconds ---" % round(time.time() - start_time, 3))

# Output all association rules
start_time = time.time()