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

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

Page 1 of 1

5 Replies - 1272 Views - Last Post: 24 May 2009 - 09:10 AM Rate Topic: -----

#1 jeanaz1989  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 28-April 09

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

Post icon  Posted 22 May 2009 - 09:01 AM

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:
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.
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.

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.
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 :)

Is This A Good Question/Topic? 0
  • +

Replies To: VB.netRandom Code Generator+ Slow motion+encrypt+decrypt

#2 jeanaz1989  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 28-April 09

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

Posted 23 May 2009 - 08:29 AM

can anybody help me????? this is really important :/
Was This Post Helpful? 0
  • +
  • -

#3 Damage  Icon User is online

  • Lord of Schwing
  • member icon

Reputation: 56
  • View blog
  • Posts: 1,215
  • Joined: 05-June 08

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

Posted 23 May 2009 - 11:22 PM

taken from http://www.codeguru....icle.php/c10343

   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?
Was This Post Helpful? 0
  • +
  • -

#4 jeanaz1989  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 28-April 09

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

Posted 24 May 2009 - 08:11 AM

i got the Code gen to work but the slow mo is a mystery to me :/
Was This Post Helpful? 1

#5 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

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

Posted 24 May 2009 - 09:02 AM

View Postjeanaz1989, on 24 May, 2009 - 07:11 AM, said:

i got the Code gen to work but the slow mo is a mystery to me :/



Give me ten mins then I can give u some code 4 that
Was This Post Helpful? 0
  • +
  • -

#6 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

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

Posted 24 May 2009 - 09:10 AM

Okay for this u need a timer and to dim y as an integer = 0 and a label1
   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:
'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)'


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1