well, obviously i've been away from MS/VB6 for a while, and i wanted to make a quick simple encryption program in VB, which just advanced the ASCII characters by a certain amount. However i have gotten an error.
Code: Private Sub cmdEncrypt_Click()
Message = txtInput.Text
Dim EncryptedMsg As String
Dim checknum As Long
checknum = Rand(1, 9)
For i = 0 To 255
EncryptedMsg = Replace$(Message, Chr(i), Chr(i + checknum))
Next i
txtOutput.Text = EncryptedMsg
End Sub
Function Rand(ByVal Low As Integer, ByVal High As Integer) As Integer
Randomize
Rand = ((High - Low + 1) * Rnd) + Low
End Function
i get a run-time error 5: invalid procedure call or argument, and highlights this line
Code: EncryptedMsg = Replace$(Message, Chr(i), Chr(i + checknum))
thanks,
-Pb
hmph, well i kinda got it to work, it doesn't give me an error anymore, however the displayed text is...not text?
[code]Private Sub cmdEncrypt_Click()
Message = txtInput.Text
Dim EncryptedMsg As String
Dim checknum As Long
checknum = Rand(1, 9)
For i = 0 To 255
If i + checknum
Dragoons Master
Unregistered
Dont use an if. Use Mod operator:
[code] If i + checknum
hmm, i've never seen that before...
tried it, still didn't work, actually kinda made it worse, now i just get one NULL character instead of at least the same amount. :S
Right before a "message =" put msgbox chr(i) just to see what character it's on.
hmph, i ran that, and remembered that several of the beginning "characters" are NULL, so i changed the for loop variables, and tried it, all i got was "#"#"# repeating for the amount of characters i put in.
so i took out the if, then all i got was €€€€€€€€€€€€€
note: i had put in "abcdefghijklmnopqrstuvwxyz"
[code]Private Sub cmdEncrypt_Click()
Message = txtInput.Text
Dim EncryptedMsg As String
Dim checknum As Long
checknum = Rand(1, 9)
For i = 32 To 126
'If i + 2
What are EncryptedMsg and checknum doing in that sub anyway?
well they had been in there prior for part of the encrypting, however i was doing some debugging and took them out for the time being.
Change to You should understand that to do from there.
Dragoons Master
Unregistered
Actually, make it
And use mod operator, it's just easier.
@Egon:
If you use anything else than the above, you will be subject to errors when decrypting.
alright, and i just kinda realized why i was only getting 2 different characters in the final string, i was adding/replacing in the same string, so the replace command was replacing characters it had just previously replaced. And now i remember why i had the encryptedmsg in there
edit: hmph, alright i tried it, and it came up with a type mismatch error
[code]Private Sub cmdEncrypt_Click()
Message = txtInput.Text
Dim EncryptedMsg As String
Dim checknum As Long
checknum = Rand(1, 9)
For i = 0 To 255
'If i + 2
Dragoons Master
Unregistered
Message = Replace$(Message, Chr(i), Chr((i + 2) Mod (255)))
Would be more correct.
And well, you will always get a fucked up string... You can't use the semi-encrypted string to replace, you need a backup, but actually even that will not work. You need to replace each character...
Here is the working function:
Code: Dim checknum As Long
Dim i As Long
Randomize
checknum = Int((9 * Rnd) + 1)
txtOutput.Text = ""
For i = 1 To Len(txtInput.Text)
txtOutput.Text = txtOutput.Text & Chr((Asc(Mid(txtInput.Text, i, 1)) + checknum) Mod 256)
Next i
heh, nice i didn't think of that :oops:
lol, thanks a bunch!
ok full working program and source for anyway who wants it, albeit it's defenatly not very advanced or anything, it can be kinda fun
|