Hello all, my name is jean-michel azzopardi from malta, and i'm a total beginner when it comes to programming. So i got a few questions and i hear this is the forum to post it on.
So basically i gotta generate 200 random chars(in slow motion) at the start, 200 random chars(in slow motion) at the end and about 50 in the middle. the middle part is the important one. i need to encrypt a message something small just to prove that it works like "Hello" or "Test".
I need to later decrypt it, for this part i have absolutely no code as i have no idea how to do it, therefore i don't expect any help at all.
This is the code i have so far:
CODE
Public Class GenerateString
Public Shared Function GenerateRandomString(ByVal varlength As Integer) As String
Dim AsciiA As Integer
Dim AsciiZ As Integer
Dim VarCharcounter As Integer
Dim VarIntgenerator As Integer
Dim VarStrgenerator As String
Dim VarNewGenerator As New Random(System.DateTime.Now.Millisecond)
AsciiA = Asc("a")
AsciiZ = Asc("z")
VarStrgenerator = ""
While (VarCharcounter < varlength)
VarIntgenerator = VarNewGenerator.Next(AsciiA, AsciiZ)
If (VarIntgenerator >= AsciiA) And (VarIntgenerator <= AsciiZ) Then
VarStrgenerator = VarStrgenerator + Chr(VarIntgenerator)
VarCharcounter = VarCharcounter + 1
End If
End While
GenerateRandomString = VarStrgenerator
End Function
End Class
that generates the code perfectly, so no problem there.
CODE
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Varstring As String = Txtmsg.Text
Dim wordlen As Integer = Txtmsg.TextLength
Dim wordint As Integer = 0
Dim charword(wordlen) As Char
For wordint = 0 To wordlen - 1
charword(wordint) = Varstring(wordint)
Next
Dim varlength As Integer = Varstart + (vargap * Txtmsg.TextLength)
Txtmsg.Text = GenerateString.GenerateRandomString(varlength)
Dim varstrencry = Txtmsg.Text
Dim varintencry As Integer = 0
Dim varlengthencry As Integer = Txtmsg.TextLength
Dim varcharencry(varlengthencry) As Char
Dim varresultencry As String = ""
Dim varposencry As Integer = 0
Dim varcharposencry As Integer = Varstart
For varintencry = 0 To varlengthencry - 1
If varintencry = varcharposencry Then
varcharencry(varintencry) = charword(varposencry)
varposencry = varcharposencry + vargap
varresultencry = varresultencry + varcharencry(varintencry)
Else
varcharencry(varintencry) = varstrencry(varintencry)
varresultencry = varresultencry + varcharencry(varintencry)
End If
Next
Txtmsg.Text = varresultencry
End Sub
Now that part is for the Encryption, now it properly encrypts 1 character just fine, but it only works for one char, while i need abt 5 or so. and i cant figure out a proper algorithm.
I tried to incorporate the slow motion display for the code but again very buggy, this is what i came up with, i included the new code generation and the slow motion.
CODE
rivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static counter As Integer
counter += 1
If counter = 1 Then
Timer1.Enabled = False
End If
Dim CharBlock As Integer = 200
RandomBlock1.Text = GenerateString.GenerateRandomString(CharBlock)
Dim RandomBlock1var As String
RandomBlock1var = RandomBlock1.Text
Dim Count As Integer
Dim Length As Integer = RandomBlock1var.Length
Dim Char1 As Char = RandomBlock1var
Dim Countvar As Integer = 0
For Count = 0 To Length - 1
Char1 = RandomBlock1var(Count)
Select Case Char1
Case "a"c, "A"c
Countvar += 1
Case "e"c, "E"c
Countvar += 1
Case "i"c, "I"c
Countvar += 1
Case "o"c, "O"c
Countvar += 1
Case "u"c, "U"
Countvar += 1
End Select
If Countvar = 1 Then
Exit For
End If
Next
start = Count
End Sub
although besides this code being messed up, the encryption became even more jumbled.
CODE
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Varstring As String = Txtmsg.Text
Dim wordlen As Integer = Txtmsg.TextLength
Dim wordint As Integer = 0
Dim charword(wordlen) As Char
For wordint = 0 To wordlen - 1
charword(wordint) = Varstring(wordint)
Next
Dim varlength As Integer = start + (space * Txtmsg.TextLength)
Txtmsg.Text = GenerateString.GenerateRandomString(varlength)
Dim varstrencry = Txtmsg.Text
Dim varintencry As Integer = 0
Dim varlengthencry As Integer = Txtmsg.TextLength
Dim varcharencry(varlengthencry) As Char
Dim varresultencry As String = ""
Dim varposencry As Integer = 0
Dim varcharposencry As Integer = start
For varintencry = 0 To varlengthencry - 1
If varintencry = varcharposencry Then
varcharencry(varintencry) = charword(varposencry)
varposencry = varcharposencry + space
varresultencry = varresultencry + varcharencry(varintencry)
Else
varcharencry(varintencry) = varstrencry(varintencry)
varresultencry = varresultencry + varcharencry(varintencry)
End If
Next
Txtmsg.Text = varresultencry
End Sub
any help would be much appreciated, i would really like to know what i am doing wrong, thanks guys and girls