Crypt512

To encrypt or decrypt any string
' Strii is the required text to protect
' PwdNr is the Encryption/Decryption number
By Rodik (rodik@hehe.com), Jul 12 2002

CodeFunctionName
What is this?

Public

Tested

Imported
Public Function Crypt512(Strii, PwdNr)
Dim Ans
Dim a, b, c
If Clng(PwdNr)=0 then PwdNr = 1
Randomize PwdNr
For a = 1 To Len(Strii)
b = Asc(Mid$(Strii, a, 1))
' Crypt two alternate algorithms depending on whether character number is pair or not.
If a / 2 = Int(a / 2) Then d = 5 Else d = -7
e = Int(Rnd(0) * 255) Xor (a Or d) ' Randomize character multiplier:
' Make sure 'e' is within allowed values this does not affect encryption
While e > 255: e = e - 255: Wend
While e < 0: e = e + 255: Wend
c = b Xor e 'Crypt character
Ans = Ans & Chr$(c) ' Add to output string
Next a
Crypt512 = Ans
End Function

' This function will encrypt any string it receives and together with the password (optional) it will output another string. This string can then be run trough this function again, with the same password (again, optional) and it will return the original string.
' Password: The so called "password" is actually just the number that the functions randomize function will use to create it's seed. It is initially set to 1, and that will work. However, anyone with the encrypted string, and this function/program, can decrypt the string to the original string. However, if a password nr is chosen, then that person would also have to know that password number. This password can of course be coded to support text, and for instance use Asc() to get a value of the chars in the password, then, for instance, add them together or multiply half of them, then divide that with the other half, or whatever. And use any number that comes out as the 'password'.
' Note: Under some circumstances, it may be possible for the encrypted string to include Chr$(0). Visual Basic handles this just fine but Windows (and therefore the TextBox control) uses Chr$(0) to signify the end of the string.
' Therefore, programs such as this one that store the encrypted data in a text box may end up truncating the data. Proper use of this algorithm should involve storing the data where all characters are supported such as to a binary file, or checking that the encrypted string actually matches the decrypted one.

Strii, PwdNr

If Not str = Crypt512(Crypt512(str, pwdNr), pwdNr) Then
The password would have to be changed in order for it to work properly.

Views 4,103

Downloads 1,299

CodeID
DB ID