MCPcopy Create free account
hub / github.com/ActiveState/code / decode

Function decode

recipes/Python/577737_Public_Key_Encryption_RSA/recipe-577737.py:111–123  ·  view source on GitHub ↗
(bcipher, privkey, verbose=False)

Source from the content-addressed store, hash-verified

109 return b''.join(result)
110
111def decode(bcipher, privkey, verbose=False):
112 chunksize = int(log(pubkey.modulus, 256))
113 outchunk = chunksize + 1
114 outfmt = '%%0%dx' % (chunksize * 2,)
115 result = []
116 for start in range(0, len(bcipher), outchunk):
117 bcoded = bcipher[start: start + outchunk]
118 coded = int(hexlify(bcoded), 16)
119 plain = pow(coded, *privkey)
120 chunk = unhexlify((outfmt % plain).encode())
121 if verbose: print('Decode:', chunksize, chunk, plain, coded, bcoded)
122 result.append(chunk)
123 return b''.join(result).rstrip(b'\x00').decode()
124
125
126if __name__ == '__main__':

Callers 1

recipe-577737.pyFile · 0.70

Calls 8

rangeFunction · 0.85
printFunction · 0.85
logFunction · 0.50
powFunction · 0.50
encodeMethod · 0.45
appendMethod · 0.45
decodeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected