Example #1
0
    def test_mixComplexByteStringWithItself(self):
        string = b'complex bytes string: \x99 \xff \x00'
        result = xor(string, string)

        if isinstance(string, bytes):
            assert xor(result, string) == string
        else:
            assert xor(result, string) == string.encode('utf-8')
Example #2
0
    def test_mixUnicodeWithItself(self):
        string = u'simple unicode string'
        result = xor(string, string)

        if isinstance(string, bytes):
            assert xor(result, string) == string
        else:
            assert xor(result, string) == string.encode('utf-8')
Example #3
0
    def test_mixByteStringWithItself(self):
        string = b'bytes string'
        result = xor(string, string)

        if isinstance(string, bytes):
            assert xor(result, string) == string
        else:
            assert xor(result, string) == string.encode('utf-8')
Example #4
0
    def test_mixStrangeUnicodeWithItself(self):
        string = u'unicode string with unicode charaters: ❄'
        result = xor(string, string)

        if isinstance(string, bytes):
            assert xor(result, string) == string
        else:
            assert xor(result, string) == string.encode('utf-8')
Example #5
0
    def test_mixUnicodeWithStrangeUnicode(self):
        string1 = u'simple unicode string'
        string2 = u'unicode string with unicode charaters: ❄'
        result = xor(string1, string2)

        if isinstance(string1, bytes):
            assert xor(result, string2) == string1
        else:
            assert xor(result, string2) == string1.encode('utf-8')

        result = xor(string2, string1)
        if isinstance(string2, bytes):
            assert xor(result, string1) == string2
        else:
            assert xor(result, string1) == string2.encode('utf-8')
Example #6
0
    def test_mixByteStringWithComplexByteString(self):
        string1 = b'bytes string'
        string2 = b'complex bytes string: \x99 \xff \x00'
        result = xor(string1, string2)

        if isinstance(string1, bytes):
            assert xor(result, string2) == string1
        else:
            assert xor(result, string2) == string1.encode('utf-8')

        result = xor(string2, string1)
        if isinstance(string2, bytes):
            assert xor(result, string1) == string2
        else:
            assert xor(result, string1) == string2.encode('utf-8')
Example #7
0
    def test_mixStrangeUnicodeWithComplexByteString(self):
        string1 = u'unicode string with unicode charaters: ❄'
        string2 = b'complex bytes string: \x99 \xff \x00'
        result = xor(string1, string2)

        if isinstance(string1, bytes):
            assert xor(result, string2) == string1
        else:
            assert xor(result, string2) == string1.encode('utf-8')

        result = xor(string2, string1)
        if isinstance(string2, bytes):
            assert xor(result, string1) == string2
        else:
            assert xor(result, string1) == string2.encode('utf-8')
Example #8
0
    def test_mixUnicodeWithByteString(self):
        string1 = u'simple unicode string'
        string2 = b'bytes string'
        result = xor(string1, string2)

        if isinstance(string1, bytes):
            assert xor(result, string2) == string1
        else:
            assert xor(result, string2) == string1.encode('utf-8')

        result = xor(string2, string1)
        if isinstance(string2, bytes):
            assert xor(result, string1) == string2
        else:
            assert xor(result, string1) == string2.encode('utf-8')
Example #9
0
 def test_byte_key_is_shorter(self):
     string1 = "0123456789ABCDEF"
     string2 = "FEDCBA98"
     assert xor(bytes(string1.encode('utf-8')),
                bytes(string2.encode('utf-8'))) \
         == b'vtvpvt\x0f\x0f~|\x05\x01\x01\x05|~'
Example #10
0
 def test_byte_key_is_bigger(self):
     string1 = "0123456789ABCDEF"
     string2 = "FEDCBA9876543210FEDCBA"
     assert xor(bytes(string1.encode('utf-8')),
                bytes(string2.encode('utf-8'))) \
         == b'vtvpvt\x0f\x0f\x0f\x0ftvpvtv'
Example #11
0
 def test_byte_same_size(self):
     string1 = "0123456789ABCDEF"
     string2 = "FEDCBA9876543210"
     assert xor(bytes(string1.encode('utf-8')),
                bytes(string2.encode('utf-8'))) \
         == b'vtvpvt\x0f\x0f\x0f\x0ftvpvtv'
Example #12
0
 def test_not_byte_same_size(self):
     assert xor("0123456789ABCDEF", "FEDCBA9876543210") \
         == b'vtvpvt\x0f\x0f\x0f\x0ftvpvtv'