Esempio n. 1
0
def test_encipher_decipher_gm():
    ps = [
        131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197,
        199
    ]
    qs = [
        89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 47
    ]
    messages = [
        0,
        32855,
        34303,
        14805,
        1280,
        75859,
        38368,
        724,
        60356,
        51675,
        76697,
        61854,
        18661,
    ]
    for p, q in zip(ps, qs):
        pri = gm_private_key(p, q)
        for msg in messages:
            pub = gm_public_key(p, q)
            enc = encipher_gm(msg, pub)
            dec = decipher_gm(enc, pri)
            assert dec == msg
Esempio n. 2
0
def test_encipher_decipher_gm():
    ps = [131, 137, 139, 149, 151, 157, 163, 167,
          173, 179, 181, 191, 193, 197, 199]
    qs = [89, 97, 101, 103, 107, 109, 113, 127,
          131, 137, 139, 149, 151, 157, 47]
    messages = [
        0, 32855, 34303, 14805, 1280, 75859, 38368,
        724, 60356, 51675, 76697, 61854, 18661,
    ]
    for p, q in zip(ps, qs):
        pri = gm_private_key(p, q)
        for msg in messages:
            pub = gm_public_key(p, q)
            enc = encipher_gm(msg, pub)
            dec = decipher_gm(enc, pri)
            assert dec == msg
Esempio n. 3
0
 def decode(self, encoded_message: List[int]):
     message_code = decipher_gm(encoded_message, self.priv_key)
     decoded_message = binascii.unhexlify(
         format(message_code, "x").encode("utf-8")).decode("utf-8")
     return decoded_message