アルファベットを一定量シフトするこのコードがあります。アルファベットのサイズは26です。より大きなサイズシフト(たとえば22)を入力すると、奇妙な文字が表示されます。ASCIIアルファベットを26に変更する必要があると思いますが、どのビットを変更するかはよくわかりません。
基本的に、アルファベットを折り返す必要があります(Zに達すると、文字Aに戻ります)modが機能するための辞書を作成する必要がありますか(A = 0 ... Z = 26など)、または使用を続けることができますか?通常のASCIIテーブル?以下のコードは次のとおりです。
Public Function encrypt(ByVal input As String) 'input is a variable within the funcion
Dim n as Integer
Dim i As Integer
n = key.Text Mod 26 'gets what is in the text box of 'key' and sets it as n
' the key is a multiple of 26 so 26 will = 0
'need to remove white spaces
While input.Contains(" ") 'when the input text contains a space
input = input.Replace(" ", "") 'replaces it with no space.
End While
For i = 1 To Len(input) 'find the length of the input
Mid(input, i, 1) = Chr(Asc(Mid(input, i, 1)) + n) 'chr returns the character associated with the specified character code
'
Next
encrypt = input
End Function