fork download
  1. # your code goes here
  2. """ base58 encoding / decoding functions """
  3. import unittest
  4.  
  5. alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
  6. base_count = len(alphabet)
  7.  
  8. def encode(num):
  9. """ Returns num in a base58-encoded string """
  10. encode = ''
  11.  
  12. if (num < 0):
  13. return ''
  14.  
  15. while (num >= base_count):
  16. mod = num % base_count
  17. encode = alphabet[mod] + encode
  18. num = num / base_count
  19.  
  20. if (num):
  21. encode = alphabet[num] + encode
  22.  
  23. return encode
  24.  
  25. def decode(s):
  26. """ Decodes the base58-encoded string s into an integer """
  27. decoded = 0
  28. multi = 1
  29. s = s[::-1]
  30. for char in s:
  31. decoded += multi * alphabet.index(char)
  32. multi = multi * base_count
  33.  
  34. return decoded
  35.  
  36. class Base58Tests(unittest.TestCase):
  37.  
  38. def test_alphabet_length(self):
  39. self.assertEqual(58, len(alphabet))
  40.  
  41. def test_encode_10002343_returns_Tgmc(self):
  42. result = encode(10002343)
  43. self.assertEqual('Tgmc', result)
  44.  
  45. def test_decode_Tgmc_returns_10002343(self):
  46. decoded = decode('Tgmc')
  47. self.assertEqual(10002343, decoded)
  48.  
  49. def test_encode_1000_returns_if(self):
  50. result = encode(1000)
  51. self.assertEqual('if', result)
  52.  
  53. def test_decode_if_returns_1000(self):
  54. decoded = decode('if')
  55. self.assertEqual(1000, decoded)
  56.  
  57. def test_encode_zero_returns_empty_string(self):
  58. self.assertEqual('', encode(0))
  59.  
  60. def test_encode_negative_number_returns_empty_string(self):
  61. self.assertEqual('', encode(-100))
  62.  
  63. if __name__ == '__main__':
  64. #print encode(int("00B94BA6C51B3D8372D82FDE5DC78773D960B5A82FCDAC8181",16))
  65. print hex(decode("Wh4bh"))
Success #stdin #stdout 0.01s 8148KB
stdin
6s(bb onc s);this.xi(a)&a(this.Fe-sthis.Ne.@@t(@).langth);this.he.set(a,(b));this.fes=s this Ne get S his,@))));@lse(a"hrray.from(tkss )€,push(bid]),rete 
b[c),e-encodeURIComponent(String(d));d=this.Dd(d);for(var f-0;1<d.length,fo.)om his.mg-null, this.Nc.set(av(this,a)p_.oc(b)),this.fassb.length));_-g-tostring irn this.mgea.join("&")); i&(a.Nc-new Map(this.Nc),a.Fe=this.Fe);return a);var av=function(a,6)(b-String(s)," tion(b,c)(var dc.tolowerCase();cl=d&&(this.remove(c),this.setValues(d,b))),this))," this.add(d,c)),this)); mngth,d=[);if(c)for(var e=function(k,1,@)(c--;d[k]-17(1z:10,volve:m): RA("Must provide a function.");this.)genull;this.H7ma),TA=11;TA=11; -sl(h,_.bb(e,f,10),_.bb(o,f,l1));else b(d)))),VA,WA,XA,YA=(jP;function(a)(VA-a;try atch(b)[))),ZA-function(o)(return _.Jy(a.status)),s^=function()(var a-1@,b-_-sy.it0). b): ;b. match(/^V */)8&(b= (window locetion. protocol. http: http: pl).match(/^https?:$/)&&(b=window.location.protocol+"//"+window.location.host+b);var tocol) match(/^https? :$/)a(b=c[1]*" https )+b) ")₹$/1,"$1$2");b-b.replace(/^(https:\/\/[-_a-20-9.]+):0"443([\/70].*)7$/i, "$1$2");b." +window, location. host+(c[3]] ) b=b. repl. ace( ject.prototype.hasOwnProperty.call(c,b)?b-String(c[b]||b): /content.googleapis.com"),b=b.replace(/^(https?):\/\/ww-(googleapis-[-_a-z@-9]-\[_. M\content(-[-. 20 9 1+)P. googleapisI. coms/)11 \-googleapis\.com)$/,"$1://content-$2")));a&&(a=_.Hf("client/firstPartyRewrite"),_ bd( $1://clients6.google.com"),b=b.replace(/^(https?):\/\/content-([-a-20-9]+)\.([-a-z0 ntent-([-a-z@-9]+)I.googleapis\.com$/,"$1://$2.clients6.google.com") ([-a-z@-9]*).google.com$/,"$1://content-googleapis-$2.$3.google.com")));return_b)." *.client.GapiClientError";SA.prototype.then-functior(a,b,c)(this.)gl|(this.]g-this 
ype hasOunProperty.call(a, c)) (var hi(a,c);d&&(c= gi(c, d))88 ii(b, t0))retsre Ky. call(this);this,ld-a;this,)I-b;this Pdac;a=();if(d) for(var in d)Object.pretetip otype.hasownProperty.call(a,e)&&(d[unescape(encodeURIComponent(e))]= A(dB Ky) z)(function()(c(eB(this))),this)),this.aa(" E E ion (b E )(this qə( ePPor (9, hh(h.headers);return b),functionb)frek 
Crop 
stdout
0x1406e058