mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
fix: targeted voucher code not working
This commit is contained in:
@@ -106,7 +106,7 @@ object RedeemCodeMachine {
|
||||
bytes[bytes.size - 1] = crc16.toByte()
|
||||
|
||||
|
||||
val basePwd = initialPassword.random()
|
||||
val basePwd = initialPassword.random().copyOf()
|
||||
val receiverPwd = receiver?.toByteArray() ?: ByteArray(16) // 128 bits of something
|
||||
|
||||
// xor basePWD with receiverPwd
|
||||
@@ -124,11 +124,19 @@ object RedeemCodeMachine {
|
||||
fun decode(codeStr: String, decoderUUID: UUID? = null): RedeemVoucher? {
|
||||
val receiverPwd = decoderUUID?.toByteArray() ?: ByteArray(16) // 128 bits of something
|
||||
|
||||
val passwords = initialPassword.map { basePwd ->
|
||||
// for decrypting targeted code
|
||||
val passwords1 = initialPassword.map { basePwd ->
|
||||
ByteArray(32) { i ->
|
||||
basePwd[i] xor receiverPwd[i % 16]
|
||||
}
|
||||
}
|
||||
// for decrypting generic code
|
||||
val passwords2 = initialPassword.map { basePwd ->
|
||||
ByteArray(32) { i ->
|
||||
basePwd[i]
|
||||
}
|
||||
}
|
||||
val passwords = passwords1 + passwords2
|
||||
|
||||
// try to decode the input string by just trying all 8 possible keys
|
||||
val decodeds = passwords.map {
|
||||
@@ -149,7 +157,7 @@ object RedeemCodeMachine {
|
||||
}
|
||||
|
||||
// if all CRC fails...
|
||||
if (crcResults.none()) {
|
||||
if (crcResults.indexOf(true) < 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -24,16 +24,18 @@ class UIRedeemCodeMachine : UICanvas(
|
||||
override var width = Toolkit.drawWidth
|
||||
override var height = App.scr.height
|
||||
|
||||
private val codeCols = 12
|
||||
|
||||
val title = UIItemTextLabel(this, { "Enter the Code" },
|
||||
(Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(14)) / 2,
|
||||
(Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(codeCols)) / 2,
|
||||
App.scr.halfh - UIItemRedeemCodeArea.estimateHeight(4) - 48 - 48,
|
||||
UIItemRedeemCodeArea.estimateWidth(14)
|
||||
UIItemRedeemCodeArea.estimateWidth(codeCols)
|
||||
)
|
||||
|
||||
val inputPanel = UIItemRedeemCodeArea(this,
|
||||
(Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(14)) / 2,
|
||||
(Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(codeCols)) / 2,
|
||||
App.scr.halfh - UIItemRedeemCodeArea.estimateHeight(4) - 48,
|
||||
14, 4)
|
||||
codeCols, 4)
|
||||
|
||||
init {
|
||||
addUIitem(title)
|
||||
|
||||
Reference in New Issue
Block a user