Is there any way to decode this?

Is there any way to decode this encryption

#include <stdlib.h>
#include <iostream >
using namespace std;
void encrypt( char p[] ); // prototypes of functions used in the code
int main( )
{
char s[MAX_PATH + 1];
cin.getline(s, MAX_PATH);
cout << "Your string before encription: " << s << endl;
encrypt(s);
cout << "Your string after encryption: " << s;
return 0;
} // encrypt
void encrypt(char p[])
{
for (int i = 0; p[i] != '\0'; i++)
p[i] = '*';
}
You're replacing everything with stars? Also, what is MAX_PATH? Did you even try to compile this?
Also, use the code tags.
Last edited on
Hethrir, MAX_PATH is a microsoft macro containing the max file path length allowed on windows (same as PATH_MAX on Linux)

Vizard, no you can't decrypt that, as your crypted data doesn't depend on the unencrypted data
Ok thanks, I was just wondering about it (i'm kind of new to this).
The answer is, no, because you are not actually encrypting your message. You are replacing it with asterisks. That's a one-way function.

Hmm, I just noticed that bartoli already said that.

@vizard
What is it you are trying to do, exactly? Is this a homework for CS101 or something? Advanced encryption methods are around CS300 and above. If this is coursework, you can get along with something as simple as a Caesar cipher, where you just add three to each letter in the code, wrapping around.

A lookup table helps.

  INPUT  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  OUTPUT D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

Given the input letter 'K', we find 'K' in the INPUT table, and then find its match in the OUTPUT table, which is 'N'. (Remember, 'K' + 3 = 'N'.)

So, your encryption could take a message like:

  HELLO WORLD

and turn it into

  KHOOR ZRUOG

To turn it back, you just use the lookup tables the other way, that is, subtract three.

There are other things to consider, of course. Do you stick to just uppercase letters? Or do you use every value possibly input?

BTW, there is no reason you should be using MAX_PATH (or #including <windows.h> to access the macro). Just specify a large number like 1000. Though...

you really should be using std::string (#include <string>). If you haven't been taught that yet, the char* is fine.

Hope this helps.
Last edited on
Topic archived. No new replies allowed.