VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,333 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,686 people online right now. Registration is fast and FREE... Join Now!




VB.netRandom Code Generator+ Slow motion+encrypt+decrypt

 

VB.netRandom Code Generator+ Slow motion+encrypt+decrypt, VB.netRandom Code Generator+ Slow motion+encrypt+decrypt

jeanaz1989

22 May, 2009 - 08:01 AM
Post #1

New D.I.C Head
*

Joined: 28 Apr, 2009
Posts: 3



Thanked: 1 times
My Contributions
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 smile.gif








User is offlineProfile CardPM
+Quote Post


jeanaz1989

RE: VB.netRandom Code Generator+ Slow Motion+encrypt+decrypt

23 May, 2009 - 07:29 AM
Post #2

New D.I.C Head
*

Joined: 28 Apr, 2009
Posts: 3



Thanked: 1 times
My Contributions
can anybody help me????? this is really important confused.gif
User is offlineProfile CardPM
+Quote Post

Damage

RE: VB.netRandom Code Generator+ Slow Motion+encrypt+decrypt

23 May, 2009 - 10:22 PM
Post #3

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 975



Thanked: 14 times
Dream Kudos: 75
My Contributions
taken from http://www.codeguru.com/vb/gen/vb_misc/enc...icle.php/c10343

CODE

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim MyText As String
        ' Encrypt
        MyText = "Karl Moore"
        MyText = SimpleCrypt(MyText)
        MessageBox.Show(MyText)
        ' Decrypt
        MyText = SimpleCrypt(MyText)
        MessageBox.Show(MyText)

    End Sub
    Public Function SimpleCrypt(ByVal Text As String) As String
        ' Encrypts/decrypts the passed string using
        ' a simple ASCII value-swapping algorithm
        Dim strTempChar As String = Text
        Dim i As Integer
        For i = 1 To Len(Text)
            If Asc(Mid$(Text, i, 1)) < 128 Then
                strTempChar = _
          CType(Asc(Mid$(Text, i, 1)) + 128, String)
            ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
                strTempChar = _
          CType(Asc(Mid$(Text, i, 1)) - 128, String)
            End If
            Mid$(Text, i, 1) = Chr(CType(strTempChar, Integer))
        Next i
        Return Text
    End Function


you don't mentio if you need to use the .net security classes for encryption?
User is offlineProfile CardPM
+Quote Post

jeanaz1989

RE: VB.netRandom Code Generator+ Slow Motion+encrypt+decrypt

24 May, 2009 - 07:11 AM
Post #4

New D.I.C Head
*

Joined: 28 Apr, 2009
Posts: 3



Thanked: 1 times
My Contributions
i got the Code gen to work but the slow mo is a mystery to me confused.gif
User is offlineProfile CardPM
+Quote Post

Asscotte

RE: VB.netRandom Code Generator+ Slow Motion+encrypt+decrypt

24 May, 2009 - 08:02 AM
Post #5

D.I.C Regular
Group Icon

Joined: 8 Feb, 2009
Posts: 398



Thanked: 10 times
Dream Kudos: 175
My Contributions
QUOTE(jeanaz1989 @ 24 May, 2009 - 07:11 AM) *

i got the Code gen to work but the slow mo is a mystery to me confused.gif



Give me ten mins then I can give u some code 4 that
User is offlineProfile CardPM
+Quote Post

Asscotte

RE: VB.netRandom Code Generator+ Slow Motion+encrypt+decrypt

24 May, 2009 - 08:10 AM
Post #6

D.I.C Regular
Group Icon

Joined: 8 Feb, 2009
Posts: 398



Thanked: 10 times
Dream Kudos: 175
My Contributions
Okay for this u need a timer and to dim y as an integer = 0 and a label1
CODE

   If y = 0 Then
            y = y + 1
            Label1.Text = "H"
        ElseIf y = 1 Then
            y = y + 1
            Label1.Text = Label1.Text + "E"
        ElseIf y = 2 Then
            y = y + 1
            Label1.Text = Label1.Text + "L"
        ElseIf y = 3 Then
            y = y + 1
            Label1.Text = Label1.Text + "L"
        ElseIf y = 4 Then
            y = y + 1
            Label1.Text = Label1.Text + "O"
        ElseIf y = 5 Then
            Button1.Text = "Start"
            Timer1.Enabled = False
            z = False
            y = 0
            MsgBox("cycle complete")
        End If


But this only helps if you know the letters,

The other way is this:
CODE

'puclic declare this'
    Dim i As Integer = 0
    Dim iTimer As Integer = 0
    Dim istr As Integer = 0
'stop here'


'I go inside a timer :)'
        iTimer += 1
        Try
            If iTimer >= i Then
                str = TextBox2.Text.Substring(istr, 1)
                istr += 1
                RichTextBox2.Text += str
            End If
            If RichTextBox2.Text.Length = TextBox2.Text.Length Then
                timer4.Stop()
                str = ""
                istr = 0
            End If
        Catch ex As Exception
            timer4.Enabled = False
            MsgBox(ex.Message)
            timer4.Enabled = False
        End Try
'stop here (If you hadent already guessed)'

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 04:49PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month