about | help | code help+videos | done | prefs |
(HARD) Given an int input, return in ascending order its two prime factors. Some inputs will have more or less than two prime factors: for those numbers return an empty array of ints. This problem is based on the use of large primes in public key cryptography, which are multiplied together to form a publicly-released modulus number to be used when encrypting information. Finding the private key without gaining access to where it is stored is possible, if you can factor that large modulus number into its composite primes. Thus, you are coding a brute force decryption attack which could also be used with the large numbers of real-world encryption. (Though, with larger numbers you probably couldn't get away with factoring using primitive data types) This problem is based on, and helps to construct, the simplified public key encryption algorithm found at https://en.wikibooks.org/wiki/Cryptography/A_Basic_Public_Key_ExampleHINTCodingBat lets you create and use helper methods in your solution; just make sure they are added after the main solution method ends. Here is a method for finding primes which you can use in this problem, taken from the following site: https://www.mkyong.com/java/how-to-determine-a-prime-number-in-java/ private boolean isPrime(int n) { //check if n is a multiple of 2 if (n%2==0) return false; //if not, then just check the odds for(int i=3;i*i<=n;i+=2) { if(n%i==0) return false; } return true; } apcsaEncryptBruteForceAttack(15) → [3, 5] apcsaEncryptBruteForceAttack(20) → [] apcsaEncryptBruteForceAttack(8777) → [67, 131] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 320
Copyright Nick Parlante 2017 - privacy