So you need help solving those cryptograms. Well, this should
get you started. It will replace the most commonly occuring letter
with an "e". Just paste this code to a form with 2 text boxes
(Text1,Text2) and a command button (Command1).
Note that the # of occurances of each letter are stored in an arrayCode:Option Explicit
Dim sEncoded As String
Private Sub Form_Load()
Text1.Word
'make sEncoded any string you want to decode
sEncoded = "fzdQlkzqfLLWzEOQzFLzFlQzqgorZtyqZZitQfziqzQitzytZITOZIYTiZtyZSoto"
End Sub
Private Sub Command1_Click()
Dim i, iNewStart, iCount, iHigh As Integer
Dim sCompare, sMostCommon, sDecoded, sReplace As String
Dim aLetterCount(26) as Integer 'alphebet
Text1 = sEncoded
'find most common letter in encoded text
For i = 65 To 91 'ascii #s for letters
sCompare = Chr(i) '(65)=A Chr(97)="a"
iCount = 0
iNewStart = InStr(1, sEncoded, sCompare, vbTextCompare)
Do While iNewStart <> 0
iCount = iCount + 1
iNewStart = InStr(iNewStart + 1, sEncoded, sCompare, vbTextCompare)
Loop
'make record of # of time a letter occurs
'aLetterCount(0) is the # of times "A" or "a" occurs
'aLetterCount(25) is the # of times "Z" or "z" occurs
aLetterCount(i - 65) = iCount
Next i 'check next letter
'replace the most common letter with "e"
For i = 0 To 25 'letters in alphebet
If aLetterCount(i) > iHigh Then iHigh = aLetterCount(i)
Next i
For i = 0 To 25
If aLetterCount(i) = iHigh Then
sMostCommon = Chr(65 + i)
sReplace = "E"
'Replace(expression, find, replacewith[, start[, count[, compare]]])
sDecoded = Replace(sEncoded, sMostCommon, sReplace, 1, -1, vbTextCompare)
Text2 = sDecoded
MsgBox "The most common letter is: " & sMostCommon & vbCr & "It was replaced with: " & sReplace
Exit For
End If
Next i
End Sub
so you can check the 2nd most common occurance, the 3rd, and so on.
Have Fun.
