如果你是打開使用第三方庫,以下解決方案使用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作爲字符串。而已。 –