' 这是我想出来的程序的加密部分,这里是如何在旋转时仅更改选定的字符
Dim stinput As String = txtinput.Text
Dim i, n, m, o As Integer
Dim inleftover As Integer
If RBRot13.Checked = False Then 'if neither rotation button is selected, a message will tell user to select one
If RBActiveSelect.Checked = False Then
MsgBox("Vous devez choisir le nombre de rotation afin de poursuivre a l'encryption")
End If
End If
txtoutput.Text = "" 'Clears output box when button is pressed to only show the result
If RBRot13.Checked = True Then
For i = 1 To stinput.Length
n = Asc(Mid(stinput, i, 1)) 'Defines the position of the caracter in the ascii table
Select Case n
Case 65 To 90 : o = n + 13 'From A(65) to Z(90), adds 13 to their respective ascii number
If o > 90 And o <= 103 Then 'if the addition is between 90 and 103(90 +13)
inleftover = o - 91 'Calculate de difference as a leftover
o = 65 + inleftover 'Apply leftover to A(65) so as to not give anything other than a letter
End If
Case 97 To 122 : o = n + 13 'From a(97) to z(122), adds 13 to their respective ascii number
If o > 122 And o <= 135 Then 'if the addition is between 122 and 135(122 +13)
inleftover = o - 123 'Calculate de difference as a leftover
o = 97 + inleftover 'Apply leftover to a(97) so as to not give anything other than a letter
End If
Case 192 To 219 : o = n + 13 'From À(192) to Z(219), adds 13 to their respective ascii number
If o > 219 And o <= 232 Then 'if the addition is between 219 and 232(219 +13)
inleftover = o - 220 'Calculate de difference as a leftover
o = 192 + inleftover 'Apply leftover to À(192) so as to not give anything other than an accented letter
End If
Case 224 To 251 : o = n + 13 'From à(224) to Z(251), adds 13 to their respective ascii number
If o > 251 And o <= 264 Then 'if the addition is between 251 and 264(251 +13)
inleftover = o - 225 'Calculate de difference as a leftover
o = 224 + inleftover 'Apply leftover to à(224) so as to not give anything other than an accented letter
End If
Case Else : o = n
End Select
txtoutput.Text = txtoutput.Text & Chr(o)
Next i
ElseIf RBActiveSelect.Checked = True Then
m = Me.NUDChoice.Value 'Defines the value of the rotation set by the user
For i = 1 To stinput.Length
n = Asc(Mid(stinput, i, 1)) 'Defines the position of the caracter in the ascii table
Select Case n
Case 65 To 90 : o = n + m 'From A(65) to Z(90), adds m to their respective ascii number
If o > 90 Then 'if the addition is over 90
inleftover = o - 91 'Calculate de difference as a leftover
o = 65 + inleftover 'Apply leftover to A(65) so as to not give anything other than a letter
End If
Case 97 To 122 : o = n + m 'From A(65) to Z(90), adds m to their respective ascii number
If o > 122 Then 'if the addition is over 122
inleftover = o - 123 'Calculate de difference as a leftover
o = 97 + inleftover 'Apply leftover to A(65) so as to not give anything other than a letter
End If
Case 192 To 219 : o = n + m 'From À(192) to Z(219), adds m to their respective ascii number
If o > 219 Then 'if the addition is over 219
inleftover = o - 220 'Calculate de difference as a leftover
o = 192 + inleftover 'Apply leftover to A(192) so as to not give anything other than an accented letter
End If
Case 224 To 251 : o = n + m 'From à(224) to Z(251), adds m to their respective ascii number
If o > 251 Then 'if the addition is over 251
inleftover = o - 225 'Calculate de difference as a leftover
o = 224 + inleftover 'Apply leftover to à(224) so as to not give anything other than an accented letter
End If
Case Else : o = n
End Select
txtoutput.Text = txtoutput.Text & Chr(o)
Next i
End If
End Sub
'这里开始使用的2个按钮的解密部分
Dim stinput As String = txtinput.Text
Dim i, n, m, o As Integer
Dim inleftover As Integer
If RBRot13.Checked = False Then 'if neither rotation button is selected, a message will tell user to select one
If RBActiveSelect.Checked = False Then
MsgBox("Vous devez choisir le nombre de rotation afin de poursuivre a la décryption")
End If
End If
txtoutput.Text = "" 'Clears output box when button is pressed to only show the result
If RBRot13.Checked = True Then 'If Rotation 13 selected do
For i = 1 To stinput.Length
n = Asc(Mid(stinput, i, 1)) 'Defines the position of the caracter in the ascii table
Select Case n
Case 65 To 90 : o = n - 13 'From A(65) to Z(90), deducts 13 to their respective ascii number
If o < 65 And o >= 52 Then 'if the addition is between 65 and 52(65 - 13)
inleftover = o - 64 'Calculate de difference as a leftover
o = 90 + inleftover 'Apply leftover to A(65) so as to not give anything other than a letter
End If
Case 97 To 122 : o = n - 13 'From a(97) to z(122), deducts 13 to their respective ascii number
If o < 97 And o >= 84 Then 'if the addition is between 97 and 84(97 - 13)
inleftover = o - 96 'Calculate de difference as a leftover
o = 122 + inleftover 'Apply leftover to a(97) so as to not give anything other than a letter
End If
Case 192 To 219 : o = n - 13 'From À(192) to Z(219), deducts 13 to their respective ascii number
If o < 192 And o >= 179 Then 'if the addition is between 192 and 179(192 - 13)
inleftover = o - 191 'Calculate de difference as a leftover
o = 219 + inleftover 'Apply leftover to À(192) so as to not give anything other than an accented letter
End If
Case 224 To 251 : o = n - 13 'From à(224) to Z(251), deducts 13 to their respective ascii number
If o < 224 And o >= 211 Then 'if the addition is between 224 and 211(224 - 13)
inleftover = o - 223 'Calculate de difference as a leftover
o = 251 + inleftover 'Apply leftover to à(224) so as to not give anything other than an accented letter
End If
Case Else : o = n 'everything else stays the same
End Select
txtoutput.Text = txtoutput.Text & Chr(o) 'Prints the result into the output box
Next i
ElseIf RBActiveSelect.Checked = True Then 'If Choice rotation selected do
m = Me.NUDChoice.Value 'Defines the value of the rotation set by the user
For i = 1 To stinput.Length
n = Asc(Mid(stinput, i, 1)) 'Defines the position of the caracter in the ascii table
Select Case n
Case 65 To 90 : o = n - m 'From A(65) to Z(90), deducts m to their respective ascii number
If o < 65 Then 'if the addition is under 65
inleftover = o - 64 'Calculate de difference as a leftover
o = 65 + inleftover 'Apply leftover to z(90) so as to not give anything other than a letter
End If
Case 97 To 122 : o = n - m 'From a(97) to z(122), deducts m to their respective ascii number
If o < 97 Then 'if the addition is under 97
inleftover = o - 96 'Calculate de difference as a leftover
o = 90 + inleftover 'Apply leftover to z(122) so as to not give anything other than a letter
End If
Case 192 To 219 : o = n - m 'From À(192) to Û(219), deducts m to their respective ascii number
If o < 192 Then 'if the addition is under 192
inleftover = o - 191 'Calculate de difference as a leftover
o = 219 + inleftover 'Apply leftover to Û(219) so as to not give anything other than an accented letter
End If
Case 224 To 251 : o = n - m 'From à(224) to û(251), deducts m to their respective ascii number
If o < 224 Then 'if the addition is under 224
inleftover = o - 223 'Calculate de difference as a leftover
o = 251 + inleftover 'Apply leftover to û(251) so as to not give anything other than an accented letter
End If
Case Else : o = n 'everything else stays the same
End Select
txtoutput.Text = txtoutput.Text & Chr(o) 'Prints the result to the output box
Next i
End If
End Sub
它的功能很长,顺便说一下,m 功能链接到一个列表按钮,可以选择 1 到 25 之间的旋转
谢谢