Skip to content
Snippets Groups Projects
Commit 8d4a3b74 authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

Added function to decode the message

parent 8b321f51
No related branches found
No related tags found
No related merge requests found
from exp_rapide import * from exp_rapide import *
from private_key import * from private_key import *
def decode_message(l: list):
if __name__ == '__main__':
n = 124344401
e = 1919
msg = [68393426, 89432542, 115521861, 49234219, 3372048, 122157013, 22349186, 35164123, 34100658, 53001833, 22308360, 27268540, 105477840, 16762760, 113133501, 37039778, 89387590, 82947194, 52601869, 118123698, 68691007, 51830717, 118914410, 22002115, 99813173, 27268540, 120352256, 64650097, 92433385, 414607, 72100751, 23998007, 66133841, 35164123, 74691367, 80836310, 5505466, 59202893, 115463881, 46024313, 74620807, 37361822, 110605220, 80046495, 99953354, 84193611, 89956350, 55477753, 18387435, 5325873, 73193855, 48738452, 33336672, 89963322, 122314690, 4452285, 110289672, 106228774, 31142434, 414607, 88872943, 29217724, 88230256, 89956350, 55477753, 18387435, 108347427, 7851834, 76320201, 34059930, 82599280, 108347427, 92752873, 64650097, 92433385, 414607, 72100751, 112081917, 4440942, 54795823, 120183171, 44819012, 55032737, 87655596, 105198146, 63239385, 33230638, 10365063, 115372183, 71955667, 115564528, 17503687, 115564528, 5325873, 36896144, 99693494, 111498758, 7774636, 105885047]
decoded = [] decoded = []
p, q = find_p_q(n) p, q = find_p_q(n)
...@@ -16,9 +11,20 @@ if __name__ == '__main__': ...@@ -16,9 +11,20 @@ if __name__ == '__main__':
print(f"q : {q}") print(f"q : {q}")
print(f"d : {d}") print(f"d : {d}")
# Décode chaque bloc avec la clé privée
for m in msg: for m in msg:
decoded.append(str(hex(exp_rapide(m, int(d), n)))[2:]) decoded.append(exp_rapide(m, int(d), n))
# Affiche le message dans le terminal
for x in decoded:
print(x.to_bytes(int((len(hex(x))-2) / 2), 'little').decode('utf8'), end="")
print(decoded) print()
if __name__ == '__main__':
n = 124344401
e = 1919
msg = [68393426, 89432542, 115521861, 49234219, 3372048, 122157013, 22349186, 35164123, 34100658, 53001833, 22308360, 27268540, 105477840, 16762760, 113133501, 37039778, 89387590, 82947194, 52601869, 118123698, 68691007, 51830717, 118914410, 22002115, 99813173, 27268540, 120352256, 64650097, 92433385, 414607, 72100751, 23998007, 66133841, 35164123, 74691367, 80836310, 5505466, 59202893, 115463881, 46024313, 74620807, 37361822, 110605220, 80046495, 99953354, 84193611, 89956350, 55477753, 18387435, 5325873, 73193855, 48738452, 33336672, 89963322, 122314690, 4452285, 110289672, 106228774, 31142434, 414607, 88872943, 29217724, 88230256, 89956350, 55477753, 18387435, 108347427, 7851834, 76320201, 34059930, 82599280, 108347427, 92752873, 64650097, 92433385, 414607, 72100751, 112081917, 4440942, 54795823, 120183171, 44819012, 55032737, 87655596, 105198146, 63239385, 33230638, 10365063, 115372183, 71955667, 115564528, 17503687, 115564528, 5325873, 36896144, 99693494, 111498758, 7774636, 105885047]
# print("".join(decoded)) decode_message(msg)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment