need help with the chrW function and handling invalid inputs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Apocmonk
    New Member
    • May 2010
    • 2

    need help with the chrW function and handling invalid inputs

    At the moment im working on an encryption program, just to prove something to myself. At the moment I have a problem, when I run the program it will drop a few characters and return wrong characters, here is the encrypter code.

    [code=vbnet]
    Dim x As Int64
    Dim y As Int64
    Dim z As Int64
    Dim chrpos As Int64
    Dim chrcode As Int64
    Dim str As String
    Dim Buffstr As String
    Buffstr = ""
    str = TBX1.Text
    For z = 0 To 10
    Buffstr = ""
    For x = 0 To str.Length - 1
    For y = -32768 To 65535
    If str.Chars(x) = ChrW(y) Then
    chrcode = y
    chrpos = x
    End If
    Next
    chrcode = chrcode + ((chrpos * chrpos))
    While chrcode > 65535
    chrcode -= 65535
    End While
    While chrcode <= -32768
    chrcode += 32768
    End While
    Buffstr = Buffstr & ChrW(chrcode)
    Next
    str = Buffstr
    Next
    tbx2.Text = str
    [/code]
    notes:
    > tbx1 and 2 are textboxes for input/output

    > the difference between the encryption and decryption code is that the decryption is the addition the square of the position of the characters and the encryption is the subraction of the sqaure of the position of the characters

    >when I run the code above and encrypt 195 1's then decrypt the output it rerurns

    111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111222222222222 222222222222222 222223333333333 333333333333334 444444444444444 444445555555555 555555556666666 66666666667耷77耷

    the output should be 195 1's but it is as above

    in advance thank you for the help
    Last edited by Apocmonk; May 10 '10, 12:54 AM. Reason: added actual and expected results
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Originally posted by OriginalPoster
    Original Poster: I have xxx, then do yyy then zzz happens. Here's my code ...
    Ok. You know what you have.
    What you don't have is a question. Nobody here knows why you posted this since you haven't asked anything, or exception or description of any error messages you are getting. You haven't described anything that is broken, or any 'expected' results versus 'actual' results.
    I recommend you read the FAQ about How to ask a good question so the volunteers will be able to help

    Comment

    • Apocmonk
      New Member
      • May 2010
      • 2

      #3
      Originally posted by tlhintoq
      Ok. You know what you have.
      What you don't have is a question. Nobody here knows why you posted this since you haven't asked anything, or exception or description of any error messages you are getting. You haven't described anything that is broken, or any 'expected' results versus 'actual' results.
      I recommend you read the FAQ about How to ask a good question so the volunteers will be able to help
      I have ammended my question and added the actual and expected results. Tahnkyou for thhe pointers

      Comment

      Working...