Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Gambas class file
- Public abecedario As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "
- Public Sub _new()
- End
- Public Sub Form_Open()
- abecedario &= abecedario
- Me.Center
- End
- Public Sub ButtonCifrar_Click()
- TextBoxMensajeCifrado.text = cifrar(TextBoxMensaje.text, ValueBoxDesplazamientoCifrar.value)
- End
- Public Sub ButtonDescifrar_Click()
- TextBoxMensajeDescifrar.text = descifrar(TextBoxMensaje2.text, ValueBoxDesplazamientoDescifrar.value)
- End
- 'cifrar
- Public Function cifrar(texto As String, numero As Integer) As String
- Dim a As Integer
- Dim letra As String
- Dim numeroLetra As Integer
- Dim textoCifrado As String
- texto = Upper$(texto)
- For a = 0 To Len(texto) - 1
- letra = Mid$(texto, a + 1, 1)
- numeroLetra = InStr(abecedario, letra)
- textoCifrado &= Mid$(abecedario, (numeroletra + numero) Mod (Len(abecedario)), 1)
- Next
- Return textoCifrado
- End
- '
- 'descifrar
- Public Function descifrar(texto As String, numero As Integer) As String
- Dim a As Integer
- Dim letra As String
- Dim numeroLetra As Integer
- Dim textoCifrado As String
- texto = Upper$(texto)
- For a = 0 To Len(texto) - 1
- letra = Mid$(texto, a + 1, 1)
- numeroLetra = InStr(abecedario, letra)
- textoCifrado &= Mid$(abecedario & abecedario & abecedario, Len(abecedario) + (numeroletra - numero) Mod (Len(abecedario)), 1)
- Next
- Return textoCifrado
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement