Below is a possible solution to Challenge 56 – Cryptography Challenge 5 – Fully Functional Caesar’s Shift Cipher Decrypter
1. Make a backup of your workbook
2. Open your workbook and ALT+F11
3. Locate your Workbook name in Project Explorer Window
4. Right click on your workbook name > Insert > Module
5. Copy paste the Macro code given below
6. Save your file as .xlsm
7. Call your function as =DecryptCS(A2,$C$2)
Function DecryptCS(CText, Shift) As String Dim Ws As Worksheet Dim i As Long Dim PText As String Dim PArr, CArr Application.Volatile CArr = Split(StrConv(CText, vbUnicode), vbNullChar) ReDim PArr(UBound(CArr) - 1) For i = LBound(CArr) To UBound(CArr) - 1 If Abs(77.5 - Asc(UCase(CArr(i)))) < 13 Then If Asc(LCase(CArr(i))) - Shift < 97 Then PArr(i) = Chr(Asc(CArr(i)) - Shift + 26) Else PArr(i) = Chr(Asc(CArr(i)) - Shift) End If Else PArr(i) = CArr(i) End If Next i DecryptCS = Join(PArr, "") End Function
The Excel file illustrating the above solution can be downloaded from Solution – Challenge 56 – Cryptography Challenge 5 – Decryption – Fully Functional Caesar’s Shift Cipher