Results 1 to 3 of 3

Thread: VB.NET | Own encryption system

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2019

    VB.NET | Own encryption system

    So recently, I decided to try to create my own encryption system and almost succeeded, but decryption doesn't work as it should. Turns chars other places than they should etc. "stet" comes out of "test" after decryption.

        Public Shared output As String
        Public Shared Function Encrypt(ByVal text As String) As String
            For Each cc As String In text
                If cc.Contains("A") Then
                    output = output + "&X01z"
                End If
                If cc.Contains("B") Then
                    output = output + "&X08u"
                End If
        End function
        Public Shared outputD As String
        Public Shared Function Decrypt(ByVal textD As String) As String
            For Each WORD As String In textD.Split("")
                If textD.Contains("&X01z") Then
                    outputD = outputD + "A"
                End If
                If textD.Contains("&X08u") Then
                    outputD = outputD + "B"
                End If
         End function
    I know it may be weird coded and useless but I want only to learn about it.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002

    Re: VB.NET | Own encryption system

    Yeah, it's weird. Both For loops look wrong, and the it seems to deal only with two characters. I assume this isn't the code you are actually using, which means it's very hard to say much of anything about it.
    My usual boring signature: Nothing

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: VB.NET | Own encryption system

    Showing us code that doesn't do X and asking us to show you how to make it do X without telling us what X actually is is a rather futile exercise. You should do what anyone should do in such a situation: treat it like it's not a programming problem. That way, no lack of programming experience can be an issue.

    Assume that everything will be done with pen and paper and that you need to provide instructions to someone else who has no prior exposure to the problem. What would those instructions be? They need to be detailed, step-by-step instructions on how to go from input to output. Write those instructions down and then follow them yourself with pen and paper. When you can get the correct results every time, you have a working algorithm.

    Only at that point should you start writing any code and the code you write should implement the steps of your algorithm. Each step will require only a very small number of lines of code - often just one - so it's very easy to confirm that your code actually implements your algorithm as you go. You can then run your code and see if you get the same results as the manual calculations. If not, you need to debug it, i.e. set breakpoints and step through the code line by line, examining the state at each step to confirm that it is what you expect. You can even debug while performing a manual calculation simultaneously. You will either find the exact spot where the code doesn't behave as expected and what data is in use at the time, or you will confirm that your expectations are incorrect.

    Only when you have done all that and still can't solve the problem should you be posting questions on forums. At that stage, you can provide far more relevant information that you have done here, which would include all that you discovered while debugging. You don't just go from idea to code, look at the results and then post if they're wrong. There's lots that you can do in between.

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