如果你是打开使用第三方库,以下解决方案使用Eclipse Collections:
MutableList<String> decryptedPasswordInPairs = Lists.mutable.with("A2")
.collectWith((oddPair, A5) ->
CharAdapter.adapt(oddPair)
.injectIntoWithIndex(
ByteLists.mutable.empty(),
(bytes, character, index) ->
bytes.with((byte) (character^A5.charAt(index % A5.length()))))
.makeString(""), "A5");
decryptedPasswordInPairs.each(System.out::println);
我用下面的进口:
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.factory.primitive.ByteLists;
import org.eclipse.collections.impl.string.immutable.CharAdapter;
通过使用Eclipse中集合提供的基本ByteList
,我是能够避免装箱。 ByteList
上的方法makeString
允许您控制分隔符。传递一个空的String
可以去掉上使用toString
的逗号。类CharAdapter
提供了一套基于String
的基于char
的协议,包括我在此使用的名为injectIntoWithIndex
的方法。
该代码也可以分成更小的步骤,使其稍微密集一点,可能更易于阅读。
MutableList<String> decryptedPasswordInPairs = Lists.mutable.with("A2")
.collect(CharAdapter::adapt)
.collectWith((oddPair, A5) ->
oddPair.injectIntoWithIndex(
ByteLists.mutable.empty(),
(bytes, character, index) ->
bytes.with((byte) (character^A5.charAt(index % A5.length())))), "A5")
.collectWith(ByteList::makeString, "");
decryptedPasswordInPairs.each(System.out::println);
注:我的Eclipse集合的参与者。
好的方法,谢谢。但它不显示输出为07. –
你想要解密什么字符串输入? –
我想要做的就是用A2与XOR A2并将07作为字符串。而已。 –