What's wrong with this encryptor?
hi,
i've been making a simple string encryptor (in fact just imitating what i saw in a site but it was in php) and it seems to work quite good for some time. i don't know whether the problem is about the encryptor or decryptor so im sending both of the codes (it always has a problem with return but, when i dcrypt a long text, it just... starts making mistakes)
And what it does is, it finds the sum of the ascii value of password, adds it to ascii value of each character of the message, and splits each character's ascii value into 3 random pieces and seperates each number with backslash
frmEnc:
VB Code:
Option Explicit
Dim PasswordSum As Integer, TextEncrypted As String
Private Sub Command1_Click()
Dim E As String, i As Integer, ascE As Integer, Letter(1 To 3), E2 As String, ascE2 As Integer, EncLetter As Integer
i = 0
PasswordSum = 0
TextEncrypted = ""
Randomize Timer
For i = 1 To Len(Text2.Text)
E = Mid(Text2.Text, i, 1)
ascE = Asc(E)
PasswordSum = PasswordSum + ascE
Next
For i = 1 To Len(Text1.Text)
E2 = ""
Letter(1) = 0
Letter(2) = 0
Letter(3) = 0
EncLetter = 0
E2 = Mid(Text1.Text, i, 1)
ascE2 = Asc(E2)
EncLetter = ascE2 + PasswordSum
Letter(1) = Fix((Rnd * EncLetter) + 1)
Letter(2) = Fix((Rnd * EncLetter - Letter(1)) + 1)
Letter(3) = EncLetter - (Letter(1) + Letter(2))
TextEncrypted = TextEncrypted & "\" & Letter(1) & "\" & Letter(2) & "\" & Letter(3)
Next
Text3.Text = TextEncrypted
End Sub
Private Sub Command2_Click()
Load frmDec
frmDec.Visible = True
End Sub
frmDec:
VB Code:
Dim Temp As String, LetterSum As Integer, PasswordSum As Integer, A(1 To 3) As Integer, TextDecrypted As String
Private Sub Command1_Click()
Temp = Text1.Text & "\"
i = 0
PasswordSum = 0
Countsl = 0
TextDecrypted = ""
Text3.Text = ""
For i = 1 To Len(Text2.Text)
E = Mid(Text2.Text, i, 1)
ascE = Asc(E)
PasswordSum = PasswordSum + ascE
Next
Tempa = Temp & "#"
For q = 1 To Len(Tempa)
For t = 1 To Len(Tempa)
C = Mid(Tempa, q, t)
If C = "\" Then Countsl = Countsl + 1
Next
Next
For j = 1 To (Countsl - 1) / 3
A(1) = 0
A(2) = 0
A(3) = 0
LetterSum = 0
A(1) = Val(Between("\", "\", Temp))
Temp = Right(Temp, (Len(Temp) - Len(A(1)) - 1))
A(2) = Val(Between("\", "\", Temp))
Temp = Right(Temp, (Len(Temp) - Len(A(2)) - 1))
A(3) = Val(Between("\", "\", Temp))
Temp = Right(Temp, (Len(Temp) - Len(A(3)) - 1))
LetterSum = (A(1) + A(2) + A(3)) - PasswordSum
Text3.Text = Text3.Text + Chr(LetterSum)
If Len(Temp) <= 1 Then MsgBox "Decryption Completed!"
Next
End Sub
Private Function Between(Begining As String, Ending As String, TextToLookIn As String) As String
Dim Be As String, En As String, TTLI As String
Dim Length As Integer
Be = Begining
En = Ending
TTLI = TextToLookIn
TTLI = Right(TTLI, Len(TTLI) - (InStr(1, TTLI, Be) + Len(Be) - 1))
If TTLI = "" Then Exit Function
Between = Left(TTLI, InStr(1, TTLI, En) - 1)
End Function
any help will be appreciated
Re: What's wrong with this encryptor?
You would be much bettr off using M$'s CAPICOM.dll to encrypt and decrypt data. You can google it. Good Luck.