Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Java] I am to complete this RSA class to make it work. Complete To Dos import java.io.*; import java.util.*; import java.math.BigInteger; public class RSA_assignment {

[Java]

I am to complete this RSA class to make it work. Complete To Dos

import java.io.*;

import java.util.*;

import java.math.BigInteger;

public class RSA_assignment

{

static Scanner console = new Scanner (System.in);

public static void main(String [] args) throws FileNotFoundException

{

System.out.println("Q. How to say hello on Java? : A. Hello Java!!!");

System.out.println("Q. How to say hello on C++? : A. Hello C++!!!");

Scanner inFile = new Scanner (new FileReader("Kamilla2.txt"));

long p,q;

long e;

String ggg;

ggg= inFile.next(); //e-

e=inFile.nextInt();

ggg= inFile.next(); //p=

p=inFile.nextLong();

ggg= inFile.next(); //q=

q=inFile.nextLong();

if ((p-1)%e==0||(q-1)%e==0) {System.out.println("I must choose another e from teacher's website");}

else{ System.out.println("gcd(e,(p-1)(q-1))=1");

BigInteger nBI= BobCalculateN(p, q);

BigInteger eBI= new BigInteger(""+e);

System.out.println("p="+p+" q="+q);

BigInteger dBI=BobCalculateD(p, q, e );

System.out.println("dBI="+dBI);

String mStr; //message

long m; //coded value as for a=01,b=02,.. z=26

// if a is first it coded 1, etc.

ggg= inFile.next(); //message=

String mmm=inFile.next();

System.out.println("message="+mmm);

mStr=getCode(mmm);

System.out.println("mStr="+mStr);

m= Long.parseLong(mStr); //work only for 9-10 letters long

BigInteger mBI=new BigInteger(""+m);

String c;

BigInteger cBI = mBI.modPow(eBI,nBI);

// c is encrypted message to post nBI n-to post

System.out.print("n= ");

System.out.print(nBI);

System.out.println();

System.out.print("e= ");

System.out.print(eBI);

System.out.println();

System.out.print("c= ");

System.out.print(cBI);

System.out.println();

System.out.print("m= ");

System.out.print(mBI);

System.out.println();

// PrintWriter outFile = new PrintWriter("Encripted.txt");

// I will get encrypted c from somebody , d and n are mine

BigInteger decryptedmBI=cBI.modPow(dBI, nBI); //decrypted message

// outFile.println(cBI);

// outFile.println(decriptedmBI);

System.out.print("mBI= ");

System.out.println(mBI);

System.out.print("decryptedmBI= ");

System.out.println(decryptedmBI);

String decriptedStr=decryptedmBI.toString();

System.out.println(decriptedStr);

//Print decoded message on meaningful English

PrintLetters(decriptedStr);

inFile.close();

// outFile.close();

}

}

public static long findPrime()

{

//ToDo

long p=0;

return p;

}

public static void PrintLetters(String decriptedStr)

{

//ToDo

}

public static void getCodeOfLetters(String str)

{

//todo

}

public static String getCode(String str)

{

//ToDo

String temp="1";

return temp;

}

public static BigInteger BobCalculateD(long p, long q, long e )

{

//ToDo

BigInteger dBI=new BigInteger(""+0);

return dBI;

}

public static BigInteger BobCalculateN(long p, long q)

{

//ToDo

BigInteger nBI= new BigInteger(""+p);

return nBI;

}

}

The goal is to produce something like this output(Doesn't have to be exact) after reading values from file

e= 103687 p= 1413297339818079839 q= 7795673610480062959 message= gravitatio

n=11017604775781478904665244719208583601 d=5452326099268946397172763409398791927 m==7180122092001200915 c==6365888847651359082866965196518212910 decriptedmBI=7180122092001200915

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions