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

 

orion.a.smith@gmail.com apcsa-encryption > apcsaEncryptPublicKeyBlocks
prev  |  next  |  chance

Given a series of plaintext blocks represented as an int array (see the apcsaEncryptStringToBlocks problem in this sequence), a public key int and a modulus, encrypt the blocks into a new int array of encrypted information.


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_Example

Something you will discover with this problem is that, even with relatively small parameter values, the calculations will exceed the limits of primitive data types.  Java has a very useful class called BigInteger in the math package (must be referenced as java.math.BigInteger because CodingBat does not allow import statements), which even has a wonderful method designed explicitly for this sort of problem.  So, this challenge is suddenly more about managing the BigInteger objects than it is about the math.
https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html
HINT
Seriously, go look at the BigInteger documentation if you are stuck.

Primes and public keys used, if you are interested (these will also be used in the decryption algorithm in a future problem):
12973,15913 --> 200344741
29989,43691 --> 150774251

apcsaEncryptPublicKeyBlocks([65656565], 200344741, 206439349) → [196980085]
apcsaEncryptPublicKeyBlocks([65656500], 200344741, 206439349) → [196945566]
apcsaEncryptPublicKeyBlocks([66000000], 200344741, 206439349) → [3054987]

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

public int[] apcsaEncryptPublicKeyBlocks(int[] blocks, int publicKey, int mod) { }

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: 340

Copyright Nick Parlante 2017 - privacy