Skip to content

Instantly share code, notes, and snippets.

@hersche
Last active August 29, 2015 13:58
Show Gist options
  • Save hersche/9963661 to your computer and use it in GitHub Desktop.
Save hersche/9963661 to your computer and use it in GitHub Desktop.
convert toxkey to toxDns secured with pin and back.
import binascii
def generateKey(dns,pin):
pub = dns[11:75]
logger.info(pub)
check = dns[83:87]
logger.info(check)
nospam = binascii.a2b_base64(pin+"==")
nospam =str(binascii.hexlify(nospam))
nospam = nospam[2:-1]
nospam = nospam.upper()
print("lookupkey="+pub+nospam+check)
return pub+nospam+check
def generateDnsId(key):
if len(key)==76:
logger.info("init-lookupkey: "+key)
pub = key[0:64]
nospam = key[64:72]
checksum = key[71:76]
dns="v=tox2;pub="+pub+";check="+checksum
logger.info(dns)
binData = binascii.unhexlify(nospam)
b64data= binascii.b2a_base64(binData)
b64data=str(b64data)
b64data=b64data[2:-5]
pin=b64data.rstrip('=')
logger.info(dns)
self.ui.toxTryNotifications.append("Your pin is "+pin)
return (dns,pin)
else:
logger.error("Wrong key size")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment