id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > quiz2021_10_21_HL_verify
prev  |  next  |  chance

This is a type of security check program. You can think of it as "cryptography lite". This method is meant to verify that someone knows the key to a cryptographic problem. In reality, this would be based on the product of two different very large prime numbers. The resulting composite number is exceedingly difficult to factor. The goal is to verify that someone knows the factors of that large composite number without giving away what those factors are. Remember, in reality, exceedingly large numbers are used, so it is not possible to quickly brute-force the factors. However, for this program, only small composites will be used, so you CAN easily find the prime factors. Parameters: 'product' will be the composite number, which is the product of two different prime numbers. 'checks' will be a list of numbers to check against the smaller factor of 'product' 'remainders' will be a list of numbers showing the CLAIMED remainder you get after dividing each number in 'checks' by the smaller prime factor of 'product'. If all of the 'remainders' ACTUALLY match the remainder you get after dividing each number in 'checks' by the smaller prime factor of 'product', that is evidence to support that the person providing the data actually knew the factors of 'product'. In that case return 'true'. However, if even one of the claimed 'remainders' is wrong, return 'false'. For example: product = 21 checks = {14, 19, 22, 50} remainders = {2, 1, 1, 2} In this case you would return 'true'. Why? Because 21 factors as 3*7. The smaller prime is 3. 14 mod 3 = 2; 19 mod 3 = 1; 22 mod 3 = 1; and 50 mod 3 = 2. So you have verified that the person passing in the data most likely knew the prime factorization of 21. Obviously, in this case, we are not shocked! However, with much larger composite numbers, it can be difficult to factor them! For example, do you know the prime factors of 1965134681? I do! 32707*60083=1965134681. But I only know that because I found two large prime numbers and multiplied them together. For this problem, I will stick to easily factored values for 'product'. Look at the test data for examples.


quiz2021_10_21_HL_verify(33, [5, 4, 8, 14, 18], [2, 1, 2, 2, 0]) → true
quiz2021_10_21_HL_verify(35, [11, 22, 33, 51, 101], [1, 2, 3, 1, 1]) → true
quiz2021_10_21_HL_verify(19464959, [2000, 2303, 5320, 9853, 2932], [877, 57, 828, 869, 686]) → true

...Save, Compile, Run (ctrl-enter)

public boolean quiz2021_10_21_HL_verify(int product, int[] checks, int[] remainders) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 280

Copyright Nick Parlante 2017 - privacy