Implementation of Scytale cipher (encryption and decryption) This is web exercise 3.1.41. from the book Computer Science An Interdisciplinary Approach by Sedgewick &amp; Wayne:

The scytale cipher is one of the first cryptographic devices used for
military purposes. (See The Code Book.) It
was used by the Spartans in the fifth century BCE. To scramble the
text, you print out every kth character starting at the beginning,
then every kth character starting at the second character, and so
forth. Write a program implements this encryption scheme.

Here is my program:
public class ScytaleCipher 
{
    public static String encrypt(String text, int kth)
    {
        int textLength = text.length();
        String encrypted = &quot;&quot;;
        for (int i = 0; i &lt; kth; i++)
        {
            for (int j = 0; i+j &lt; textLength; j += kth)
            {
                encrypted += String.valueOf(text.charAt(i+j));
            }
        }
        return encrypted;
    }
    public static String decrypt(String text, int kth)
    {
        return encrypt(text, kth-1);
    }
    public static void main(String[] args)
    {
        int kth = Integer.parseInt(args[0]);
        String message = &quot;&quot;;
        while (!StdIn.isEmpty())
        {
            String word = StdIn.readString();
            message += word;
        }
        // to encrypt
        System.out.println(encrypt(message, kth));
        // to decrypt
        //System.out.println(decrypt(message, kth));
    }
}

StdIn is a simple API written by the authors of the book. I checked my program and it works.
Is there any way that I can improve my program?
Thanks for your attention.
I have some suggestions for your code.
Use java.lang.StringBuilder to concatenate String in a loop.
It's generally more efficient to use the builder in a loop, since the compiler is unable to optimize it by itself while translating your code into bytecode; The compiler will not use the java.lang.StringBuilder in complex loops and your method will take more time and more memory to execute, since the String Object is immutable (a new instance will be created each iteration).
StringBuilder encrypted = new StringBuilder();
for (int i = 0; i &lt; kth; i++) {
   for (int j = 0; i + j &lt; textLength; j += kth) {
      encrypted.append(text.charAt(i + j));
   }
}
return encrypted.toString();

When concatenating a primitive into a string, you don’t need to convert it.
You can add the primitive (int, double, float, char, ect) directly into the string by using the assignment operators (+, +=).
Before
encrypted += String.valueOf(text.charAt(i+j));

After
encrypted += text.charAt(i+j);