예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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|~'
예제 #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'
예제 #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'
예제 #12
0
 def test_not_byte_same_size(self):
     assert xor("0123456789ABCDEF", "FEDCBA9876543210") \
         == b'vtvpvt\x0f\x0f\x0f\x0ftvpvtv'