コード例 #1
0
def removeDictio(dictioName):
    allDictio.remove(dictioName)
    clg.debug(allDictio)
    saveDictio()
    os.remove("dictionnaries/{}.dct".format(dictioName))
    try:
        os.remove("dictionnaries/readable_{}.rdct".format(dictioName))
    except FileNotFoundError:
        pass
コード例 #2
0
 def calcul(self):  #Calculate function.
     with open(filePath, "a") as f:
         f.write("[{}] : Begining of calculation;\n".format(
             time.strftime("%A %d %B %Y at %H:%M:%S")))
     with open(filePath, "a") as f:
         f.write("[{}] : Calculation of '{}' ^ '{}';\n".format(
             time.strftime("%A %d %B %Y at %H:%M:%S"), self.num.get(),
             self.exp.get()))
     #===== Check of number's validity =====
     try:
         self.resu = power(float(self.num.get()), int(self.exp.get()))
     except ValueError:
         with open(filePath, "a") as f:
             f.write("[{}] : ValueError;\n".format(
                 time.strftime("%A %d %B %Y at %H:%M:%S")))
         try:
             float(self.num.get())
         except ValueError:
             self.errorNum.pack(side="left")  #Display error message
             with open(filePath, "a") as f:
                 f.write("[{}] : The number is not a number;\n".format(
                     time.strftime("%A %d %B %Y at %H:%M:%S")))
         else:
             self.errorNum.pack_forget()
         try:
             int(self.exp.get())
         except ValueError:
             self.errorExp.pack(side="left")  #Display error message
             with open(filePath, "a") as f:
                 f.write(
                     "[{}] : The power is not a integer number;\n".format(
                         time.strftime("%A %d %B %Y at %H:%M:%S")))
         else:
             self.errorExp.pack_forget()
     else:
         self.errorNum.pack_forget()
         self.errorExp.pack_forget()
         self.resultLab["text"] = "{} ^ {} = ".format(
             self.num.get(), self.exp.get())  #Update the text
         self.resul.set(str(self.resu))  #Display the resultat
         self.result["width"] = len(str(self.resu)) + 1
         with open(filePath, "a") as f:
             f.write("[{}] : The resultat is {};\n".format(
                 time.strftime("%A %d %B %Y at %H:%M:%S"), self.resu))
         clg.debug(self.resu)
     with open(filePath, "a") as f:
         f.write("[{}] : End of calculation;\n".format(
             time.strftime("%A %d %B %Y at %H:%M:%S")))
コード例 #3
0
def power(num, exposant=2):  #The function to calculate the power of a number.
    """
	Function to calculate a power.
	Requested settings :
	 - The number (num) requisite.
	 - The power (exposant) optionnal, default value : 2
	"""
    if not type(num) == int:
        num = int(num)
    out = 1
    if exposant > -1:
        for loop in range(exposant):
            clg.debug(out)
            out *= num
        return out
    elif exposant < 0:
        return 1 / power(num, -exposant)
