Files
corejava/corejava第10版/v1ch13/serviceLoader/impl/CaesarCipher.java
T
2019-05-22 19:31:49 +08:00

24 lines
508 B
Java

package serviceLoader.impl;
import serviceLoader.Cipher;
public class CaesarCipher implements Cipher
{
public byte[] encrypt(byte[] source, byte[] key)
{
byte[] result = new byte[source.length];
for (int i = 0; i < source.length; i++)
result[i] = (byte) (source[i] + key[0]);
return result;
}
public byte[] decrypt(byte[] source, byte[] key)
{
return encrypt(source, new byte[] { (byte) -key[0] });
}
public int strength()
{
return 1;
}
}