String Bitwise XOR

  • Share this:

Code introduction


Perform bitwise XOR operation on two strings and return the resulting string. If the strings are of different lengths, only the shorter string is XORed.


Technology Stack : String, bitwise operation

Code Type : String processing

Code Difficulty : Intermediate


                
                    
        def string_xor(s1, s2):
            return ''.join(chr(ord(c1) ^ ord(c2)) for c1, c2 in zip(s1, s2))