Skip to content

Instantly share code, notes, and snippets.

@cazeip
Created February 16, 2022 16:32
Show Gist options
  • Select an option

  • Save cazeip/a75ea8c8f0e3e199544b6a4e4cc703e7 to your computer and use it in GitHub Desktop.

Select an option

Save cazeip/a75ea8c8f0e3e199544b6a4e4cc703e7 to your computer and use it in GitHub Desktop.

Revisions

  1. cazeip revised this gist Feb 16, 2022. 1 changed file with 69 additions and 0 deletions.
    69 changes: 69 additions & 0 deletions vigenere.py
    Original file line number Diff line number Diff line change
    @@ -1 +1,70 @@
    from math import *


    def encrypt():
    key = input("Veuillez entrer votre cle\n(lettres, sans espace)\n$ ").lower()
    msg = input("Veuillez entrer le message\n$ ").lower()
    calculateEncryption(key, msg)

    def calculateEncryption(key, msg):
    str = ""
    count = 0
    unsupported = -1
    for i in range(len(msg)):
    if alphabet.find(msg[i]) == -1 and msg[i] != " ":
    unsupported = i
    break
    elif msg[i] != " ":
    str += alphabet[((alphabet.find(msg[i])) + (alphabet.find(key[count % len(key)]))) % 26]
    count += 1
    else:
    str += " "
    if unsupported != -1:
    print("Charactere \""+msg[unsupported]+"\" n'est pas\nsupporte")
    else:
    print(str)
    input("\nAppuyez sur entree pour\ncontinuer...")
    menu()

    def decrypt():
    key = input("Veuillez entrer votre cle\n(lettres, sans espace)\n$ ").lower()
    msg = input("Veuillez entrer le message\n$ ").lower()
    calculateDecryption(key, msg)

    def calculateDecryption(key, msg):
    str = ""
    count = 0
    unsupported = -1
    for i in range(len(msg)):
    if alphabet.find(msg[i]) == -1 and msg[i] != " ":
    unsupported = i
    break
    elif msg[i] != " ":
    str += alphabet[((alphabet.find(msg[i])) - (alphabet.find(key[count % len(key)])))]
    count += 1
    else:
    str += " "
    if unsupported != -1:
    print("Charactere \""+msg[unsupported]+"\" n'est pas\nsupporte")
    else:
    print(str)
    input("\nAppuyez sur entree pour\ncontinuer...")
    menu()

    def menu():
    ans = input("Souhaitez vous\n 1. Crypter\n 2. Decrypter\n 3. Sortir\n$ ")
    if ans == "1":
    encrypt()
    elif ans == "2":
    decrypt()
    elif ans == "3":
    print("A Bientot")
    else:
    print("Reponse invalide")
    input("\nAppuyez sur entree pour\ncontinuer...")
    menu()

    alphabet = "abcdefghijklmnopqrstuvwxyz"
    separator = "================="
    print(separator+"\nCodeur et decodeur de\nchiffrement vigenere\n"+separator)
    menu()
  2. cazeip created this gist Feb 16, 2022.
    1 change: 1 addition & 0 deletions vigenere.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    from math import *