Universal Download V 1.0 {Download Games PC Prototype - Download Games - Streaming Movie - Anime Streaming - Naruto - Soccer}

Reply
[Visual Basic] Semplice crypt/decrypt di stringhe
view post Posted on 22/6/2009, 10:03Quote
Avatar

Virtual Graphic

Group: Staff


Posts: 8654


Status: Offline: ultima azione eseguita il 30/12/2009, 21:59



Sviluppando Simple Notes.NET, mi sono trovato di fronte il problema dei miei file SNT. Infatti, al momento, se aperti con il NotePad, si possono leggere sia intestazione che testo. E allora mi sono detto: perchè non criptarli? Non essendo espertissimo, sono riuscito a scrivere due funzioni per semplice crypt/decrypt di stringhe (più una funzione per prendere carattere per carattere la stringa), che si basano sull' alteramento dei valori Chr() dei caratteri.

Sono scritte con VB.NET, ma il principio dovrebbe essere lo stesso di VB6.

CODICE
Function SearchChar(ByVal Character As String) As Integer
       For I = 0 To 255
           If Chr(I) = Character Then
               Return I
           End If
       Next I
   End Function


CODICE
Function CryptString(ByVal Text As String) As String
       Dim CryptedString As String
       Dim CharFound As Integer
       Dim CryptedChar As Integer

       CryptedString = ""

       For N = 1 To Len(Text)
           CharFound = SearchChar(Mid(Text, N, 1))
           If CharFound <= 235 Then
               CryptedChar = CharFound + 20
           Else
               CryptedChar = CharFound - 236
           End If
           CryptedString = CryptedString & Chr(CryptedChar)
       Next N

       Return CryptedString
   End Function


CODICE
Function DecryptString(ByVal Text As String) As String
       Dim DecryptedString As String
       Dim CharFound As Integer
       Dim DecryptedChar As Integer

       DecryptedString = ""

       For N = 1 To Len(Text)
           CharFound = SearchChar(Mid(Text, N, 1))
           If CharFound >= 20 Then
               DecryptedChar = CharFound - 20
           Else
               DecryptedChar = CharFound + 236
           End If
           DecryptedString = DecryptedString & Chr(DecryptedChar)
       Next N

       Return DecryptedString
   End Function


Attenzione: per VB6 sostituire

CODICE
Return


Con

CODICE
NomeFunzione = Ritorno

 
P_MSG P_WEBSITE Top
0 replies since 22/6/2009, 10:03
 
Reply

load
Fast reply

 
 
 

Enable emoticons
Clickable Smilies
Show All


Nickname:      Email: