• 0
Sign in to follow this  
Guest - fabio -

Codifica E Decodifica Strings

Question

Guest - fabio -

alguém tem um exemplo simples de como codificar e decodificar arquivos usando uma senha.

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Eu tenho um bem simples cara veja se te serve wink.gif

'Num módulo

Function Codifica(Entrada As String, Senha As String) As String
Dim a As Long
Dim i As Long
Dim t As Long
On Error Resume Next
t = 1
Codifica = String(Len(Entrada), 0)
For i = 1 To Len(Entrada)
    a = Asc(Mid(Entrada, i, 1)) + Asc(Mid(Senha, t, 1))
    While a > 255
        a = a - 256
    Wend
    Mid$(Codifica, i, 1) = Chr(a)
    t = t + 1
    If t > Len(Senha) Then: t = 1
Next i
End Function

Function Decodifica(Entrada As String, Senha As String) As String
Dim a As Long
Dim i As Long
Dim t As Long
On Error Resume Next
t = 1
Decodifica = String(Len(Entrada), 0)
For i = 1 To Len(Entrada)
    a = Asc(Mid(Entrada, i, 1)) - Asc(Mid(Senha, t, 1))
    While a < 0
        a = a + 255
    Wend
    Mid$(Decodifica, i, 1) = Chr(a)
    t = t + 1
    If t > Len(Senha) Then: t = 1
Next i
End Function



'Exemplo:

'Num Form:

Private Sub Command1_Click()
Dim STR As String
STR = InputBox("Digite algum texto.")
STR = Codifica(STR, "abc")
MsgBox Decodifica(STR, "abc")
End Sub

Qualquer coisa volta ae cara.

beleza, falow!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this