Assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samimmu
    New Member
    • Mar 2007
    • 32

    #1

    Assignment

    hey, guys, how are you doing? i wish everybody is working well, anyway, actually i am a new one, i just want your help guys if you have some experience, in fact, i am a novice i don't know how to make a program in C++. I have no idea, the lecturer has given me this question as my assignement but i really have no idea how to solve it and i don't know how can i post a question in the right way, i hope i can get your responses as soon as possible..thank you, i really appreciate.





    Your country is at war and your enemies are using a secret code to
    communicate with each other. You have managed to intercept a message
    that reads as follows:
    :mmZ\dxZmx]Zpgy
    The message is obviously encrypted using the enemy’s secret code. You
    have just learned that their encryption method is based upon the ASCII code.
    Individual characters in a string are encoded using this system. For example,
    TCP1231 Computer Programming 1 Assignment 1
    Page 3 of 6
    the letter “A” is encoded using the number 65 and “B”is encoded using the
    number 66.
    Your enemy’s secret code takes each letter of the message and encrypts it as
    follows:
    If (OriginalChar + Key > 126) then
    EncryptedChar = 32 + ((OriginalChar + Key) - 127)
    Else
    EncryptedChar = (OriginalChar + Key)
    For example, if the enemy uses Key = 10 then the message “Hey” would be
    encrypted as:
    Character ASCII code
    H
    e
    y
    72
    101
    102
    Encrypted H = (72 + 10) = 82 = R in ASCII
    Encrypted e = (101 + 10) = 111 = o in ASCII
    Encrypted y = ((121 + 10) - 127) = 36 = $ in ASCII
    Consequently, “Hey” would be transmitted as “Ro$”.
    Write a program that decrypts the intercepted message. You only know that
    the key used is a number between 1 and 100. Your program should try to
    decode the message using all possible keys between 1 and 100. When you
    try the valid key, the message will make sense.
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    This question has been moved to the C++ forum.

    ADMIN

    Comment

    • DeMan
      Top Contributor
      • Nov 2006
      • 1799

      #3
      HJave you though about this problem, and what the steps involved in solving it would be?
      Sometimes it helps to try to work out a few "encrypt" and "decrypt" operations to get a good feel for what is going on.

      I suggest that once you have played around a little to see how it works,
      then hardcode a value of key, and define an encrypt and decrypt method (strictly speaking you don't need the encrypt, but it will make it easier for you to test, and it gives a mroe complete program, if you choose to leave it in afterward),
      the encrypt method is reasonably well defined in the spec, so you might like to implement that first, testing the example data you've been given to see that it works fine (make sure it turns Hey into Ro$).
      The decrypt is the opposite, and playing around earlier should help you to manage this task fairly simply....
      Finally, once your confident your program works for the example case, remove the hard coded value of key, and a dd a loop that tries every value from 1 to 100 as the key.
      Now you can test with the hardcoded value and verify that all works.
      HYou can also encrypt a string with a key of your choosing, and see that your decrypt fubnction does find the correct answer

      (I assume your teacher wants you to list every keys output, and find the right one "by eye".....)
      Post Agiain if you run iunto difficulty...

      Comment

      Working...