|
|
| 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 Con CODICE NomeFunzione = Ritorno
|
| |