Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,582 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,909 people online right now. Registration is fast and FREE... Join Now!




Practical

 
Reply to this topicStart new topic

Practical

Trevovo
26 Sep, 2008 - 02:37 AM
Post #1

New D.I.C Head
*

Joined: 26 Sep, 2008
Posts: 1

Yarr! It be International Talk like a Pirate Day!

A group of cunning and ruthless Space Pirates have managed to
steal the Astral Dattebayo from the Space Ninja’s village and
hidden it on one of the planets in our solar system. As the captain
of a rival vessel you are keen to acquire this valuable item for
yourself. You have “persuaded” a crew member of the rival ship to
give you the encrypted secret location (ygpsu) as well as
information about the key (its an integer between 1 and 10).
Unfortunately the crew member did not know which algorithm was
used to encrypt it. Knowing your rival captain as well as you do
you are sure that he either used the Caesar Cipher (moving each
character in the string forward as many characters as the key
specifies) or XOR encryption (applying XOR to each character in
the string using the key as the second operand).

Seeing that all Space Pirates are good at programming you devise
the following system.
• An abstract base class Encryption with a pure virtual
decrypt() method which returns a string. The constructor for
this class takes both the message and the key as
parameters.
• Derived classes for each algorithm which implement the
decrypt() method according to the message and key stored
in the class.
• A main program which populates a vector of type Encryption*
with instances of both derived classes with all possible key
values. Dynamic polymorphism is used to invoke the
appropriate algorithm. Since the return value is going to be
one of our solar system’s planets you are able to test each
decrypted message to see if it is one of these values.

#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>


using namespace std;

class Encryption
{
public:

virtual string Decrypt(string msg, int key);

private:

string msg;
int key;
};

class Caeser : public Encryption
{
Caeser::Decrypt(msg,key){

};

class XOR : public Encryption
{
};



int main(int argc, char *argv[])
{

system("PAUSE");
return 0;
}
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: Practical
26 Sep, 2008 - 03:30 AM
Post #2

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 580



Thanked: 59 times
Dream Kudos: 50
My Contributions
Arrrr, how about showing some effort, matey?
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Practical
26 Sep, 2008 - 04:08 AM
Post #3

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,031



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Missin code tags and nary a spot o' effort? Walk the bleedin plank!

Seriously, you've done almost nothing and the little you did is wrong.

Here's a gift.

cpp

class Encryption {
public:
// I'm betting your derived classes will want access to these values.
// Since you probably don't want to change them in the class either
// might as well make them public and const
const string msg;
const int key;

// The constructor that was asked for
Encryption(const string &msg, int key) : msg(msg), key(key) {}

// The "pure" virtual method
virtual string decrypt() = 0;
};


Now put yer back into it or yer fish food. pirate.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 12:35AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month