1 2 3 4
|
public String CeasarCipher( String text, int count )
{
int c1 = 5; //these ought to be arguments of your function, it would also simplify your select
int c2 = 19;
|
if( !(letter == ' ' || letter < 'A'))
¿don't you have an `isalpha()' function?
> String text = "Nice to meet you";
> Expected output:
> String cipher = "Sbvj mt fxjm dhn";
meet -> fxjm
`e' transform first to `x' and then to `j'. One of the biggest weakness of Caesar cipher is that the output character depends only on the input character (all the `e' would transform to the same symbol), and so the process doesn't change the frequency of the symbols.
If that's really the expected output, then you are misunderstanding how the cipher should be applied.
> following the algorithm C1C2C2C1C2 where C1 = 5 and C2 = 19
you may as well add all the offset and apply just one cipher
(3*C1 + 3*C2) mod ('z'-'a'+1)
there's another weakness. A brute-force approach only needs to try 'z'-'a'+1 times.
Edit: taking the distance between the strings, I've got this
5 19 19 5 0 19 5 0 19 19 5 19 0 5 19 19 |
were 0 is the white space.
Then it becomes clearer what you need to do:
- the first character gets moved C1 places
- the second character, C2 places
- third, C2
- fourth C1,
- fifth, C2
- then repeat that sequence until you had traversed the entire string.