コード例 #4
0
ファイル: mainTk.py プロジェクト: LopsemPyier/KEEP
    def __init__(self, win):
        self.dictio = keep.getDictio()
        clg.debug(self.dictio)

        self.window = win
        self.menu = tk.Frame(self.window)
        self.keeps = tk.Frame(self.menu).pack()
        self.keepas = tk.Frame(self.menu).pack()
        self.generate = tk.Frame(self.window).pack()
        self.imports = tk.Frame(self.window).pack()
        self.encryptFrame = tk.Frame(self.window).pack()
        self.decryptFrame = tk.Frame(self.window).pack()

        self.title = tk.Label(self.window, text = "KEEP S or AS.\nKey Encryptor Encodage Processus.\nSymetrical or Asymetrical and Symetrical.")
        self.quitButton = tk.Button(self.window, text = "Quit", command = self.window.quit)

        self.titleKeeps = tk.Label(self.keeps, text = "\nKEEP Symetrical : ")
        self.encryptKeepsButton = tk.Button(self.keeps, text = "Encrypt", command = self.encryptS)
        self.decryptKeepsButton = tk.Button(self.keeps, text = "Decrypt", command = self.decryptS)
        self.generateButton = tk.Button(self.keeps, text = "Generate dictionnaies", command = self.generateDic)
        self.importButton = tk.Button(self.keeps, text = "Import dictionnaries", command = self.importDic)
        self.backButton = tk.Button(self.window, text = "Back to menu", command = self.back)

        self.eCommunText = tk.StringVar()
        self.eCommunTextLab = tk.Label(self.encryptFrame, text = "Enter the commun text : ")
        self.eCommunTextEnt = tk.Entry(self.encryptFrame, textvariable = self.eCommunText, width = 40)
        self.eEncryptText = tk.StringVar()
        self.eEncryptTextLab = tk.Label(self.encryptFrame, text = "Enter the text to encrypt : ")
        self.eEncryptTextEnt = tk.Entry(self.encryptFrame, textvariable = self.eEncryptText, width = 40)
        self.eDictioLab = tk.LabelFrame(self.encryptFrame, text = "Choose dictionnaries to use : ")
        self.eDictioToUse = tk.Listbox(self.eDictioLab)
        for i in self.dictio:
            self.eDictioToUse.insert("end", i)
        self.eEncryptTextButton = tk.Button(self.encryptFrame, text = "Encrypt", command = _kTk.encrypt)
        self.saveInFile = tk.Button(self.encryptFrame, text = "Save the encrypted text in a file", command = _kTk.saveInFile)
        self.encryptedTextVal = tk.StringVar()
        self.encryptedTextL = tk.Label(self.encryptFrame, text = "The encrypted text : ")
        self.encryptedTextLab = tk.Entry(self.encryptFrame, textvariable = self.encryptedTextVal)
        self.eCopyEncryptedTextButton = tk.Button(self.encryptFrame, text="Copy to clipboard", command=self.copy)

        self.dCommunText = tk.StringVar()
        self.dCommunTextLab = tk.Label(self.decryptFrame, text = "Enter the commun text : ")
        self.dCommunTextEnt = tk.Entry(self.decryptFrame, textvariable = self.dCommunText, width = 40)
        self.dEncryptText = tk.StringVar()
        self.dEncryptTextLab = tk.Label(self.decryptFrame, text = "Enter the text to decrypt : ")
        self.dEncryptTextEnt = tk.Entry(self.decryptFrame, textvariable = self.dEncryptText, width = 40)
        self.dDictioLab = tk.LabelFrame(self.decryptFrame, text = "Choose dictionnaries to use : ")
        self.dDictioToUse = tk.Listbox(self.dDictioLab)
        for i in self.dictio:
            self.dDictioToUse.insert("end", i)
        self.decryptTextButton = tk.Button(self.decryptFrame, text = "Decrypt", command = _kTk.decrypt)
        self.decryptedTextVal = tk.StringVar()
        self.decryptedTextL = tk.Label(self.decryptFrame, text = "The decrypted text : ")
        self.decryptedTextLab = tk.Entry(self.decryptFrame, textvariable = self.decryptedTextVal)

        self.caracFrame = tk.LabelFrame(self.generate, text = "Choose a characters' type.")
        self.choiceAlpha = tk.StringVar()
        self.alphanumChoice = tk.Radiobutton(self.caracFrame, text="Alpha-numérique", variable = self.choiceAlpha, value = "ALPHANUM")
        self.defaultChoice = tk.Radiobutton(self.caracFrame, text="Default choice", variable = self.choiceAlpha, value = "DEFAULT")
        self.validButton = tk.Button(self.generate, text="Generate", command = _kTk.generate)
        self.nameDicLab = tk.Label(self.generate, text = "Enter the name of the dictionnaries : ")
        self.nameDic = tk.StringVar()
        self.nameDicText = tk.Entry(self.generate, textvariable = self.nameDic, width = 30)
        self.overwrite = tk.IntVar()
        self.overwriteCase = tk.Checkbutton(self.generate, text = "Overwrite if dictionnaries' name already taken.", variable = self.overwrite)
        self.saveReadable = tk.IntVar()
        self.saveReadableCase = tk.Checkbutton(self.generate, text = "Save dictionnaries also in readable files.", variable = self.saveReadable)

        self.dictiosFrame = tk.LabelFrame(self.imports, text = "Dictionnaries already imported : ")
        self.dictioToImport = tk.Listbox(self.dictiosFrame)
        self.importDictioButton = tk.Button(self.imports, text = "Choose other dictionnaries", command=self._import)
        self.deleteDictioButton = tk.Button(self.imports, text = "Delete dictionnaries", command=self.delDictio)
        self.updateDictioButton = tk.Button(self.imports, text = "Update dictionnaries", command=self.updateDictio)
        for i in self.dictio:
            self.dictioToImport.insert("end", i)
            keep.dictios[i] = keep.importDictios(i)
            clg.debug("Loading {} dictionnaries.\n".format(i))

        self.title.pack(side = "top")
        self.quitButton.pack(side = "top")

        self.titleKeeps.pack(side = "top")
        self.encryptKeepsButton.pack(side = "top")
        self.decryptKeepsButton.pack(side = "top")
        self.generateButton.pack(side = "top")
        self.importButton.pack(side = "top")

        self.menu.pack()
