Vigenère a inventé son code au XVIème siècle
selon un procédé voisin de celui de César.
S'agissant d'un code à polyalphabétique,
l'algorithme consiste à substituer à chaque
lettre du message une lettre de l'alphabet. La
lettre de substitution étant calculée
à partir d'une clef et dépend de la position de
la lettre codée dans le message.
Par exemple, On veut coder la phrase "II FAIT
BEAU" avec la clé "ZORRO"
I L F A I T B E A U
Z O R R O Z O R R O
I A X S X T Q W S J
Ce qui, transcrit sous formes de chiffres en
affectant à chaque lettre sa place dans
lalphabet en partant de A, donne:
9 12 6 1 9 20 2 5 1 21
+ 26 15 18 18 15 26 15 18 18 15
9 1 24 19 24 20 17 23 19 10
Comme lalphabet latin est constitué de 26
lettres, il faut effectuer une addition modulo
26, afin de garder des nombres compris entre 1 et
26. Pour le décryptage, il suffit de procéder à
lopération inverse, cest à dire une simple
soustraction.
L'avantage de cet algorithme par rapport à celui
de César est qu'il est un peu plus compliqué à
déchiffrer du fait de l'utilisation d'une clef
secrète et qu'à chaque caractère
correspond plusieurs autres caractères. Mais
aussi, plus la clé est longue, plus le message
est difficile à décrypter.
Source / Exemple :
Dim x, xx, xxx, xxxx
Dim a, b, y, yy
Dim Clef
Private Sub Command1_Click()
Text2 = ""
Clef = Text3
Do While Len(Text3) < Len(Text1)
Text3 = Text3 & Clef
Loop
For i = 1 To Len(Text1)
a = Mid$(Text1, i, 1)
b = Mid$(Text3, i)
If a = " " Then Text3 = Mid$(Text3, 1, i - 1) & " " & b
Next i
Text3 = Mid$(Text3, 1, Len(Text1))
Crypter
End Sub
Private Sub Crypter()
Text2 = ""
For i = 1 To Len(Text1)
x = Mid$(Text1, i, 1)
If x = "a" Or x = "A" Or x = "b" Or x = "B" Or x = "c" Or x = "C" Or x = "d" Or x = "D" Or x = "e" Or x = "E" Or x = "f" Or x = "F" Or x = "g" Or x = "G" Or x = "h" Or x = "H" Or x = "i" Or x = "I" Or x = "j" Or x = "J" Or x = "k" Or x = "K" Or x = "l" Or x = "L" Or x = "m" Or x = "M" Or x = "n" Or x = "N" Or x = "o" Or x = "O" Or x = "p" Or x = "P" Or x = "q" Or x = "Q" Or x = "r" Or x = "R" Or x = "s" Or x = "S" Or x = "t" Or x = "T" Or x = "u" Or x = "U" Or x = "v" Or x = "V" Or x = "w" Or x = "W" Or x = "x" Or x = "X" Or x = "y" Or x = "Y" Or x = "z" Or x = "Z" Then
' Valeur de la lettre du msg non crypté
If x = "a" Or x = "A" Then xx = 1
If x = "b" Or x = "B" Then xx = 2
If x = "c" Or x = "C" Then xx = 3
If x = "d" Or x = "D" Then xx = 4
If x = "e" Or x = "E" Then xx = 5
If x = "f" Or x = "F" Then xx = 6
If x = "g" Or x = "G" Then xx = 7
If x = "h" Or x = "H" Then xx = 8
If x = "i" Or x = "I" Then xx = 9
If x = "j" Or x = "J" Then xx = 10
If x = "k" Or x = "K" Then xx = 11
If x = "l" Or x = "L" Then xx = 12
If x = "m" Or x = "M" Then xx = 13
If x = "n" Or x = "N" Then xx = 14
If x = "o" Or x = "O" Then xx = 15
If x = "p" Or x = "P" Then xx = 16
If x = "q" Or x = "Q" Then xx = 17
If x = "r" Or x = "R" Then xx = 18
If x = "s" Or x = "S" Then xx = 19
If x = "t" Or x = "T" Then xx = 20
If x = "u" Or x = "U" Then xx = 21
If x = "v" Or x = "V" Then xx = 22
If x = "w" Or x = "W" Then xx = 23
If x = "x" Or x = "X" Then xx = 24
If x = "y" Or x = "Y" Then xx = 25
If x = "z" Or x = "Z" Then xx = 26
' Valeur de la lettre de la clef
xxx = Mid$(Text3, i, 1)
If xxx = "a" Or xxx = "A" Then xxxx = 1
If xxx = "b" Or xxx = "B" Then xxxx = 2
If xxx = "c" Or xxx = "C" Then xxxx = 3
If xxx = "d" Or xxx = "D" Then xxxx = 4
If xxx = "e" Or xxx = "E" Then xxxx = 5
If xxx = "f" Or xxx = "F" Then xxxx = 6
If xxx = "g" Or xxx = "G" Then xxxx = 7
If xxx = "h" Or xxx = "H" Then xxxx = 8
If xxx = "i" Or xxx = "I" Then xxxx = 9
If xxx = "j" Or xxx = "J" Then xxxx = 10
If xxx = "k" Or xxx = "K" Then xxxx = 11
If xxx = "l" Or xxx = "L" Then xxxx = 12
If xxx = "m" Or xxx = "M" Then xxxx = 13
If xxx = "n" Or xxx = "N" Then xxxx = 14
If xxx = "o" Or xxx = "O" Then xxxx = 15
If xxx = "p" Or xxx = "P" Then xxxx = 16
If xxx = "q" Or xxx = "Q" Then xxxx = 17
If xxx = "r" Or xxx = "R" Then xxxx = 18
If xxx = "s" Or xxx = "S" Then xxxx = 19
If xxx = "t" Or xxx = "T" Then xxxx = 20
If xxx = "u" Or xxx = "U" Then xxxx = 21
If xxx = "v" Or xxx = "V" Then xxxx = 22
If xxx = "w" Or xxx = "W" Then xxxx = 23
If xxx = "x" Or xxx = "x" Then xxxx = 24
If xxx = "y" Or xxx = "Y" Then xxxx = 25
If xxx = "z" Or xxx = "Z" Then xxxx = 26
' Addition des 2 valeurs
y = xx + xxxx
' On réduit y pour avoir un nbr egal ou supérieur à 26
Do While y >= 26
y = y - 26
Loop
' On remplace y par la lettre correspondante
If y = 1 Then yy = "a"
If y = 2 Then yy = "b"
If y = 3 Then yy = "c"
If y = 4 Then yy = "d"
If y = 5 Then yy = "e"
If y = 6 Then yy = "f"
If y = 7 Then yy = "g"
If y = 8 Then yy = "h"
If y = 9 Then yy = "i"
If y = 10 Then yy = "j"
If y = 11 Then yy = "k"
If y = 12 Then yy = "l"
If y = 13 Then yy = "m"
If y = 14 Then yy = "n"
If y = 15 Then yy = "o"
If y = 16 Then yy = "p"
If y = 17 Then yy = "q"
If y = 18 Then yy = "r"
If y = 19 Then yy = "s"
If y = 20 Then yy = "t"
If y = 21 Then yy = "u"
If y = 22 Then yy = "v"
If y = 23 Then yy = "w"
If y = 24 Then yy = "x"
If y = 25 Then yy = "y"
If y = 26 Then yy = "z"
' On affiche le résultat
Text2 = Text2 & yy
Else
Text2 = Text2 & " "
End If
Next i
Text3 = Clef
End Sub
Conclusion :
Text1 = msg "normal"
Text2 = msg crypté
Text3 = clef
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.