#post-id: 4275-15-44 #original-date: 9.04.2012 Mon #original-time: 3:44 PM #original-day: 4275 #original-host: WinXP Prof SP3 (Build 2600) Это писал очень изобретательный человек... > Public Function EncryptData(ByVal Data As String, _ > ByVal Password As String) As String > Dim sEncrypted As String > Dim lEncryptionCount As Long > Dim sTempPassword As String > > 'It is possible that the normal encryption will give you a string > 'containing cr or lf characters which make it difficult to write to files > 'Do a loop changing the password and keep encrypting until the result is ok > 'To be able to decrypt we need to also store the number of loops in the result > > 'Try first encryption > lEncryptionCount = 0 > sTempPassword = Password & lEncryptionCount > sEncrypted = EncryptDecrypt(Data, sTempPassword, True) > > 'Loop if this contained a bad character > Do While (InStr(1, sEncrypted, vbCr) > 0) _ > Or (InStr(1, sEncrypted, vbLf) > 0) _ > Or (InStr(1, sEncrypted, Chr$(0)) > 0) _ > Or (InStr(1, sEncrypted, vbTab) > 0) > > 'Try the next password > lEncryptionCount = lEncryptionCount + 1 > sTempPassword = Password & lEncryptionCount > sEncrypted = EncryptDecrypt(Data, sTempPassword, True) > > 'Don't go on for ever, 1 billion attempts should be plenty > If lEncryptionCount = 99999999 Then > Err.Raise vbObjectError + 999, "EncryptData", _ > "This data cannot be successfully encrypted" > EncryptData = "" > Exit Function > End If > Loop > > 'Build encrypted string, starting with number of encryption iterations > EncryptData = EncryptNumber(lEncryptionCount) & sEncrypted > End Function