1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-02-26 12:10:13 +08:00

为生成的 IMEI 增加校验位 ()

* feat: luhn

* fix: China Country Code 86

* fix: China Country Code 86

* fix: China Country Code 86
This commit is contained in:
cssxsh 2022-02-12 20:47:19 +08:00 committed by GitHub
parent d2505a397d
commit cadb529588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -152,10 +152,28 @@ public class DeviceInfo(
wifiBSSID = "02:00:00:00:00:00".toByteArray(),
wifiSSID = "<unknown ssid>".toByteArray(),
imsiMd5 = getRandomByteArray(16, random).md5(),
imei = getRandomIntString(15, random),
imei = "86${getRandomIntString(12, random)}".let { it + luhn(it) },
apn = "wifi".toByteArray()
)
}
/**
* 计算 imei 校验位
*/
private fun luhn(imei: String): Int {
var odd = false
val zero = '0'
val sum = imei.sumOf { char ->
odd = !odd
if (odd) {
char.code - zero.code
} else {
val s = (char.code - zero.code) * 2
s % 10 + s / 10
}
}
return (10 - sum % 10) % 10
}
}
/**