public FpeCharDecryptor(FpeEngine fpeEngine, byte[] key, byte[] tweak, char[] alphabet) { this.fpeEngine = fpeEngine; alphabetMapper = new BasicAlphabetMapper(alphabet); fpeEngine.Init(false, new FpeParameters(new KeyParameter(key), alphabetMapper.Radix, tweak)); }
private void ff3_1Test(IAlphabetMapper alphabetMapper, String skey, String stweak, String input, String output) { FpeEngine fpeEncEngine = new FpeFf3_1Engine(); FpeEngine fpeDecEngine = new FpeFf3_1Engine(); byte[] key = Hex.Decode(skey); byte[] tweak = Hex.Decode(stweak); int radix = alphabetMapper.Radix; fpeEncEngine.Init(true, new FpeParameters(new KeyParameter(key), radix, tweak)); fpeDecEngine.Init(false, new FpeParameters(new KeyParameter(key), radix, tweak)); byte[] bytes = alphabetMapper.ConvertToIndexes(input.ToCharArray()); byte[] encryptedBytes = process(fpeEncEngine, bytes); IsEquals(output, new String(alphabetMapper.ConvertToChars(encryptedBytes))); byte[] decryptedBytes = process(fpeDecEngine, encryptedBytes); IsTrue(Arrays.AreEqual(bytes, decryptedBytes)); char[] chars = alphabetMapper.ConvertToChars(decryptedBytes); IsEquals(input, new String(chars)); }