i have written some code to encrypt and decrypt a some text and i want to adapt it so that the encryption will encrypt repeated letters differently
for example "t" would be 44 and "tt" would be something like 4445. I have been using VB for about two months now and was wondering if someone could show me what to do or at least point me in the right direction, thanks.
my code so far...
Public Class Form1
Dim encrypt(0) As Single
Dim x As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim counter As Integer
Dim name As String
Dim encrypt_temp As Single
name = nametxt.Text
x = Len(name)
Dim temp(x - 1) As String
ReDim encrypt(x - 1)
For counter = 1 To x
temp(counter - 1) = Mid(name, counter, 1)
Next
For counter = 0 To x - 1
encrypt_temp = Asc(temp(counter))
encrypt_temp = encrypt_temp * encrypt_temp
encrypt_temp = encrypt_temp / 7
encrypt_temp = encrypt_temp + 14
encrypt(counter) = encrypt_temp
Next
encryptedlbl.Text = ""
For counter = 0 To x - 1
encryptedlbl.Text = encryptedlbl.Text & encrypt(counter)
Next
nametxt.Text = ""
MsgBox("Text encrypted")
For counter = 0 To x - 1
temp(counter) = ""
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim decrypt_temp(0) As String
Dim temp_length As Integer
Dim temp_string As String
Dim new_letter As String
Dim position As Integer
Dim t As Single
For counter = 0 To x - 1
ReDim Preserve decrypt_temp(UBound(decrypt_temp) + 1)
temp_string = LTrim(Str(encrypt(counter)))
temp_length = Len(temp_string)
decrypt_temp(counter) = temp_length
Next
new_letter = ""
position = 1
For counter = 0 To x - 1
t = Convert.ToSingle(Mid(codetxt.Text, position, decrypt_temp(counter)))
position = position + (decrypt_temp(counter))
t = t - 14
t = t * 7
t = Math.Sqrt(t)
new_letter = new_letter & Chr(t)
Next
answerlbl.Text = new_letter
End Sub
End Class
for example "t" would be 44 and "tt" would be something like 4445. I have been using VB for about two months now and was wondering if someone could show me what to do or at least point me in the right direction, thanks.
my code so far...
Public Class Form1
Dim encrypt(0) As Single
Dim x As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim counter As Integer
Dim name As String
Dim encrypt_temp As Single
name = nametxt.Text
x = Len(name)
Dim temp(x - 1) As String
ReDim encrypt(x - 1)
For counter = 1 To x
temp(counter - 1) = Mid(name, counter, 1)
Next
For counter = 0 To x - 1
encrypt_temp = Asc(temp(counter))
encrypt_temp = encrypt_temp * encrypt_temp
encrypt_temp = encrypt_temp / 7
encrypt_temp = encrypt_temp + 14
encrypt(counter) = encrypt_temp
Next
encryptedlbl.Text = ""
For counter = 0 To x - 1
encryptedlbl.Text = encryptedlbl.Text & encrypt(counter)
Next
nametxt.Text = ""
MsgBox("Text encrypted")
For counter = 0 To x - 1
temp(counter) = ""
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim decrypt_temp(0) As String
Dim temp_length As Integer
Dim temp_string As String
Dim new_letter As String
Dim position As Integer
Dim t As Single
For counter = 0 To x - 1
ReDim Preserve decrypt_temp(UBound(decrypt_temp) + 1)
temp_string = LTrim(Str(encrypt(counter)))
temp_length = Len(temp_string)
decrypt_temp(counter) = temp_length
Next
new_letter = ""
position = 1
For counter = 0 To x - 1
t = Convert.ToSingle(Mid(codetxt.Text, position, decrypt_temp(counter)))
position = position + (decrypt_temp(counter))
t = t - 14
t = t * 7
t = Math.Sqrt(t)
new_letter = new_letter & Chr(t)
Next
answerlbl.Text = new_letter
End Sub
End Class