How to decrypt simple XOR encryption

user3101398

I found the following XOR encryption function on the internet:

void xor_encrypt(char *key, char *string)
{
    int i, string_length = strlen(string);
    for(i=0; i<string_length; i++)
    {
        string[i]=string[i]^key[i];
        printf("%i", string[i]);
    }
}

It works perfect, but I would like to decrypt the string also.

For example:

void xor_decrypt(char *key, char *encrypted_string)
{
    //decrypt method goes here
}

So basically after I encrypt the string, I would use the same encryption key to decrypt the previously encrypted string.

I'm pretty new to programming and I would just like to know how to decrypt the previously encrypted string. Thanks, all help is appreciated.

dmitrig01

One of the cool things about XOR encryption is that when you apply it twice, you get back the original string – see http://en.wikipedia.org/wiki/XOR_cipher.

In your function, xor_decrypt, you take string and key and return string ^ key. If, now, you xor that with the key again, you get (string ^ key) ^ key = string ^ (key ^ key) = string ^ identity = string (by properties of XOR operator: http://en.wikipedia.org/wiki/Exclusive_or#Properties)

Thus, you can just run your function, xor_encrypt, a second time on the output of the first xor_encrypt.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to decrypt simple XOR encryption

From Dev

Simple XOR encryption program not working as intended

From Dev

How can I apply a simple XOR encryption/decryption mechanism in Delphi with no third party packages?

From Dev

How to decrypt PHP Openssl encryption with BASH command

From Dev

How to decode/decrypt MD5 encryption using Java

From Dev

How to Decrypt data that uses Chilkat for Encryption without using Chilcat library

From Dev

XOR encryption with c++

From Dev

C++ XOR encryption

From Dev

Limitation to xor encryption

From Dev

Xor encryption fails

From Dev

Limitation to xor encryption

From Dev

Decoding hexadecimal xor encryption

From Dev

C Xor Encryption (beginner)

From Dev

XOR Encryption with "Padded Key"

From Dev

decrypt/encrypt xor algorithm in C

From Dev

RSA Encryption Javascript and Decrypt Java

From Dev

Decrypt BIP38 encryption?

From Dev

How can I get python XOR to Decrypt a Multi-line String?

From Dev

Porting XOR encryption code to PHP

From Dev

How to create a keystream generator in C for simple XOR cipher?

From Dev

How to decrypt with WinRT without changing existing encryption code in .NET Desktop App?

From Dev

How to set a machine specific encryption to allow only one machine to decrypt data

From Dev

Simply XOR encrypt in Javascript and Decrypt in Java

From Dev

Are there default encryption features to encrypt/decrypt strings in Swift?

From Dev

Encrypt / Decrypt UIImage in Swift using AES Encryption

From Dev

How to do encryption for a simple telephone on Nexus 5 and Ubuntu Touch?

From Dev

Python Simple Encryption program: How to loop Z back to A

From Dev

C++ XOR encryption - decryption issue

From Dev

Porting XOR encryption scheme implemented in PHP

Related Related

  1. 1

    How to decrypt simple XOR encryption

  2. 2

    Simple XOR encryption program not working as intended

  3. 3

    How can I apply a simple XOR encryption/decryption mechanism in Delphi with no third party packages?

  4. 4

    How to decrypt PHP Openssl encryption with BASH command

  5. 5

    How to decode/decrypt MD5 encryption using Java

  6. 6

    How to Decrypt data that uses Chilkat for Encryption without using Chilcat library

  7. 7

    XOR encryption with c++

  8. 8

    C++ XOR encryption

  9. 9

    Limitation to xor encryption

  10. 10

    Xor encryption fails

  11. 11

    Limitation to xor encryption

  12. 12

    Decoding hexadecimal xor encryption

  13. 13

    C Xor Encryption (beginner)

  14. 14

    XOR Encryption with "Padded Key"

  15. 15

    decrypt/encrypt xor algorithm in C

  16. 16

    RSA Encryption Javascript and Decrypt Java

  17. 17

    Decrypt BIP38 encryption?

  18. 18

    How can I get python XOR to Decrypt a Multi-line String?

  19. 19

    Porting XOR encryption code to PHP

  20. 20

    How to create a keystream generator in C for simple XOR cipher?

  21. 21

    How to decrypt with WinRT without changing existing encryption code in .NET Desktop App?

  22. 22

    How to set a machine specific encryption to allow only one machine to decrypt data

  23. 23

    Simply XOR encrypt in Javascript and Decrypt in Java

  24. 24

    Are there default encryption features to encrypt/decrypt strings in Swift?

  25. 25

    Encrypt / Decrypt UIImage in Swift using AES Encryption

  26. 26

    How to do encryption for a simple telephone on Nexus 5 and Ubuntu Touch?

  27. 27

    Python Simple Encryption program: How to loop Z back to A

  28. 28

    C++ XOR encryption - decryption issue

  29. 29

    Porting XOR encryption scheme implemented in PHP

HotTag

Archive