package Decode;
import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.binary.Base64;public class Test { public static String decode(String data, String key) throws UnsupportedEncodingException { String temp = data;byte[] bin = Base64.decodeBase64(temp.getBytes("utf-8")); byte[] bout = new byte[bin.length];byte[] bkey = key.getBytes();for (int i = 0; i < bin.length; i++) { bout[i] = (byte) (bin[i] - bkey[(i % bkey.length)]);}return new String(bout, 0, bout.length, "utf-8");}public static String encode(Stringdata, String key) throwsUnsupportedEncodingException { byte[] bin = data.getBytes("utf-8");byte[] bout = new byte[bin.length];byte[] bkey = key.getBytes();for (int i = 0; i < bin.length; i++) { bout[i] = (byte) (bin[i] + bkey[(i % bkey.length)]);}return new String(Base64.encodeBase64(bout));}public static voidmain(String[] args) throwsUnsupportedEncodingException { System.out.println(encode("aaaaaaa", "abc"));System.out.println(decode("YmRm", "abc"));}}