fork download
  1. program rsa;
  2. const MaxL=100;
  3. var N, d, L , i:int64;
  4. messaggio : array [0..maxL] of int64;
  5. plaintext : array [0..maxL] of char;
  6.  
  7. function fast_pow (base:int64; esp:int64; modd:int64) :int64;
  8. var meta :int64;
  9. begin
  10. if esp = 0 then fast_pow:=1
  11. else
  12. if esp = 1 then fast_pow:= base mod modd
  13. else
  14. begin
  15. meta := fast_pow(base, esp div 2, modd);
  16. if esp mod 2 =0 then fast_pow:= (meta*meta) mod modd
  17. else fast_pow:= (meta*meta * base) mod modd;
  18. end;
  19. end;
  20. procedure decifra (N :int64; d:int64;L:int64; var messaggio :array of int64 ;plaintext:array of char);
  21. var i:int64;
  22. begin
  23. plaintext[L]:=char(0);
  24. for i:=0 to L-1 do plaintext[i]:=char(fast_pow(messaggio[i], d, N));
  25. for i:=0 to L -1 do write(plaintext[i]);
  26. end;
  27.  
  28.  
  29. begin
  30. readln (N,d,L);
  31. for i:=0 to L-1 do read(messaggio[i]);readln;
  32. decifra(N,d,L,messaggio,plaintext);
  33. end.
  34.  
Success #stdin #stdout 0s 5320KB
stdin
391 3 3
295 123 129
stdout
abc