How can I add a different value to each item in a list?

I am trying to decrypt a modified Vigenère cipher text. I am unfamiliar with Mathematica, so I need some guidance. Here is what I want:

modifiedVigenere[ciphertext_, keylength_]:= *insert code here*


Here is what I want the code to do. First, convert the ciphertext to numbers mod 26. I already have a command which will do this.

stringToNumbers[string_] := ToCharacterCode[StringReplace[ToUpperCase[string],
RegularExpression["[^A-Z]"] -> ""]] - 65


Then I want to modify the numbers based on the keylength. Let's say the string changes to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Then, let's say the keylength is 3. I want to subtract 0 from the first three entries in the list, 1 from the second three, 2 from the third three, and then 3 from the final three (in this case, only the number 10). The resulting string would look like this: {1, 2, 3, 3, 4, 5, 5, 6, 7, 7}.

I would then change the numbers back into a string with the following command:

numbersToString[list_] :=
FromCharacterCode[
Select[list, Function[x, IntegerQ[x] && x >= 0 && x <26]] + 65
]


If anyone could help me, that would be greatly appreciated.

• Instead of stringToNumbers and numbersToString you can also use the functions LetterNumber and FromLetterNumber.
– A.Z.
Jun 25 '20 at 20:07

Do you want something like this?

modifiedVigenere[ciphertext_, keylength_] := StringJoin[
FromLetterNumber[
LetterNumber[
ciphertext
] - Floor[
Range[
0,
StringLength[ciphertext] - 1
]/keylength
]
]
]


This produces

modifiedVigenere["abcdefghij", 3]  (* "abccdeefgg" *)

• Yes, that works. Thank you so much! Jun 25 '20 at 23:01
• @NathanielLackey if you find an answer valuable & useful, it’s always better to make that checkmark turn green by accepting the answer :) not only does it provide others in the future a nice and easy way to see if a problem is solved or not, it gives the answering party a good bit of points ;D Jun 26 '20 at 14:45