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

 

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

Given a String input, create an int array output containing the combined number of four characters at a time in the String. By "combined," I mean that the ASCII character number for each character should be represented in sequence in this rather large number. If the String length is not divisible by four, pad the last int with two extra zeroes at the end for each "missing" character in a four-character sequence. Thus, each output int will have eight digits. Precondition: all the characters in the input String will be capital letters.


How does this problem relate to public key cryptography?  Encrypting involves raising one number (representing the plaintext) to an exponent, and then finding the remainder after division.  Reverse-engineering that process (meaning, a brute-force decryption attack without knowing the private key) would be much easier if the base of the exponentiation function fit within a small, predictable range such as the ASCII character subset.  By combining several characters into one number to encrypt, the range of possibilities is massively increased and so is the difficulty of guessing the base of the exponent.  And guess what, you will eventually be decrypting and re-assembling these big blocks.
HINT
There are math-oriented methods (think: place value) to build these output numbers, or you could use String concatenation. Your choice, but remember that when you are done you do need to return an array of int.

apcsaEncryptStringToBlocks("AAAA") → [65656565]
apcsaEncryptStringToBlocks("AAA") → [65656500]
apcsaEncryptStringToBlocks("B") → [66000000]

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

public int[] apcsaEncryptStringToBlocks(String str) { }

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

Copyright Nick Parlante 2017 - privacy