Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package rsa;
- import java.math.BigInteger;
- /**
- *
- * @author Student
- */
- public class Rsa {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int n;
- n = gcd(12, 40);
- System.out.println(n);
- n = atobmodn(2, 3, 4);
- System.out.println(n);
- System.out.println();
- int mc = sign(35, 7, 13);
- System.out.println(mc);
- }
- static int gcd(int a, int b) {
- int r;
- r = a % b;
- if (r == 0) {
- return b;
- } else {
- return gcd(b, r);
- }
- }
- static int atobmodn(int a, int b, int n) {
- double pow = Math.pow(a, b);
- return (int) (pow % n);
- }
- static int sign(int m, int p, int q) {
- int S;
- int v = 5;
- int pq= p*q;
- int n = (p-1) * (q-1);
- BigInteger s = BigInteger.valueOf(v).modInverse(BigInteger.valueOf(n));
- int ss = s.intValue();
- System.out.println(s);
- S = atobmodn(m, ss, pq);
- return S;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement