How about a UDF?
----A---- -----B------ --------------C---------------
1 Key LEMON B1: Input
2 Plaintext ATTACKATDAWN B2: Input
3 Cypher LXFOPVEFRNHR B3: =Vigenere(B2, $B$1, TRUE)
4 Plaintext ATTACKATDAWN B4: =Vigenere(B3, $B$1, FALSE)
Function Vigenere(ByVal sInp As String, _
ByVal sKey As String, _
Optional bEncrypt As Boolean = True) As String
Dim i As Long
Dim j As Long
sInp = UCase(Replace(sInp, " ", ""))
sKey = Replace(sKey, " ", "")
sKey = Left(WorksheetFunction.Rept(sKey, Len(sInp) \ Len(sKey) + 1), Len(sInp))
If bEncrypt Then
For i = 1 To Len(sInp)
j = Asc(Mid(sInp, i, 1)) + Asc(Mid(sKey, i, 1)) - 130
If j > 25 Then j = j - 26
Mid(sInp, i) = Chr(j + 65)
Next i
Else
For i = 1 To Len(sInp)
j = Asc(Mid(sInp, i, 1)) - Asc(Mid(sKey, i, 1))
If j < 0 Then j = j + 26
Mid(sInp, i) = Chr(j + 65)
Next i
End If
Vigenere = sInp
End Function
Bookmarks