|
-
Jul 10th, 2006, 08:40 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Fastest Encryption
Hi, I would like to know what is the fastest encryption available, but I don't want it to be intensively secure. I just want something illegible to the human eye. For example, letter key shifting doesn't work because it's easy to visualize what the words were before hand. I just need something that you can't just crack by staring at it for 10 seconds, but it can't be resource intensive or slow. Any ideas?
-
Jul 10th, 2006, 08:46 AM
#2
Re: Fastest Encryption
Just call encode or decode 
VB Code:
Public Function Encode(Data As String) As String
Randomize
Dim Key() As Long
ReDim Key(Len(Data))
Dim i As Long
Dim LenData As Long
Dim Coded As String
Coded = ""
LenData = Len(Data)
For i = 1 To LenData
Key(i) = (Rnd() * 50 + 1) + 20 'Define keys for each character
Next
For i = 1 To LenData
'Adding the key to each character's ascii
If Asc(Mid$(Data, i, 1)) + Key(i) > 255 Then
'If the new ascii value exceeds 255(Highest char ascii), then count upwards from 0
Coded = Coded & Chr$(Key(i)) & Chr$(Asc(Mid$(Data, i, 1)) + Key(i) - 255)
Else
Coded = Coded & Chr$(Key(i)) & Chr$(Asc(Mid$(Data, i, 1)) + Key(i))
End If
Next
'Return encoded value
'Debug.Print Len(Coded)
Encode = Coded
End Function
Public Function Decode(Data As String) As String
Dim Key() As Long
ReDim Key(Len(Data))
Dim i As Long
Dim Decoded As String
Dim CodedString As String
Dim LenData As Long
Dim LenCodedString As Long
Dim NextChr As Long
Decoded = ""
CodedString = ""
'Seperate the key from the actual code
LenData = Len(Data)
For i = 1 To LenData
If (i / 2) = Int(i / 2) Then
CodedString = CodedString & Mid$(Data, i, 1)
Else
Key(((i - 1) / 2) + 1) = Asc(Mid$(Data, i, 1))
End If
Next
'Minus the key from each character
LenCodedString = Len(CodedString)
For i = 1 To LenCodedString
NextChr = Asc(Mid$(CodedString, i, 1)) - Key(i)
'If the new ascii is below 0, then count backwards from 255
If NextChr <= 0 Then
NextChr = NextChr + 255
End If
'Add to decoded string
Decoded = Decoded + Chr$(NextChr)
Next
'Return Decoded value
Decode = Decoded
End Function
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 10th, 2006, 08:56 AM
#3
Re: Fastest Encryption
I modified the code in my original thread ( VB - 31 Bit Encryption function ) for speed
It should be fast enough, and it's definitelly not readable because it's using random numbers XORed with original string to encrypt.
VB Code:
Public Function RndCrypt(ByRef Str As String, ByVal Password As String) As String
'
' Made by Michael Ciurescu (CVMichael from vbforums.com)
' Original thread: [url]http://www.vbforums.com/showthread.php?t=231798[/url]
'
Dim SK As Long, K As Long, Data() As Byte
Data = StrConv(Str, vbFromUnicode)
' init randomizer for password
Rnd -1
Randomize Len(Password)
' (((K Mod 256) Xor Asc(Mid$(Password, K, 1))) Xor Fix(256 * Rnd)) -> makes sure that a
' password like "pass12" does NOT give the same result as the password "sspa12" or "12pass"
' or "1pass2" etc. (or any combination of the same letters)
For K = 1 To Len(Password)
SK = SK + (((K Mod 256) Xor Asc(Mid$(Password, K, 1))) Xor Fix(256 * Rnd))
Next K
' init randomizer for encryption/decryption
Rnd -1
Randomize SK
' encrypt/decrypt every character using the randomizer
For K = 0 To UBound(Data)
Data(K) = Fix(256 * Rnd) Xor Data(K)
Next K
RndCrypt = StrConv(Data, vbUnicode)
End Function
-
Jul 10th, 2006, 09:00 AM
#4
Re: Fastest Encryption
Remove StrConv and any string processing besides copying byte array to a string and vice versa and you get much faster result (especially with a compiled program).
-
Jul 10th, 2006, 09:05 AM
#5
Re: Fastest Encryption
 Originally Posted by Merri
Remove StrConv and any string processing besides copying byte array to a string and vice versa and you get much faster result (especially with a compiled program).
You mean something like this ?
VB Code:
Option Explicit
Private Declare Sub CopyMemoryStrToAny Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, ByVal pSrc As String, ByVal ByteLen As Long)
Private Declare Sub CopyMemoryAnyToStr Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDest As String, pSrc As Any, ByVal ByteLen As Long)
Public Function RndCrypt(ByRef Str As String, ByVal Password As String) As String
'
' Made by Michael Ciurescu (CVMichael from vbforums.com)
' Original thread: [url]http://www.vbforums.com/showthread.php?t=231798[/url]
'
Dim SK As Long, K As Long, Data() As Byte
ReDim Data(Len(Str) - 1)
CopyMemoryStrToAny Data(0), Str, Len(Str)
' init randomizer for password
Rnd -1
Randomize Len(Password)
' (((K Mod 256) Xor Asc(Mid$(Password, K, 1))) Xor Fix(256 * Rnd)) -> makes sure that a
' password like "pass12" does NOT give the same result as the password "sspa12" or "12pass"
' or "1pass2" etc. (or any combination of the same letters)
For K = 1 To Len(Password)
SK = SK + (((K Mod 256) Xor Asc(Mid$(Password, K, 1))) Xor Fix(256 * Rnd))
Next K
' init randomizer for encryption/decryption
Rnd -1
Randomize SK
' encrypt/decrypt every character using the randomizer
For K = 0 To UBound(Data)
Data(K) = Fix(256 * Rnd) Xor Data(K)
Next K
RndCrypt = String(Len(Str), 0)
CopyMemoryAnyToStr RndCrypt, Data(0), Len(Str)
End Function
-
Jul 10th, 2006, 10:15 AM
#6
Re: Fastest Encryption
There are slowdown factors:- In CopyMemory, you're passing as string. This causes Unicode <-> ANSI conversion behind the scenes.
- Doing API calls is slow.
- Mid$ and Asc are very slow.
- String$ is slow.
- Password is passed to the function ByVal (= extra copy made of the string = slow).
Every time you copy memory, every time you handle memory, every time you calculate anything, you're slowing things down. It is a challenge to get rid of all the things that unnecessarily slowdown the code 
Of course, it is all up to how much speed is required and how it is required. For example, doing lots of sequential calls for small files would require minimal bloat between the actual processing of the data, thus CopyMemory would be a major cause of slowdown with, say, 10000 files. In the other hand, with smaller amount of big files it would be important to make sure the main processing is fast and most of the waiting is caused by the main processing.
But if we truly wanted the fastest encryption, we'd use ASM and not VB.
-
Jul 10th, 2006, 10:31 AM
#7
Re: Fastest Encryption
So, how would you write the code improving the points you made ?
I want to learn how to make fast code
-
Jul 10th, 2006, 12:23 PM
#8
Thread Starter
Addicted Member
Re: Fastest Encryption
Thx for the rndCrypt function. it's quite quick. Exactly what I was looking for. Hopefully won't be too similar that people can recognize characters.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|