Advertisement
Guest User

Untitled

a guest
May 9th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public string enc(string a)
  2. {
  3. char[] x = a.ToCharArray();
  4. string j = "";
  5. for (int i = 0; i < x.Length; i++)
  6. {
  7. j += Convert.ToChar(ExponentiationModulo(x[i], ee, n));
  8. }
  9. return j;
  10. }
  11. long ExponentiationModulo(long Number, long Degree, long Modulo)
  12. {
  13. long Result = 1; //Переменная-результат
  14. while (Degree > 0) //Цикл, вычисляющий результат
  15. {
  16. if (Degree % 2 == 0)
  17. {
  18. Degree /= 2;
  19. Number = (Number * Number) % Modulo;
  20. }
  21. else
  22. {
  23. Degree--;
  24. Result = (Result * Number) % Modulo;
  25. }
  26. }
  27. return Result;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement