Results 1 to 10 of 10

Thread: What's wrong

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    Newcastle
    Posts
    13

    What's wrong

    i have this code to make a simple encryption in vb.2008
    it should take a letter and change it/swap it for another for example "A"="B"
    and so on and so forth,
    i have a basic understanding of vb but not much and i have a vague idea of what i need to do but the code just doesnt seem to work and everything i try just doesnt work, i have used the "Replace" and "insert" methods
    but they are not what i am looking for

    Dim X(3) As Char

    For i = 0 To 3
    X(i) = ChrW(100)

    Next i
    Console.WriteLine(X[0]&X[1]&X[2]&X[3])

    End Function

    End Class

    The X would be 25 because of the alphabet 
    Hope you can help

    Rich.vb
    Last edited by richardMorris.vb; Feb 7th, 2012 at 09:30 AM.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: What's wrong

    You'll have to post your code in order for us to help you.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    Newcastle
    Posts
    13

    Re: What's wrong

    sorry it's very basic but it gives you an idea of what i need:
    Dim X(3) As Char

    For i = 0 To 3
    X(i) = ChrW(100)

    Next i
    Console.WriteLine(X[0]&X[1]&X[2]&X[3])

    End Function

    End Class

    The X would be 25 because of the alphabet

    cheers

    Rich.vb

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: What's wrong

    duplicate posting - http://www.vbforums.com/showthread.php?t=671790
    Please do not create more than one post for the same problem... it just leads to all kinds of confusion... people who reply to that post won't see this one, and people replying to this one won't see the other...

    ----
    That said... your code at the moment does nothing but dispaly a string of 4 char 100 ... your'e not inserting or replacing anything...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    Newcastle
    Posts
    13

    Re: What's wrong

    could you help me with anything?

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: What's wrong

    As TG states, you aren't really doing anything in that code. All the loop does is puts four copies of ChrW(100) into the four array slots. That makes it pretty difficult to suggest anything. If you wanted to encrypt some string, you'd first need the string you wanted to encrypt, then you'd have some function to change the values into something else. There isn't a string in that code, nor is there a mechanism to supply one, nor is there even a need for one. Therefore, there really isn't much that can be said about it. I would expect that there be a string, then you would loop through the characters in the string either replacing each character with a different one, or getting the ASCII value for the character and adding a number to it, or something like that.
    My usual boring signature: Nothing

  7. #7
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: What's wrong

    Since there's not much to go on here(code didn't make much sense), maybe I can take a swing and hopefully not miss...

    Perhaps, are you converting your characters to another by using .Replace()?

    If you are then it could get a little tricky. Take this example..

    String = 'abcde'

    and your conversions are a=b, b=c, c=d, d=e, e=f

    The problem that will occur is if you do...

    String.Replace("a", "b"), results in String = 'bbcde'

    Next... this is where the problem occurs.

    String.Replace("b", "c"), results in String = 'cccde'


    With this example you will eventually end up with 'fffff', but that's only because I have consecutive alpha values, maybe in your case you don't but this will still occur. Which would make it impossible to bring it back to what it was by reversing the order.


    To do this your going to have to go through your string, character by character and build it into another string.

    vbnet Code:
    1. Dim String1 As String = "abcde"
    2. Dim String2 As String = ""
    3. Dim sub As String
    4.  
    5. For i as Int32 = 0 to String1.Length-1
    6.     sub = String1.SubString(i, 1)
    7.     Select Case sub 'This can implement your own way of determining your values. This was for the sake of my example.
    8.         Case "a":    String2 &= "b"
    9.         Case "b":    String2 &= "c"
    10.         Case "c":    String2 &= "d"
    11.         Case "d":    String2 &= "e"
    12.         Case "e":    String2 &= "f"
    13.     End Select
    14. Next i
    15.  
    16. 'This should result in String1 = "bcdef"

    I mean there are a hundred ways you could be doing this, and I'm sure there's a simpler way. But for the sake of learning I keep it simple, in hopes you will understand and build from there.

    Hope this was your problem, and can help you solve it!
    Last edited by DavesChillaxin; Feb 7th, 2012 at 11:54 AM.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    Newcastle
    Posts
    13

    Re: What's wrong

    Thank you very much for help

    unfortunately it didn't work and i dont understand why haha

    yer basically what i am aiming for is a ceasar cipher if that helps anyone?

    once again thank you, your time was very much given to a grateful person

    Thanks

    R.Vb
    A programmer in need, is a programmer in deed

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: What's wrong

    Aah... ok... that makes it a little easier then.... The Caesar Cipher is a shift cipher... first thing to do is determine what shift you want... and if you want to be able to change it or leave it alone.
    then the steps to encrypt it are as follows:
    1) loop through each letter
    2) get the value (ASCII)
    3) Apply the shift value
    4) convert it back to a char (ToChar)
    5) add the character to a new string (not the original one)
    6) Repeat the loop until done.

    then to decrypt it you apply the same logic but reverse the shift value.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    Newcastle
    Posts
    13

    Re: What's wrong

    thank you tg,

    my issue is that for example i make a = £
    just so i text code is unreadable.....

    would you be able to shed any light on this situation

    many thanks

    R.Vb
    A programmer in need, is a programmer in deed

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width