Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java please RSA Encryption 1 Overview How are messages transferred in a secure w

ID: 3758188 • Letter: J

Question

java please

RSA Encryption 1 Overview How are messages transferred in a secure way? How is your browser sure that it is talking to the website it should be instead of an imposter? How can we carry key-chains that tell us a password that changes every five seconds? The answer to all of these questions is asymmetrical encryption. Asymmetric encryption allows us to take a message and turn it into gibberish using a digital key, and turn it back into the original message using a different public key to the world, and let them encrypt messages that can only be de- crypted using our private key. The public and private keys are mathematically related, but it is computationally infeasible to compute a private key from only the public key We can give out a Today we will be implementing one such asymmetrical encryption algorithm known as RSA, named for its inventors Ron Rivest, Adi Shamir and Leonard Adleman. RSA uses randomly generated prime numbers to generate a key pair and then uses exponentiation and modulation to encrypt and decrypt messages using this key. RSA, while being surplanted by the more sophisticated SHA family of algorithms, is sl commonly used for digital security. The mathe- matics proving RSA to be secure are beyond the scope of this course. The implementation of RSA, however, is of a reasonable level of complexity to be implemented in the our lab, given the tools provided by Java's class library Normally RSA is used to encoded small pieces of data due to it's inability to encode large numbers of bytes at once, so in our implementation we will be encoding files one byte a time, leading to very large output files

Explanation / Answer

import java.math.BigInteger;
public class CaesarCipher
{
   private BigInteger enc;
   private BigInteger dec;

   public CaesarCipher(BigInteger aEnc, BigInteger aDec)
   {
       enc = aEnc;
       dec = aDec;
   }

   public byte[] encrypt(int n)
   {
       byte[] byteArray = new byte[4];
       byteArray[0] = (byte) (n >> 24);
       byteArray[1] = (byte) (n >> 16);
       byteArray[2] = (byte) (n >> 8);
       byteArray[3] = (byte) (n);
       return byteArray;
   }

   public int decrypt(byte[] byteArray)
   {
       int n = byteArray[0] << 24 | (byteArray[1] & 0xFF) << 16
               | (byteArray[2] & 0xFF) << 8 | (byteArray[3] & 0xFF);
       return n;
   }
}