Categoria: Programacion Tema: Visual Basic Titulo: Encryptar y desemcryptar un texto en Visual Basic
Fecha del Tema: 2012-05-13 10:22:33Esta es una pequeña aplicación para poder encryptar un texto y luego poder desemcryptarlo utilizando la tabla asci. En nuestro form1 pondremos el siguiente codigo: <?//esto no va ïPublic Class Form1 Dim LineaTexto As String Dim todo As String Dim encrip As String Dim cnt As Integer Dim cadena As String Dim convertidor As Integer Dim longitud As Integer Dim codificado As String Dim numero As Integer Dim acum As String Dim entrada As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub examinar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles examinar.Click OpenFileDialog1.ShowDialog() mostrar.Enabled = True todo = "" Try FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) Do Until EOF(1) LineaTexto = LineInput(1) todo &= LineaTexto & vbCrLf Loop Catch ex As Exception MsgBox("El fichero no existe") Finally FileClose(1) End Try TextBox2.Text = OpenFileDialog1.FileName End Sub Private Sub mostrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mostrar.Click TextBox1.Text = todo encriptado.Enabled = True guardar.Enabled = True Salir.Enabled = True borrar.Enabled = True desencriptado.Enabled = True End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged End Sub Private Sub borrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles borrar.Click TextBox1.Text = "" End Sub Private Sub Salir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Salir.Click End End Sub Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click SaveFileDialog1.ShowDialog() Try If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, TextBox1.Text) FileClose() End If Catch ex As Exception MsgBox("El fichero no existe") End Try End Sub Private Sub encriptado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles encriptado.Click cadena = TextBox1.Text SaveFileDialog1.ShowDialog() cnt = 0 codificado = "" longitud = TextBox1.Text.Length For index = 0 To longitud - 1 encrip = cadena.Substring(cnt, 1) convertidor = 5 + Asc(encrip) codificado = codificado & convertidor codificado = codificado & "-" cnt = cnt + 1 Next Try If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, codificado) FileClose() End If Catch ex As Exception MsgBox("El fichero no existe") End Try End Sub Private Sub desencriptado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles desencriptado.Click cadena = TextBox1.Text SaveFileDialog1.ShowDialog() cnt = 0 entrada = 0 codificado = "" longitud = TextBox1.Text.Length For index = 0 To longitud - 1 encrip = cadena.Substring(cnt, 1) acum = acum & encrip If encrip <> "-" Then entrada = entrada + 1 Else numero = acum.Substring(0, entrada) - 5 codificado = codificado & Chr(numero) acum = "" entrada = 0 End If cnt = cnt + 1 Next Try If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, codificado) FileClose() End If Catch ex As Exception MsgBox("El fichero no existe") End Try End Sub End Class ?>//esto no va Es una encryptacion sencilla pero eficaz
Esta es una pequeña aplicación para poder encryptar un texto y luego poder desemcryptarlo utilizando la tabla asci. En nuestro form1 pondremos el siguiente codigo: <?//esto no va ïPublic Class Form1 Dim LineaTexto As String Dim todo As String Dim encrip As String Dim cnt As Integer Dim cadena As String Dim convertidor As Integer Dim longitud As Integer Dim codificado As String Dim numero As Integer Dim acum As String Dim entrada As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub examinar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles examinar.Click OpenFileDialog1.ShowDialog() mostrar.Enabled = True todo = "" Try FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) Do Until EOF(1) LineaTexto = LineInput(1) todo &= LineaTexto & vbCrLf Loop Catch ex As Exception MsgBox("El fichero no existe") Finally FileClose(1) End Try TextBox2.Text = OpenFileDialog1.FileName End Sub Private Sub mostrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mostrar.Click TextBox1.Text = todo encriptado.Enabled = True guardar.Enabled = True Salir.Enabled = True borrar.Enabled = True desencriptado.Enabled = True End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged End Sub Private Sub borrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles borrar.Click TextBox1.Text = "" End Sub Private Sub Salir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Salir.Click End End Sub Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click SaveFileDialog1.ShowDialog() Try If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, TextBox1.Text) FileClose() End If Catch ex As Exception MsgBox("El fichero no existe") End Try End Sub Private Sub encriptado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles encriptado.Click cadena = TextBox1.Text SaveFileDialog1.ShowDialog() cnt = 0 codificado = "" longitud = TextBox1.Text.Length For index = 0 To longitud - 1 encrip = cadena.Substring(cnt, 1) convertidor = 5 + Asc(encrip) codificado = codificado & convertidor codificado = codificado & "-" cnt = cnt + 1 Next Try If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, codificado) FileClose() End If Catch ex As Exception MsgBox("El fichero no existe") End Try End Sub Private Sub desencriptado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles desencriptado.Click cadena = TextBox1.Text SaveFileDialog1.ShowDialog() cnt = 0 entrada = 0 codificado = "" longitud = TextBox1.Text.Length For index = 0 To longitud - 1 encrip = cadena.Substring(cnt, 1) acum = acum & encrip If encrip <> "-" Then entrada = entrada + 1 Else numero = acum.Substring(0, entrada) - 5 codificado = codificado & Chr(numero) acum = "" entrada = 0 End If cnt = cnt + 1 Next Try If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, codificado) FileClose() End If Catch ex As Exception MsgBox("El fichero no existe") End Try End Sub End Class ?>//esto no va Es una encryptacion sencilla pero eficaz