Implement this key cipher
Goal
Use the algorithm (explained in the Algorithm section) to implement a certain cipher.
The program must read input from STDIN or the closest available equivalent, use the algorithm to generate the ciphertext and a key.
The ciphertext and the key will be written to STDOUT or the closest available equivalent. Any format is allowed, as long as it outputs the ciphertext and the key.
Algorithm
Convert the characters in the string into the respective ASCII values. For example:
Hello -> 72 101 108 108 111
Next, you will need to generate a key as long as the string with random numbers in the range of 0-9.
Hello -> 62841
Add the integers in the random number sequence to the ASCII values of the string. In the above examples, 72 would become 78, and 101 would become 104.
72 + 6 = 78, 101 + 2 = 103, 108 + 8 = 116, etc
Next, convert the new values back to characters. In the above examples, the text Hello
has become Ngtpp
.
Examples
(These are simply examples of what the output might look like. The output can and will vary.)
Hello World
Lfrlu)_supg
41606984343
This will be encoded
Zhjs$~koo gj$iuhofgj
60104723305544750226
Rules
- You can assume that the input will only contain characters in the range a-z, A-Z, and spaces.
- Submissions must be full programs or functions.
- Submissions will be scored in bytes.
- Standard loopholes are forbidden.
- This is code-golf, so the shortest code wins.
(This is one of my first challenges, if there's something wrong with it, feel free to tell me how I could improve it.)
preferably with the format (ciphertext)\n(key).
"preferred features" and code golf don't mix very well. Your should make that mandatory or allow other output formats. 3. Does the key have to be printed without spaces? What about printing it in list format, e.g.[0, 5, 2, ...]
? \$\endgroup\$