Beispiel #1
0
    def test_english_stress(self):
        # 纯英文+数字 性能 测试
        repeat_times = 100
        key = "1bb762f7ce24ceee"
        txt = '1525dsfsdijrwemrkwerw5484856er' * 10

        start_time = time.time()
        cipher = rc4.encode(txt, key)
        end_time = time.time()
        logging.info('*' * 100)
        logging.info(u'单次加密耗时:%.4f秒' % (end_time - start_time))

        start_time = time.time()
        for i in range(repeat_times):
            cipher = rc4.encode(txt, key)
        end_time = time.time()
        logging.info(u'%d次加密耗时:%.4f秒' % (repeat_times, end_time - start_time))

        start_time = time.time()
        decr = rc4.decode(cipher, key)
        end_time = time.time()
        logging.info(u'单次解密耗时:%.4f秒' % (end_time - start_time))

        start_time = time.time()
        for i in range(repeat_times):
            decr = rc4.decode(cipher, key)
        end_time = time.time()
        logging.info(u'%d次解密耗时:%.4f秒' % (repeat_times, end_time - start_time))
        logging.info('*' * 100)
Beispiel #2
0
    def test_chinese_stress(self):
        # 中文 性能 测试
        repeat_times = 100
        key = "1bb762f7ce24ceee"
        txt = '15呵呵5@#E$$@#gh,。h()_=154中文4*4616' * 10

        start_time = time.time()
        cipher = rc4.encode(txt, key)
        end_time = time.time()
        logging.info('*' * 100)
        logging.info(u'单次加密耗时:%.4f秒' % (end_time - start_time))

        start_time = time.time()
        for i in range(repeat_times):
            cipher = rc4.encode(txt, key)
        end_time = time.time()
        logging.info(u'%d次加密耗时:%.4f秒' % (repeat_times, end_time - start_time))

        start_time = time.time()
        decr = rc4.decode(cipher, key)
        end_time = time.time()
        logging.info(u'单次解密耗时:%.4f秒' % (end_time - start_time))

        start_time = time.time()
        for i in range(repeat_times):
            decr = rc4.decode(cipher, key)
        end_time = time.time()
        logging.info(u'%d次解密耗时:%.4f秒' % (repeat_times, end_time - start_time))
        logging.info('*' * 100)
Beispiel #3
0
    def test_encode_decode(self):
        key = "1bb762f7ce24ceee"

        # 英文加密测试
        txt = 'abc321cc55+-*/,.,.dfdehryz908&^%$#@!~*()_+-='
        secret_txt = rc4.encode(txt, key)
        assert secret_txt
        assert rc4.decode(secret_txt, key) == txt

        # 中文加密测试
        txt = '哈哈5+-*/,.,.dfd08&^%$#@!~*()_+-='
        secret_txt = rc4.encode(txt, key)
        assert secret_txt
        assert rc4.decode(secret_txt, key) == txt

        check_unicode = True
        try:
            # py2 的中文加密测试
            unicode
            txt = u'哈哈5+-*/,.,.dfd08&^%$#@!~*()_+-='
            check_unicode = False
            secret_txt = rc4.encode(txt, key)
            assert secret_txt
            assert rc4.decode(secret_txt, key) == txt.encode("utf-8")
            check_unicode = True
        except NameError:
            pass
        assert check_unicode
Beispiel #4
0
    def test_param(self):
        key = "1bb762f7ce24ceee"

        # 明文参数为空测试
        secret_txt = rc4.encode('', key)
        assert not secret_txt
        secret_txt = rc4.encode(None, key)
        assert not secret_txt

        # 密文参数为空测试
        real_text = rc4.decode('', key)
        assert not real_text
        real_text = rc4.decode(None, key)
        assert not real_text

        # 加密 key 为空测试
        txt = '13800138000'
        has_error = False
        try:
            secret_txt = rc4.encode(txt, '')
        except:
            has_error = True
        assert has_error

        has_error = False
        try:
            secret_txt = rc4.encode(txt, None)
        except:
            has_error = True
        assert has_error

        # 解密 key 为空测试
        has_error = False
        try:
            real_text = rc4.decode(txt, '')
        except:
            has_error = True
        assert has_error

        has_error = False
        try:
            real_text = rc4.decode(txt, None)
        except:
            has_error = True
        assert has_error
Beispiel #5
0
    def test_encode_decode(self):
        key = "1bb762f7ce24ceee"

        # 英文加密测试
        txt = '01A0519'
        assert rc4.encode(txt, key) == '36824f33ca5d6c'
        assert rc4.decode(rc4.encode(txt, key), key) == txt

        # 中文加密测试
        txt = '哈哈'
        assert rc4.encode(txt, key) == 'e32086e66ce4'
        assert rc4.decode(rc4.encode(txt, key), key) == txt

        check_unicode = True
        try:
            # py2 的中文加密测试
            unicode
            txt = u'哈哈'
            check_unicode = False
            assert rc4.encode(txt, key) == 'e32086e66ce4'
            assert rc4.decode(rc4.encode(txt, key), key) == txt.encode("utf-8")
            check_unicode = True
        except NameError:
            pass
        assert check_unicode