Function CodeRotN(ByVal sStr As String, ByRef iRot As Integer) As String
If LenB(sStr) > 2 Then
If iRot < 1 Then
iRot = 1
ElseIf iRot > 255 Then
iRot = 255
End If
Dim i As Long, ascii As Integer
CodeRotN = sStr
For i = 1 To Len(sStr)
ascii = Asc(Mid$(sStr, i, 1))
If ascii > 255 - iRot Then ascii = ascii - 255
ascii = ascii + iRot
Mid$(CodeRotN, i, 1) = Chr$(ascii)
Next i
Else
CodeRotN = vbNullString
End If
End Function
'
'
' =====================
' EXEMPLE D'UTILISATION
' =====================
'
'
Private Sub Form_Load()
Debug.Print CodeRotN("bonjour", 13)
Debug.Print CodeRotN("bonjour", 128)
Debug.Print CodeRotN("bonjour", 250)
Debug.Print CodeRotN("o|{w|‚", 242)
Debug.Print CodeRotN("âïîêïõò", 127)
Debug.Print CodeRotN("]jiejpm", 5)
End Sub