Advertisement
Guest User

rsarsarsa

a guest
Oct 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package rsa;
  7.  
  8. import java.math.BigInteger;
  9.  
  10. /**
  11. *
  12. * @author Student
  13. */
  14. public class Rsa {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) {
  20. // TODO code application logic here
  21. int n;
  22. n = gcd(12, 40);
  23. System.out.println(n);
  24. n = atobmodn(2, 3, 4);
  25. System.out.println(n);
  26.  
  27. System.out.println();
  28.  
  29. int mc = sign(35, 7, 13);
  30. System.out.println(mc);
  31. }
  32.  
  33. static int gcd(int a, int b) {
  34. int r;
  35. r = a % b;
  36. if (r == 0) {
  37. return b;
  38. } else {
  39. return gcd(b, r);
  40. }
  41. }
  42.  
  43. static int atobmodn(int a, int b, int n) {
  44. double pow = Math.pow(a, b);
  45. return (int) (pow % n);
  46. }
  47.  
  48. static int sign(int m, int p, int q) {
  49. int S;
  50. int v = 5;
  51. int pq= p*q;
  52. int n = (p-1) * (q-1);
  53. BigInteger s = BigInteger.valueOf(v).modInverse(BigInteger.valueOf(n));
  54. int ss = s.intValue();
  55. System.out.println(s);
  56. S = atobmodn(m, ss, pq);
  57. return S;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement