新答案“接近”的数字看起来不同
您可以使用 RSA 加密(然后解密)您的号码。这绝对是矫枉过正 - 但是......这是一个例子:
安装https://github.com/sybrenstuvel/python-rsa(pip install rsa)
import rsa
import rsa.core
# (pubkey, privkey) = rsa.newkeys(64) # Generate key pair
pubkey = rsa.PublicKey(n=9645943279888986023, e=65537)
privkey = rsa.PrivateKey(n=9645943279888986023, e=65537, d=7507666207464026273, p=9255782423, q=1042153201)
print("1st", rsa.core.encrypt_int(13892359163211, pubkey.e, pubkey.n))
print("2nd", rsa.core.encrypt_int(13992351216421, pubkey.e, pubkey.n))
print("1st", hex(rsa.core.encrypt_int(13892359163211, pubkey.e, pubkey.n))[2:])
print("2nd", hex(rsa.core.encrypt_int(13992351216421, pubkey.e, pubkey.n))[2:])
# If you want to compare a couple of numbers that are similar
for i in range (13892359163211, 13892359163251):
encrypted = rsa.core.encrypt_int(i, pubkey.e, pubkey.n)
# decrypted = rsa.core.decrypt_int(encrypted, privkey.d, privkey.n)
print (i, hex(encrypted)[2:], encrypted)
请注意,您不能加密大于 pubkey.n 的数字。这是 RSA 相关的限制。通过生成具有更高n 的不同密钥对,您可以规避此问题。如果您希望所有生成的数字具有相同的长度,请在它们前面加上前导零。您还可以考虑将它们设为大写以提高可读性。要使显示的字符串更短,请考虑使用下面我的旧答案中提到的 base62 编码。
输出
1st 5427392181794576250
2nd 7543432434424555966
1st 4b51f86f0c99177a
2nd 68afa7d5110929be
input hex(encrypted) encrypted
13892359163211 4b51f86f0c99177a 5427392181794576250
13892359163212 2039f9a3f5cf5d46 2322161565485194566
13892359163213 173997b57918a6c3 1673535542221383363
13892359163214 36644663653bbb4 244958435527080884
13892359163215 c2eeec0c054e633 877901489011746355
...
旧答案 与显示数字有点短有关,不知道它们应该看起来有很大不同
您想将数字的底数从 10 更改为更大的数字以使用更少的字符。请参阅https://stackoverflow.com/a/1119769 以获取基数为 62 的示例 (a-zA-Z0-9)。
或以 16 为底的快速而肮脏的,(0-9A-F,十六进制)。
hex(13892359163211)[2:] # -> 'ca291220d4b'