• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with RSA Encryption

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

So my latest project involves RSA encryption and decryption. I build the bare bones of the program, but now need to change some variable elements to complete the assignment, and I'm having some trouble.
My code is currently this:


Right now, all variables are specifically declared, but I need them to be generated.

1. P and Q need to be randomly generated primes (between 3 and 128)
2. Use Z ((P-1) * (Q-1)) to randomly generate an e which:
A. 1 < E < Z
B. E and phiPQ are relatively prime (relatively prime means that gcd(E, phiPQ) == 1)
C. There may be several candidates for E, so pick the smallest one
and finally,
3. Generate D ((DE-1) is evenly divisible by phiPQ)

I don't necessarily want the code here, but I'm just not sure how I can take what I have above and now modify it to accept what needs to be generated.

 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can’t do all that lot at once, so don’t even try. One bit at a time. Do you know how to generate prime numbers? If not google for Sieve of Eratosthenes. Use that to remove non‑primes from an array with 128 elements.
Then you can create a new prime number array and use a Random object to select from that array. If you use that in high‑security settings, there is a SecureRandom class. You might be able to use methods of the BigInteger class to find prime numbers.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This program encrypts the text in plaintext.txt file and saves the cipher text in encrypted.txt file. Similarly decryption is done using encrypted.txt file and plain text is saved in decrypted.txt file
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have changed the red text to black because many people find coloured text hard to read.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic