4 Replies - 486 Views - Last Post: 12 February 2015 - 05:27 AM Rate Topic: -----

#1 Michael9594  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 11-February 15

Any way to change my code to make it look different but do the same.

Posted 12 February 2015 - 04:46 AM

I would like to change the appearance and structure of my code but still do the same thing. It is a encrypter and decrypter using the caeser cipher in VB.net as a console application.
Module Module1
    Sub Main()
        Dim answer As String

        answer = ""
        While answer <> "encrypt" And answer <> "decrypt"
            Console.WriteLine("Do you wish to encrypt or Decrypt?")
            answer = Console.ReadLine()
            answer = answer.ToLower()
        End While

        If answer = "encrypt" Then
            Console.WriteLine(Encrypt)
            Console.ReadKey()
        ElseIf answer = "decrypt" Then
            Console.WriteLine(Decrypt)
            Console.ReadKey()
        End If


    End Sub

    Function Encrypt() As String
        Dim shift As Integer
        Dim Text As String
        Dim EncodedMessage As String

        Console.Write("Enter your text that you would like to encrypt. ")

        Text = Console.ReadLine()
        Dim LetterArray() As Char = Text.ToCharArray

        Console.Write("How many places would you like to shift your message by? ")

        shift = Console.ReadLine()



        For i = 0 To LetterArray.Length - 1

            EncodedMessage = EncodedMessage & Chr(Asc(LetterArray(i)) + shift)

        Next


        Return EncodedMessage



    End Function
    Function Decrypt() As String
        Dim shift As Integer
        Dim Text As String
        Dim EncodedMessage As String

        Console.Write("Enter your text that you would like to decrypt. ")

        Text = Console.ReadLine()
        Dim LetterArray() As Char = Text.ToCharArray

        Console.Write("How many places would you like to shift your message by? ")

        shift = Console.ReadLine()



        For i = 0 To LetterArray.Length - 1

            EncodedMessage = EncodedMessage & Chr(Asc(LetterArray(i)) - shift)

        Next


        Return EncodedMessage



    End Function



End Module



Is This A Good Question/Topic? 0
  • +

Replies To: Any way to change my code to make it look different but do the same.

#2 djjeavons  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 114
  • View blog
  • Posts: 417
  • Joined: 09-January 09

Re: Any way to change my code to make it look different but do the same.

Posted 12 February 2015 - 05:14 AM

View PostMichael9594, on 12 February 2015 - 04:46 AM, said:

I would like to change the appearance and structure of my code but still do the same thing. It is a encrypter and decrypter using the caeser cipher in VB.net as a console application.

Why? What appearance and structure are you looking to change it to?

I haven't tested your code but it looks fine in the main. You are using decent variable names, you have two functions that do explicit things and they are called from your main routine. What is it that you don't like about your code at the moment?
Was This Post Helpful? 0
  • +
  • -

#3 Michael9594  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 11-February 15

Re: Any way to change my code to make it look different but do the same.

Posted 12 February 2015 - 05:23 AM

It's for a school project and someone I think has copied my code so I would prefer to change it if possible. I
Am unsure of how to change it because I haven't learnt a different way to do it.

This post has been edited by andrewsw: 12 February 2015 - 05:35 AM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#4 djjeavons  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 114
  • View blog
  • Posts: 417
  • Joined: 09-January 09

Re: Any way to change my code to make it look different but do the same.

Posted 12 February 2015 - 05:25 AM

Well, luckily files have a created date and time stamp so your teacher will know that you wrote it first and that someone copied it from you :) unless of course ....
Was This Post Helpful? 1
  • +
  • -

#5 Michael9594  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 11-February 15

Re: Any way to change my code to make it look different but do the same.

Posted 12 February 2015 - 05:27 AM

View Postdjjeavons, on 12 February 2015 - 05:25 AM, said:

Well, luckily files have a created date and time stamp so your teacher will know that you wrote it first and that someone copied it from you :)/> unless of course ....

Oh ok thanks, I will mention it to him. Saves me a lot of time 😊
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1