Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Advanced C: Simple XOR Encryption

Lesson 50 of 53 in the free Foundation of C & C++ notes on Siksha Sarovar, written by Rohit Jangra.

The Power of Exclusive OR

XOR is a bitwise operator that is its own inverse. This unique property makes it the foundation of many cryptographic algorithms.

How it works

If you take a message (A) and XOR it with a key (B), you get a scrambled result (C). A ^ B = C If you then XOR that result (C) with the same key (B), you get the original message back! C ^ B = A

Implementation in C

      void encryptDecrypt(char *data, char key) {
      for (int i = 0; i < strlen(data); i++) {
      data[i] = data[i] ^ key;
      }
      }

Why use bitwise for security?

  1. Speed: Bitwise operations happen in a single CPU cycle.
  2. Obfuscation: It's a quick way to hide data from casual observers.
  3. Low Resource: It doesn't require complex mathematical libraries, making it perfect for embedded systems and IoT devices.
Simple XOR encryption is NOT secure against professional hackers. It can be easily broken if the key is short or if the hacker has enough encrypted text to look for patterns. For real security, use industrial standards like AES.