| 131 | |
| 132 | |
| 133 | def decode(bcipher, privkey, verbose=False): |
| 134 | chunksize = int(log(privkey.modulus, 256)) |
| 135 | outchunk = chunksize + 1 |
| 136 | outfmt = '%%0%dx' % (chunksize * 2,) |
| 137 | result = [] |
| 138 | for start in range_func(0, len(bcipher), outchunk): |
| 139 | bcoded = bcipher[start: start + outchunk] |
| 140 | coded = int(hexlify(bcoded), 16) |
| 141 | plain = pow(coded, *privkey) |
| 142 | chunk = unhexlify((outfmt % plain).encode()) |
| 143 | if verbose: |
| 144 | print('Decode:', chunksize, chunk, plain, coded, bcoded) |
| 145 | result.append(chunk) |
| 146 | return b''.join(result).rstrip(b'\x00').decode('utf-8') |
| 147 | |
| 148 | |
| 149 | def key_to_str(key): |