473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Assignment

32
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.
Mar 3 '07 #1
2 2713
MMcCarthy
14,534 Expert Mod 8TB
This question has been moved to the C++ forum.

ADMIN
Mar 3 '07 #2
DeMan
1,806 1GB
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...
Mar 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
10
by: Andrew Koenig | last post by:
It has been pointed out to me that various C++ books disagree about the relative precedence of ?: and the assignment operators. In order to satisfy myself about the matter once and for all, I...
5
by: CoolPint | last post by:
It seems to me that I cannot assign objects of a class which has a constant data member since the data member cannot be changed once the constructor calls are completed. Is this the way it is meant...
16
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
9
by: Rick N. Backer | last post by:
I have an abstract base class that has char* members. Is an assignment operator necessary for this abstract base class? Why or why not? Thanks in advance. Ken Wilson Amer. Dlx. Tele,...
1
by: Jon Slaughter | last post by:
I have a chain of classes(i.e., a series of classes each containing an array of the next class). Each class has array like access. struct Myclass1 { vector(Myclass2) _Myclass2; Myclass2&...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
6
by: Neil Zanella | last post by:
Hello, I would like to know whether the following C fragment is legal in standard C and behaves as intended under conforming implementations... union foo { char c; double d; };
35
by: nagy | last post by:
I do the following. First create lists x,y,z. Then add an element to x using the augumented assignment operator. This causes all the other lists to be changed also. But if I use the assignment...
20
by: TimeHorse | last post by:
I would like to gauge interest in the following proposal: Problem: Assignment statements cannot be used as expressions. Performing a list of mutually exclusive checks that require data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.