I have to write a program that uses letter displacement to encrypt a string that is entered by the user. The code for encryption looks like:
for (int j = 0; j<key; j++){
for (i = j; i <length; i += key)
{
password += phrase.charAt(i);
}
}
This does what I want it to do. For example it will change Testing1234567890ABCDEF to Ttg369BEei1470CFsn258AD when I use a key length of 3.
My issue is when I try to undo it.
for (int j = 0; j<=Math.ceil(phrase.length()/key); j++){
for (int i = j; i < phrase.length(); i += Math.ceil((phrase.length()/key))+1)
{
password += phrase.charAt(i);
}
}
This works for this phrase at this key but does not work if I use a different phrase or different key.
What am I missing?
Aucun commentaire:
Enregistrer un commentaire