about | help | code help+videos | done | prefs |
Write a method that returns an array of values representing a lossy encryption of a string by grouping characters into chunks that are 'group' characters long, adding their ASCII (or UNICODE) values, and then finding the remainder when that sum is divided by 'max'. Store the resulting value in an array that is as long as the number of sets of grouped characters. This is a "lossy" encryption method because it might not be possible to explicitly recover the original message, depending on the values of 'group' and 'max', but it IS possible if certain conditions are met. For example, if 'group' is 1 and 'max' is greater than the greatest ASCII-value in the string, the resulting message can easily be decrypted. However, if 'group' is greater than 2 and/or 'max' is a relatively small number, significant information loss will occur. Look at the test data for examples. As preconditions you may make the following assumptions: 'group'>0, 'max'>2. test2024_04_16_HL_encrypt("ABC", 5, 50) → [48] test2024_04_16_HL_encrypt("Along time ago in a galaxy right next to ours...", 2, 100) → [73, 21, 35, 21, 10, 29, 14, 37, 42, 29, 0, 5, 41, 46, 8, 20, 42, 21, 48, 27, 43, 31, 61, 92] test2024_04_16_HL_encrypt("Encrypt this message!", 5, 200) → [113, 80, 62, 131, 33] ...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: 290
Copyright Nick Parlante 2017 - privacy