0

Is there any function that, for a given non encrypted input, return an encrypted data and for a encrypted input returns the decrypted data?

Somethin like this...

char *text = "This text is being encrypted.";
crypto(text);
//Now "text" is equal to "uhabD143Adev9123CAegawgawash"
crypto(text);
//Now "text" is equal to "This text is being encrypted."

There is no real use for it. Only for demonstration. I won't use it on a real aplication.

4
  • 2
    The basic XOR encryption does this. There may be more: search for symmetrical encryption code. Commented Mar 5, 2015 at 1:49
  • Other symmetric encryption algorithms that are widely used are DES, 3DES, and AES. Commented Mar 5, 2015 at 1:51
  • en.wikipedia.org/wiki/ROT13 Commented Mar 5, 2015 at 12:04
  • There are too many functions that do this. A simple XOR encryption as shown by Mux is easy, but insecure. Basically all stream ciphers operate this way including RC4 or AES in CTR mode or a One Time Pad. Commented Mar 7, 2015 at 17:14

1 Answer 1

1

If same function can encrypt and decrypt it's not actually encryption :) Anyway xor should work fine:

void crypto(char* text, char key) {
  for (; *text; ++text) *text ^= key;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.