|
-
Jun 1st, 2004, 10:44 AM
#1
Thread Starter
Frenzied Member
Simple key 'encryption'
VB Code:
Private Function InvertString(sT As String) As String
Dim sTT As String
For I = Len(sT) To 1 Step -1
sTT = sTT & Mid(sT, I, 1)
Next
InvertString = sTT
End Function
Private Function Encrypt(sT As String, sKey As String) As String
Dim sEncrypted As String
Dim keyCount As Integer
sT = InvertString(sT)
sKey = InvertString(sKey)
keyCount = 1
For I = 1 To Len(sT)
sEncrypted = sEncrypted & Chr(Asc(Mid(sT, I, 1)) + Mid(sKey, keyCount, 1))
keyCount = keyCount + 1
If keyCount > Len(sKey) Then keyCount = 1
Next
Encrypt = sEncrypted
End Function
Private Function Decrypt(sT As String, sKey As String) As String
Dim sDecrypted As String
Dim keyCount As Integer
sKey = InvertString(sKey)
keyCount = 1
For I = 1 To Len(sT)
sDecrypted = sDecrypted & Chr(Asc(Mid(sT, I, 1)) - Mid(sKey, keyCount, 1))
keyCount = keyCount + 1
If keyCount > Len(sKey) Then keyCount = 1
Next
Decrypt = InvertString(sDecrypted)
End Function
Just use, Encrypt() And Decrypt() - remember to pass the same key!!
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Jun 4th, 2004, 09:20 PM
#2
Did you try your own code before posting it ?
First of all, it seems that you like to declare variables global (I think)., because variable "I" is not declared anywhere in any of the functions...
Second, I gt a "Type mismatch", at this line:
VB Code:
sEncrypted = sEncrypted & Chr(Asc(Mid(sT, I, 1)) + Mid(sKey, keyCount, 1))
Asc(Mid(sT, I, 1)) returns a number, and you want to add it to character Mid(sKey, keyCount, 1)...
Third, even if I put Chr(Mid(sKey, keyCount, 1)), it will add the 2 numbers togeter, and if the result is over 255, it will also give an error...
Fourth... there are LOTS of other posts with lame addition/substraction encryptions, that are really easy to crack, if you reverse the strings before you encrypt it, it won't add much of a "twist" to it...
Take a look at the encryptions I posted in the CodeBank, even this encryption is better than what you posted, and it's less code than that
VB - 31 Bit Encryption function
And after you look at that one, look at this one:
VB - 128, 160 and 256 Bit File Encryption/Decryption with MD5, SHA1 and SHA256
-
Jun 6th, 2004, 07:58 AM
#3
Thread Starter
Frenzied Member
Originally posted by CVMichael
Did you try your own code before posting it ?
First of all, it seems that you like to declare variables global (I think)., because variable "I" is not declared anywhere in any of the functions...
Second, I gt a "Type mismatch", at this line:
VB Code:
sEncrypted = sEncrypted & Chr(Asc(Mid(sT, I, 1)) + Mid(sKey, keyCount, 1))
Asc(Mid(sT, I, 1)) returns a number, and you want to add it to character Mid(sKey, keyCount, 1)...
Third, even if I put Chr(Mid(sKey, keyCount, 1)), it will add the 2 numbers togeter, and if the result is over 255, it will also give an error...
Fourth... there are LOTS of other posts with lame addition/substraction encryptions, that are really easy to crack, if you reverse the strings before you encrypt it, it won't add much of a "twist" to it...
Take a look at the encryptions I posted in the CodeBank, even this encryption is better than what you posted, and it's less code than that
VB - 31 Bit Encryption function
And after you look at that one, look at this one:
VB - 128, 160 and 256 Bit File Encryption/Decryption with MD5, SHA1 and SHA256
Whatever you say, I don't have any problems running the code, and I did call it SIMPLE encryption, furthermore, if you don't like it - don't use it, I really don't care.
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Sep 23rd, 2004, 10:58 PM
#4
Addicted Member
yeah... I got that type mismatch too :-P
-
Oct 11th, 2004, 11:32 AM
#5
He did say it was simple. Here, I converted his code into something that compiles. I like it - It gives you a simple layer of security when you just don't want anyone reading your plaintext and you don't care if they try to hack into it.
VB Code:
Option Explicit
'
Private Const KEY As String = "Key1"
'
Private Sub Command1_Click()
Text2 = Encrypt(Text1, KEY)
End Sub
Private Sub Command2_Click()
Text3 = Decrypt(Text2, KEY)
End Sub
Private Function InvertString(sT As String) As String
Dim sTT As String
Dim i As Integer
'
For i = Len(sT) To 1 Step -1
sTT = sTT & Mid(sT, i, 1)
Next
'
InvertString = sTT
End Function
Private Function Encrypt(sT As String, sKey As String) As String
Dim strEncrypted As String
Dim keyCount As Long
Dim i As Long
Dim lngTemp1 As Long
Dim lngTemp2 As Long
'
sT = InvertString(sT)
sKey = InvertString(sKey)
keyCount = 1
'
For i = 1 To Len(sT)
'
lngTemp1 = Asc(Mid(sT, i, 1))
lngTemp2 = Asc(Mid(sKey, keyCount, 1))
strEncrypted = strEncrypted & Chr(lngTemp1 + lngTemp2)
keyCount = keyCount + 1
'
If keyCount > Len(sKey) Then
keyCount = 1
End If
Next
'
Encrypt = strEncrypted
End Function
Private Function Decrypt(sT As String, sKey As String) As String
Dim strDecrypted As String
Dim keyCount As Integer
Dim i As Long
Dim lngTemp1 As Long
Dim lngTemp2 As Long
'
sKey = InvertString(sKey)
keyCount = 1
'
For i = 1 To Len(sT)
'
lngTemp1 = Asc(Mid(sT, i, 1))
lngTemp2 = Asc(Mid(sKey, keyCount, 1))
strDecrypted = strDecrypted & Chr(lngTemp1 - lngTemp2)
keyCount = keyCount + 1
'
If keyCount > Len(sKey) Then
keyCount = 1
End If
Next
'
Decrypt = InvertString(strDecrypted)
End Function
-
Oct 11th, 2004, 11:41 AM
#6
It encrypts only strings where the ASCII values are less than 128, and the key has to have the ASCII values less than 128 also.
Encrypt something like this, and you'll see what I mean:
VB Code:
Debug.Print Encrypt(String(20, 254), KEY)
-
Oct 11th, 2004, 12:32 PM
#7
The code author never meant for it to encrypt "binary data". Just the printable ASCII characters. Again, it works very well for what it was designed to do.
-
Oct 11th, 2004, 01:02 PM
#8
This is very cool, too. You're right, much less code. I'm not sure how one would rate it better or worse than the original post, except to see which one is more crackable..?
I think it's cool you got it to work as a single function.
-
Oct 13th, 2004, 04:12 AM
#9
Hyperactive Member
You guys may want to check out CAPICOM. It's bascially a com wrapper around the cryptoapi. Would probably be a easy means for security in your applications.
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde
-
Jan 6th, 2005, 11:24 PM
#10
Re: Simple key 'encryption'
Windows 2000 Workstation has a problem with Capicom, that I'm trying to figure out.
EDIT:
As it turns out, it only seems to have a problem with
CAPICOM_ENCRYPTION_ALGORITHM_AES
but,
CAPICOM_ENCRYPTION_ALGORITHM_3DES
works fine under both XP and W2K...
Last edited by dglienna; Jan 7th, 2005 at 01:55 AM.
-
Nov 16th, 2005, 03:10 AM
#11
Hyperactive Member
Re: Simple key 'encryption'
when i try it, it only runs once then errors out. any thoughts?
"Anybody can get angry or sad and frown but it takes a person with character to smile when times are hard."
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
|