コード例 #5
0
def generateDictio(overWrite=True,
                   saveReadable=False,
                   dictioName="default",
                   alpha=DEFAULT_ALPHA,
                   carac=DEFAULT_CARAC,
                   alphaHash=DEFAULT_ALPHA_HASH):
    dictio = {
        "alpha": {
            "encrypt": {},
            "decrypt": {}
        },
        "alphaHash": {
            "encrypt": {},
            "decrypt": {}
        },
        "carac": {
            "encrypt": {},
            "decrypt": {}
        },
        "settings": {
            "overWrite": overWrite,
            "saveReadable": saveReadable,
            "alpha": alpha,
            "alphaHash": alphaHash,
            "carac": carac
        }
    }
    clg.debug(dictio.get("settings"))
    for i in range(len(alpha)):
        ((dictio.get("alpha")).get("encrypt"))[alpha[i]] = i
        ((dictio.get("alpha")).get("decrypt"))[i] = alpha[i]
    for i in range(len(alphaHash)):
        ((dictio.get("alphaHash")).get("encrypt"))[alphaHash[i]] = i
        ((dictio.get("alphaHash")).get("decrypt"))[i] = alphaHash[i]
    for i in range(len(carac)):
        tmp = rd.choice(carac)
        ((dictio.get("carac")).get("encrypt"))[tmp] = i
        ((dictio.get("carac")).get("decrypt"))[i] = tmp
        carac = carac.replace(tmp, '')
    dictioNamePath = "dictionnaries/{}."
    with open(dictioNamePath.format(dictioName).lower() + "dct", "wb") as f:
        fp = pickle.Pickler(f)
        fp.dump(dictio)
    if saveReadable:
        with open(
                dictioNamePath.format("readable_" + dictioName).lower() +
                "rdct", "w") as f:
            f.write(
                "Readable dictionnaries of {} dictionnaries.\nAlpha's characters\n\tEncode characters : \n"
                .format(dictioName))
            for i, j in dictio.get("alpha").get("encrypt").items():
                f.write("- {} > {} \n".format(i, j))
            f.write("\tDecode characters : \n")
            for i, j in dictio.get("alpha").get("decrypt").items():
                f.write("- {} > {} \n".format(i, j))
            f.write("Alpha hash's characters\n\tEncode characters : \n".format(
                dictioName))
            for i, j in dictio.get("alphaHash").get("encrypt").items():
                f.write("- {} > {} \n".format(i, j))
            f.write("\tDecode characters : \n")
            for i, j in dictio.get("alphaHash").get("decrypt").items():
                f.write("- {} > {} \n".format(i, j))
            f.write("Carac's characters\n\tEncode characters : \n".format(
                dictioName))
            for i, j in dictio.get("carac").get("encrypt").items():
                f.write("- {} > {} \n".format(i, j))
            f.write("\tDecode characters : \n")
            for i, j in dictio.get("carac").get("decrypt").items():
                f.write("- {} > {} \n".format(i, j))

    allDictio.append(dictioName)
    saveDictio()
    return False