XOR Crypt

holy_spirit

New Member
Reaction score
25
XOR Crypt
Today I faced a new way of encryption
was I applying for a new job, there was a set of questions I have to solve
between them, there was a crypting question, and I thought it could be solve be using a basic way of adding some integer values to the ASCII of current char for specific text (string)
after submitting my answers, I met the supervisor who told my that I failed with that question (crypting one) :rolleyes: and just told me, why you did not use XOR !

some working and I found what XOR encrypt is

0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 1 = 0
1 XOR 0 = 1

if we applied 1 XOR 6 then
(encrypt) 6 with 1
110 (6)
001 (1)
---
111 (7)


(decrypt encrypted) 6 with 1
111 (7)
001 (1)
---
110 (6)


C# Code
Code:
public static string XORCrypt(string toCrypt, string password)
        {
            string encrepted = "";
            int j = 0;
            for (int i = 0; i < toCrypt.Length; i++)
            {
                if(j==password.Length)
                    j=0;
                encrepted += (Char)(toCrypt[i] ^ password[j++]);//Using XOR bitwise operation 
            }
            return encrepted;
        }
        public static string XORDecrypt(string Encrypted, string password)
        {
            string decrypted = "";
            int j = 0;
            for (int i = 0; i < Encrypted.Length; i++)
            {
                if (j == password.Length)
                    j = 0;
                decrypted += (Char)(Encrypted[i] ^ password[j++]);
            }
            return decrypted;
        }


It might help you somehow !
 

SFilip

Gone but not forgotten
Reaction score
634
Why do you need two functions? XORCrypt is the same as XORDecrypt.

It also should be noted that XOR, albeit simple and fast, is a pretty weak (and well known) cipher. Also, in the implementation you posted, passwords "abc" and "abcabc" as well as "cabc" and "bcca" are the same which can make it easier to crack.
 

enouwee

Non ex transverso sed deorsum
Reaction score
240
Why do you need two functions? XORCrypt is the same as XORDecrypt.

Why do you think he failed that test? :rolleyes:

On a side note: I wouldn't call XOR encryption as it's very easy to break using a known plaintext attack or analysing two outputs against the same secret.
 

holy_spirit

New Member
Reaction score
25
It also should be noted that XOR, albeit simple and fast, is a pretty weak (and well known) cipher. Also, in the implementation you posted, passwords "abc" and "abcabc" as well as "cabc" and "bcca" are the same which can make it easier to crack.
Question was, "Use a basic way of encryption, no Advance known methods" with 20 min only!
and yes it is cackable.
 
General chit-chat
Help Users

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top