Crypter: Vigenere Cipher 12-26-2013, 02:32 PM
#1
This is a variant of the Cesar Code. It works the same way, but the coding step if made with a word instead of a uniq letter
Choose 1 to crypt and 2 to decrypt
Type the word used for coding
Type the message
It is harder to decryot than Cesar cipher because it uses a polyaphabetic algorithm. The sentence is not coded with a letter but with a word. If you want to understand it better, visite this link:
http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
Code:
#!/usr/bin/env python3.3
#RUN WITH python codevigenere.py
#YOU CAN USE SPECIAL CHARS
import sys
choixmenu=raw_input("Do you want to crypt or decrypt ? type 1 to crypt or 2 to decrypt: ")
while (choixmenu != "1") and (choixmenu != "2"): #On verifie que 1 ou 2 est demande sinon on demande a nouveau
choixmenu=raw_input("You must type 1 or 2 ? type 1 to crypt or 2 to decrypt: ")
if choixmenu == "1": #On veut encoder
choixcle=raw_input("Type the word you want to use to crypt your message: ")
choixcle=choixcle.upper()
message=raw_input("Type your message: ")
message=message.upper() #On passe le message en majuscule
savecle=[]
savemess=[]
k=0
l=0
for i in choixcle:
valchiffre1=ord(i) #On recupere la valeur ascii de chaque lettre
#On initialiste le dictionnaire qui fait la correspondance valeure ascii->chiffre normal
dichiffre = {65:0, 66:1, 67:2, 68:3, 69:4, 70:5, 71:6, 72:7, 73:8, 74:9, 75:10, 76:11, 77:12, 78:13, 79:14, 80:15, 81:16, 82:17, 83:18, 84:19, 85:20, 86:21, 87:22, 88:23, 89:24, 90:25}
clechiffre=dichiffre[valchiffre1]
savecle.append(clechiffre)
for j in message:
valchiffre2=ord(j) #On recupere la valeur ascii de chaque lettre
if (valchiffre2 >= 65) and (valchiffre2 <= 90):
#On initialiste le dictionnaire qui fait la correspondance valeure ascii->chiffre normal
dichiffre = {65:0, 66:1, 67:2, 68:3, 69:4, 70:5, 71:6, 72:7, 73:8, 74:9, 75:10, 76:11, 77:12, 78:13, 79:14, 80:15, 81:16, 82:17, 83:18, 84:19, 85:20, 86:21, 87:22, 88:23, 89:24, 90:25}
messagechiffre=dichiffre[valchiffre2]
savemess.append(messagechiffre)
else:
messagechiffre=valchiffre2
savemess.append(messagechiffre)
while k < len(message):
x=savemess[k]
if (x >= 32) and (x <= 64) or (x >= 91) and (x <= 96) or (x >= 123) and (x <= 126):
convertion=x
valascii=convertion
else:
if l == len(choixcle):
l=0
y=savecle[l]
l += 1
else:
y=savecle[l]
l += 1
convertion=(x+y)%26
#On initialiste le dictionnaire qui fait la correspondance valeure chiffre normal->ascii
dicascii = {0:65, 1:66, 2:67, 3:68, 4:69, 5:70, 6:71, 7:72, 8:73, 9:74, 10:75, 11:76, 12:77, 13:78, 14:79, 15:80, 16:81, 17:82, 18:83, 19:84, 20:85, 21:86, 22:87, 23:88, 24:89, 25:90}
valascii=dicascii[convertion];
resultat=chr(valascii) #On transforme le code ascii en caractere lisible
sys.stdout.softspace=0
print resultat,
k += 1
elif choixmenu == "2": #On veut decoder
choixcle=raw_input("Type the word you want to use to decrypt your message: ")
choixcle=choixcle.upper()
message=raw_input("Type your message: ")
message=message.upper() #On passe le message en majuscule
savecle=[]
savemess=[]
k=0
l=0
for i in choixcle:
valchiffre1=ord(i) #On recupere la valeur ascii de chaque lettre
#On initialiste le dictionnaire qui fait la correspondance valeure ascii->chiffre normal
dichiffre = {65:0, 66:1, 67:2, 68:3, 69:4, 70:5, 71:6, 72:7, 73:8, 74:9, 75:10, 76:11, 77:12, 78:13, 79:14, 80:15, 81:16, 82:17, 83:18, 84:19, 85:20, 86:21, 87:22, 88:23, 89:24, 90:25}
clechiffre=dichiffre[valchiffre1]
savecle.append(clechiffre)
for j in message:
valchiffre2=ord(j) #On recupere la valeur ascii de chaque lettre
if (valchiffre2 >= 65) and (valchiffre2 <= 90):
#On initialiste le dictionnaire qui fait la correspondance valeure ascii->chiffre normal
dichiffre = {65:0, 66:1, 67:2, 68:3, 69:4, 70:5, 71:6, 72:7, 73:8, 74:9, 75:10, 76:11, 77:12, 78:13, 79:14, 80:15, 81:16, 82:17, 83:18, 84:19, 85:20, 86:21, 87:22, 88:23, 89:24, 90:25}
messagechiffre=dichiffre[valchiffre2]
savemess.append(messagechiffre)
else:
messagechiffre=valchiffre2
savemess.append(messagechiffre)
while k < len(message):
x=savemess[k]
if (x >= 32) and (x <= 64) or (x >= 91) and (x <= 96) or (x >= 123) and (x <= 126):
convertion=x
valascii=convertion
else:
if l == len(choixcle):
l=0
y=savecle[l]
l += 1
else:
y=savecle[l]
l += 1
convertion=(x-y)%26
#On initialiste le dictionnaire qui fait la correspondance valeure chiffre normal->ascii
dicascii = {0:65, 1:66, 2:67, 3:68, 4:69, 5:70, 6:71, 7:72, 8:73, 9:74, 10:75, 11:76, 12:77, 13:78, 14:79, 15:80, 16:81, 17:82, 18:83, 19:84, 20:85, 21:86, 22:87, 23:88, 24:89, 25:90}
valascii=dicascii[convertion];
resultat=chr(valascii) #On transforme le code ascii en caractere lisible
resultat=resultat.lower()
sys.stdout.softspace=0
print resultat,
k += 1Choose 1 to crypt and 2 to decrypt
Type the word used for coding
Type the message
It is harder to decryot than Cesar cipher because it uses a polyaphabetic algorithm. The sentence is not coded with a letter but with a word. If you want to understand it better, visite this link:
http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)