the determination of how to split up the ciphertext is slightly more complicated than as described above, but the basic approach is the same. Alternatively, for simplicity in decrypting, one can pad the plaintext with extra letters to make its length a multiple of . If the ciphertext has not been padded, but you either know or are willing to brute-force the number of rails used, you can decrypt it using the following steps. As above, let be the length of the string to be decrypted and let be the number of rails used during encryption. We will add two variables, and , where = the number of diagonals in the decrypted Rail Fence, and = the number of empty spaces in the last diagonal. Next solve for and algebraically, where both values are the smallest number possible. This is easily done by incrementing by 1 until the denominator is larger than , and then simply solving for . Consider the example cipher, modified to use 6 rails instead of 3. W.........V.........O .E.......O.E.......T.N ..A.....C...R.....A...C ...R...S.....E...N.....E ....E.I.......D.U....... .....D.........R........ The resulting cipher text is: WVO EOETN ACRAC RSENE EIDU DR We know that , and if we use we can solve the equation above. Simplify the fraction. Solve for Solve for We now have , , and . Or, 6 rails, 5 diagonals (4+1), and 2 empty spaces at the end. By blocking out the empty spaces at the end of the last diagonal, we can simply fill in the Rail Fence line by line using the ciphertext. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ X _ _ X W V O E O E T N A C R A C _ _ _ _ _ _ _ _ _ X _ _ X Cryptanalysis The cipher's key is , the number of rails. If is known, the ciphertext can be decrypted by using the above algorithm. Values of equal to or greater than , the length of the ciphertext, are not usable, since then the ciphertext is the same as the plaintext. Therefore the number of usable keys is low, allowing the brute-force attack of trying all possible keys. As a result, the rail-fence cipher is considered weak. Zigzag cipher The term zigzag cipher may refer to the rail fence cipher as described above. However,